Skip to content

Commit

Permalink
Add publishing to npm
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaStebaev committed May 18, 2022
1 parent 46e80e2 commit ca0e56a
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 5 deletions.
94 changes: 94 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Build and publish
on:
push:
branches-ignore:
- stable
- beta
- develop
pull_request:
types: [closed]
branches:
- stable
- beta
- develop
env:
NODE_VERSION: 16

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'

- name: Install project
run: |
yarn
yarn install-peers
- name: Compile typescript
run: yarn compile

- name: Determine version
run: |
export BRANCH=${GITHUB_REF##*/}
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
echo "Branch $BRANCH"
export VERSION=$(bash ./scripts/calculate_version.sh)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Version $VERSION"
( test $BRANCH = "stable" && export PRERELEASE=false ) || export PRERELEASE=true
echo "PRERELEASE=$PRERELEASE" >> $GITHUB_ENV
- name: Publish NPM package
run: ./scripts/publish_package.sh
env:
BRANCH: ${{ env.BRANCH }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
prerelease: ${{ env.PRERELEASE }}

clean:
runs-on: ubuntu-latest
if: github.event.pull_request.merged
steps:
- uses: actions/checkout@v2

- name: Set up Node
uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'

- name: Remove feature tag
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
export SOURCE_BRANCH=${GITHUB_HEAD_REF##*/}
echo "Source branch: $SOURCE_BRANCH"
npm dist-tag rm @skalenetwork/skale-manager-interfaces $SOURCE_BRANCH
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Build and test
on: [push, pull_request]

env:
PYTHON_VERSION: 3.9

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -9,9 +12,6 @@ jobs:
matrix:
node-version: [12.x, 14.x, 16.x]

env:
python-version: 3.9

steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ env.python-version }}
python-version: ${{ env.PYTHON_VERSION }}

- name: Install slither
run: pip3 install -r scripts/requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@skalenetwork/upgrade-tools",
"version": "0.0.1-custom.10",
"version": "0.0.1",
"description": "Scripts to support upgrades of smart contracts",
"files": [
"dist/**/*"
Expand Down
32 changes: 32 additions & 0 deletions scripts/calculate_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -e

VERSION=$(node --print --eval "require('./package.json').version")
USAGE_MSG='Usage: BRANCH=[BRANCH] calculate_version.sh'

if [ -z "$BRANCH" ]
then
(>&2 echo 'You should provide branch')
echo "$USAGE_MSG"
exit 1
fi

BRANCH=$(echo $BRANCH | tr [:upper:] [:lower:] | tr -d [:space:])

if [ -z "$VERSION" ]; then
echo "The base version is not set."
exit 1
fi

git fetch --tags > /dev/null

for (( NUMBER=0; ; NUMBER++ ))
do
FULL_VERSION="$VERSION-$BRANCH.$NUMBER"
if ! [[ $(git tag -l | grep "$FULL_VERSION") ]]
then
echo "$FULL_VERSION" | tr / -
break
fi
done
31 changes: 31 additions & 0 deletions scripts/publish_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -e

USAGE_MSG='Usage: BRANCH=[BRANCH] publish_package.sh'
if [ -z "$BRANCH" ]
then
(>&2 echo 'You should provide branch')
echo "$USAGE_MSG"
exit 1
fi

cd "$(dirname "$0")/.."

BRANCH=$(echo $BRANCH | tr [:upper:] [:lower:] | tr -d [:space:])
VERSION=$(BRANCH=$BRANCH ./scripts/calculate_version.sh)

TAG=""
if ! [[ $BRANCH == 'stable' ]]
then
TAG="--tag $BRANCH"
fi

if [[ "$VERSION" == *-stable.0 ]]
then
VERSION=${VERSION%-stable.0}
fi

echo "Using $VERSION as a new version"

yarn publish --access public --new-version $VERSION --verbose --no-git-tag-version $TAG

0 comments on commit ca0e56a

Please sign in to comment.