|
| 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 | +
|
| 20 | + export CHECK_TAG=$(git tag | grep $TAG) |
| 21 | + if [[ $CHECK_TAG ]]; then |
| 22 | + echo "Skipping because release tag already exists" |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | + - name: Output |
| 26 | + id: release_output |
| 27 | + if: ${{ steps.prepare_tag.outcome == 'success' }} |
| 28 | + run: | |
| 29 | + echo "::set-output name=tag::${{ env.TAG }}" |
| 30 | + outputs: |
| 31 | + tag: ${{ steps.release_output.outputs.tag }} |
| 32 | + |
| 33 | + create-github-release: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + needs: check-release-tag |
| 36 | + if: ${{ needs.check-release-tag.outputs.tag }} |
| 37 | + steps: |
| 38 | + - uses: actions/checkout@v2 |
| 39 | + - name: Prepare tag |
| 40 | + run: | |
| 41 | + export TAG=v$(jq -r '.version' package.json) |
| 42 | + echo "TAG=$TAG" >> $GITHUB_ENV |
| 43 | + - name: Setup git |
| 44 | + run: | |
| 45 | + git config user.email "pusher-ci@pusher.com" |
| 46 | + git config user.name "Pusher CI" |
| 47 | + - name: Prepare description |
| 48 | + run: | |
| 49 | + csplit -s CHANGELOG.md "/##/" {1} |
| 50 | + cat xx01 > CHANGELOG.tmp |
| 51 | + - name: Create Release |
| 52 | + uses: actions/create-release@v1 |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + with: |
| 56 | + tag_name: ${{ env.TAG }} |
| 57 | + release_name: ${{ env.TAG }} |
| 58 | + body_path: CHANGELOG.tmp |
| 59 | + draft: false |
| 60 | + prerelease: false |
| 61 | + |
| 62 | + publish-to-npm: |
| 63 | + runs-on: ubuntu-latest |
| 64 | + needs: create-github-release |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v2 |
| 67 | + - uses: flood-io/is-published-on-npm@8478347e2650eb228d303975415458183d0a37e4 |
| 68 | + id: is-published |
| 69 | + - run: echo "This version is already published on NPM" |
| 70 | + if: ${{ steps.is-published.outputs.published == 'true' }} |
| 71 | + - uses: actions/setup-node@v2 |
| 72 | + if: ${{ steps.is-published.outputs.published == 'false' }} |
| 73 | + with: |
| 74 | + node-version: "14" |
| 75 | + registry-url: https://registry.npmjs.org/ |
| 76 | + - run: npm install |
| 77 | + if: ${{ steps.is-published.outputs.published == 'false' }} |
| 78 | + - run: npm publish --access public |
| 79 | + if: ${{ steps.is-published.outputs.published == 'false' }} |
| 80 | + env: |
| 81 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 82 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
0 commit comments