Skip to content

Commit

Permalink
SKALE-1753 Add publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroNazarenko committed Sep 28, 2020
1 parent 054dba5 commit 4213a4f
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and publish
on:
push:
branches:
- stable
- develop
- beta


jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://registry.npmjs.org'
- name: Set version and branch
run: |
export BRANCH=${GITHUB_REF##*/}
export VERSION=$(bash ./scripts/calculate.sh)
echo "::set-env name=VERSION::$VERSION"
echo "::set-env name=BRANCH::$BRANCH"
echo "Version $VERSION"
echo ${{ secrets.GITHUB_TOKEN }}
- name: Publish on npm
if: github.ref != 'refs/heads/stable'
run: |
npm version --no-git-tag-version ${{ env.VERSION }}
npm publish --access public --tag ${{ env.BRANCH }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish on npm (stable)
if: github.ref == 'refs/heads/stable'
run: |
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create Release
if: github.ref != 'refs/heads/stable'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
draft: false
prerelease: true
- name: Create Release (stable)
if: github.ref == 'refs/heads/stable'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
release_name: ${{ env.VERSION }}
draft: false
35 changes: 35 additions & 0 deletions scripts/calculate_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
VERSION=$(npm run --silent 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

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

if [[ $BRANCH == 'master' ]]; then
echo $VERSION
exit 1
fi

if [[ $BRANCH == 'stable' ]]; then
echo $VERSION
exit 0
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

0 comments on commit 4213a4f

Please sign in to comment.