From 4213a4ffa62f8987fe6b62b97ba2b525e416cf56 Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Mon, 28 Sep 2020 16:39:59 +0300 Subject: [PATCH] SKALE-1753 Add publish workflow --- .github/workflows/publish.yml | 58 +++++++++++++++++++++++++++++++++++ scripts/calculate_version.sh | 35 +++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 .github/workflows/publish.yml create mode 100644 scripts/calculate_version.sh diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..379262d --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 diff --git a/scripts/calculate_version.sh b/scripts/calculate_version.sh new file mode 100644 index 0000000..39b286d --- /dev/null +++ b/scripts/calculate_version.sh @@ -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 \ No newline at end of file