|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + types: [closed] |
| 8 | + workflow_dispatch: # force release |
| 9 | + |
| 10 | +jobs: |
| 11 | + check: |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + runs-on: ubuntu-latest |
| 15 | + if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch' |
| 16 | + outputs: |
| 17 | + EXISTS_TAG: ${{ steps.tag_check.outputs.EXISTS_TAG }} |
| 18 | + steps: |
| 19 | + - name: Checkout |
| 20 | + uses: actions/checkout@v3 |
| 21 | + - name: Set PACKAGE_VERSION |
| 22 | + run: echo "PACKAGE_VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV |
| 23 | + - name: Tag Check |
| 24 | + id: tag_check |
| 25 | + run: | |
| 26 | + GET_API_URL="https://api.github.com/repos/${GITHUB_REPOSITORY}/git/ref/tags/${TAG_NAME}" |
| 27 | + http_status_code=$(curl -LI $GET_API_URL -o /dev/null -w '%{http_code}\n' -s \ |
| 28 | + -H "Authorization: token ${GITHUB_TOKEN}") |
| 29 | + if [ "$http_status_code" -ne "404" ] ; then |
| 30 | + echo "EXISTS_TAG=true" >> $GITHUB_OUTPUT |
| 31 | + else |
| 32 | + echo "EXISTS_TAG=false" >> $GITHUB_OUTPUT |
| 33 | + fi |
| 34 | + env: |
| 35 | + TAG_NAME: v${{ env.PACKAGE_VERSION }} |
| 36 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + release: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + needs: check |
| 40 | + if: always() && (needs.check.outputs.EXISTS_TAG == 'false') |
| 41 | + permissions: |
| 42 | + contents: write |
| 43 | + issues: write |
| 44 | + pull-requests: write |
| 45 | + packages: write |
| 46 | + steps: |
| 47 | + - name: Checkout |
| 48 | + uses: actions/checkout@v3 |
| 49 | + - name: Setup Node |
| 50 | + uses: actions/setup-node@v3 |
| 51 | + with: |
| 52 | + node-version: 20 |
| 53 | + - name: Git Identity |
| 54 | + run: | |
| 55 | + git config --global user.name 'github-actions[bot]' |
| 56 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 57 | + git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY |
| 58 | + env: |
| 59 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 60 | + - name: Set PACKAGE_VERSION |
| 61 | + run: echo "PACKAGE_VERSION=$(cat package.json | jq -r .version)" >> $GITHUB_ENV |
| 62 | + - name: Create Git Tag |
| 63 | + uses: pkgdeps/git-tag-action@v2 |
| 64 | + with: |
| 65 | + version: ${{ env.PACKAGE_VERSION }} |
| 66 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + github_repo: ${{ github.repository }} |
| 68 | + git_commit_sha: ${{ github.sha }} |
| 69 | + git_tag_prefix: "v" |
| 70 | + - name: Create Release |
| 71 | + id: create_release |
| 72 | + uses: softprops/action-gh-release@v1 |
| 73 | + env: |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + with: |
| 76 | + tag_name: v${{ env.PACKAGE_VERSION }} |
| 77 | + release_name: ${{ github.event.pull_request.title }} |
| 78 | + body: ${{ github.event.pull_request.body }} |
| 79 | + draft: false |
| 80 | + prerelease: false |
| 81 | + generate_release_notes: ${{ !github.event.pull_request.body }} |
| 82 | + - uses: actions/github-script@v6 |
| 83 | + if: github.event_name != 'workflow_dispatch' |
| 84 | + with: |
| 85 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 86 | + script: | |
| 87 | + github.rest.issues.createComment({ |
| 88 | + issue_number: context.issue.number, |
| 89 | + owner: context.repo.owner, |
| 90 | + repo: context.repo.repo, |
| 91 | + body: '🎉 Release https://github.com/${{ github.repository }}/releases/tag/v${{ env.PACKAGE_VERSION }}' |
| 92 | + }) |
0 commit comments