From 0aa43760af36a2f5e0be593b39cdcf6d1436b02d Mon Sep 17 00:00:00 2001 From: Erfan Besharat Date: Fri, 18 Dec 2020 18:58:57 +0330 Subject: [PATCH] Pass release tag as env var in version action --- .github/workflows/version.yml | 55 ++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml index 0b4e7a2c..26e292c4 100644 --- a/.github/workflows/version.yml +++ b/.github/workflows/version.yml @@ -1,33 +1,36 @@ +name: Bump "package.json" Version + on: release: - types: [prereleased, released, published] + types: [prereleased, released] jobs: version-bump: runs-on: ubuntu-latest steps: - - uses: actions/checkout@master - with: - persist-credentials: true - fetch-depth: 0 # otherwise, you will failed to push refs to dest repo - - name: Get the last API TAG and current version in package.json - run: | - export RELEASE_TAG=$(curl -sS -X GET -G \ - -d max=300 \ - -H 'Accept: application/json' https://api.github.com/repos/shocknet/api/tags | jq -r '.[0].name') - export API_TAG=$(cat ./package.json | jq -r '.version') - echo $(if [ "$API_TAG" = "$RELEASE_TAG" ]; then echo "UPGRADEABLE=true"; else echo "UPGRADEABLE=false"; fi) >> $GITHUB_ENV - - - name: Update and Commit files - if: ${{ env.UPGRADEABLE == 'true' }} - run: | - echo $(cat ./package.json | jq -r --arg API_TAG "$API_TAG" '.version = $API_TAG') > package.json - git config --local user.email "actions@shock.network" - git config --local user.name "Version Update Action" - git commit -m "version upgraded to ${API_TAG}" -a - - name: Push changes - if: ${{ env.UPGRADEABLE == 'true' }} - uses: ad-m/github-push-action@master - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: master + - uses: actions/checkout@master + with: + persist-credentials: false + fetch-depth: 0 # otherwise, you will failed to push refs to dest repo + - name: Get the last API TAG and current version in package.json + run: | + export RELEASE_TAG=$(git describe --tags --abbrev=0) && \ + echo "VERSION=${RELEASE_TAG}" >> $GITHUB_ENV + + export API_TAG=$(cat ./package.json | jq -r '.version') + + echo $(if [ "$API_TAG" = "$RELEASE_TAG" ]; then echo "UPGRADEABLE=false"; else echo "UPGRADEABLE=true"; fi) >> $GITHUB_ENV + + - name: Update and Commit files + if: ${{ env.UPGRADEABLE == 'true' }} + run: | + cat ./package.json | jq -r --arg API_TAG "${{ env.VERSION }}" '.version = $API_TAG' | tee a.json && mv a.json package.json + git config --local user.email "actions@shock.network" + git config --local user.name "Version Update Action" + git commit -m "version upgraded to ${{ env.VERSION }}" -a + - name: Push changes + if: ${{ env.UPGRADEABLE == 'true' }} + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: master