|
| 1 | +on: |
| 2 | + push: |
| 3 | + branches: [ master ] |
| 4 | + |
| 5 | +jobs: |
| 6 | + check-release-tag: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + steps: |
| 9 | + - name: Checkout code |
| 10 | + uses: actions/checkout@v2 |
| 11 | + with: |
| 12 | + fetch-depth: 0 |
| 13 | + - name: Prepare tag |
| 14 | + id: prepare_tag |
| 15 | + continue-on-error: true |
| 16 | + run: | |
| 17 | + export TAG=v$(jq -r '.version' package.json) |
| 18 | + echo "TAG=$TAG" >> $GITHUB_ENV |
| 19 | + export CHECK_TAG=$(git tag | grep $TAG) |
| 20 | + if [[ $CHECK_TAG ]]; then |
| 21 | + echo "Skipping because release tag already exists" |
| 22 | + exit 1 |
| 23 | + fi |
| 24 | + - name: Output |
| 25 | + id: release_output |
| 26 | + if: ${{ steps.prepare_tag.outcome == 'success' }} |
| 27 | + run: | |
| 28 | + echo "::set-output name=tag::${{ env.TAG }}" |
| 29 | + outputs: |
| 30 | + tag: ${{ steps.release_output.outputs.tag }} |
| 31 | + |
| 32 | + build: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + needs: check-release-tag |
| 35 | + if: ${{ needs.check-release-tag.outputs.tag }} |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v2 |
| 38 | + - uses: actions/setup-node@v2 |
| 39 | + with: |
| 40 | + node-version: 16.x |
| 41 | + - run: npm install |
| 42 | + |
| 43 | + publish-npm: |
| 44 | + runs-on: ubuntu-latest |
| 45 | + needs: build |
| 46 | + if: ${{ needs.check-release-tag.outputs.tag }} |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v2 |
| 49 | + - uses: actions/setup-node@v2 |
| 50 | + with: |
| 51 | + node-version: 16.x |
| 52 | + registry-url: https://registry.npmjs.org/ |
| 53 | + scope: '@pusher' |
| 54 | + - run: npm install |
| 55 | + - run: npm publish --dry-run --verbose --access public |
| 56 | + env: |
| 57 | + NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}} |
| 58 | + |
| 59 | + create-github-release: |
| 60 | + runs-on: ubuntu-latest |
| 61 | + needs: publish-npm |
| 62 | + if: ${{ needs.check-release-tag.outputs.tag }} |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v2 |
| 65 | + - name: Prepare tag |
| 66 | + run: | |
| 67 | + export TAG=v$(jq -r '.version' package.json) |
| 68 | + echo "PRE_RELEASE=false" >> $GITHUB_ENV |
| 69 | + echo "TAG=$TAG" >> $GITHUB_ENV |
| 70 | + - name: Check pre release |
| 71 | + if: contains(env.TAG, 'beta') |
| 72 | + run: echo "PRE_RELEASE=true" >> $GITHUB_ENV |
| 73 | + - name: Setup git |
| 74 | + run: | |
| 75 | + git config user.email "[email protected]" |
| 76 | + git config user.name "Pusher CI" |
| 77 | + - name: Prepare description |
| 78 | + run: | |
| 79 | + csplit -s CHANGELOG.md "/##/" {0} |
| 80 | + cat xx01 > CHANGELOG.tmp |
| 81 | + - name: Create Release |
| 82 | + uses: actions/create-release@v1 |
| 83 | + env: |
| 84 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + with: |
| 86 | + tag_name: ${{ env.TAG }} |
| 87 | + release_name: ${{ env.TAG }} |
| 88 | + body_path: CHANGELOG.tmp |
| 89 | + draft: false |
| 90 | + prerelease: ${{ env.PRE_RELEASE }} |
0 commit comments