Publish #42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version_type: | |
| type: choice | |
| description: Version type | |
| default: minor | |
| options: | |
| - major | |
| - minor | |
| - patch | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | |
| with: | |
| token: ${{ secrets.GH_API_TOKEN }} | |
| - name: Setup git repo | |
| env: | |
| GH_API_TOKEN: ${{ secrets.GH_API_TOKEN }} | |
| run: | | |
| git config user.name $GITHUB_ACTOR | |
| git config user.email gh-actions-${GITHUB_ACTOR}@github.com | |
| - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6 | |
| with: | |
| node-version: 24 | |
| registry-url: "https://registry.npmjs.org" | |
| - run: npm install | |
| - run: npm run build | |
| - run: npm run test | |
| - name: Bump Version | |
| run: | | |
| git add dist/* | |
| npm version ${{ github.event.inputs.version_type }} --force -m "Version %s" | |
| - name: Push release commit and tag to GitHub | |
| id: push | |
| run: | | |
| git push --tags | |
| echo "tag-name=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT | |
| - name: Publish to npm | |
| run: | | |
| npm set //registry.npmjs.org/:_authToken ${{ secrets.NODE_AUTH_TOKEN }} | |
| npm publish | |
| - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | |
| if: failure() | |
| with: | |
| name: npm-logs | |
| path: ~/.npm/_logs | |
| - name: Create a Release | |
| id: create-release | |
| uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 # v1 | |
| with: | |
| tag_name: ${{ steps.push.outputs.tag-name }} | |
| generate_release_notes: true | |
| - name: Comment on PRs with link to release they are included in | |
| uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6 | |
| env: | |
| RELEASE_ID: ${{ steps.create-release.outputs.id }} | |
| with: | |
| script: | | |
| const releaseId = process.env.RELEASE_ID; | |
| console.log(`Fetching release_id: ${releaseId} ...`); | |
| const getReleaseResponse = await github.rest.repos.getRelease({ | |
| release_id: process.env.RELEASE_ID, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo | |
| }); | |
| const release = getReleaseResponse.data; | |
| const prNumbersInRelease = new Set(Array.from(release.body.matchAll(/\/pull\/(\d+)/g)).map(p=>p[1])); | |
| for(let prNumber of prNumbersInRelease) { | |
| console.log(`Adding comment on PR #${prNumber} ...`); | |
| await github.rest.issues.createComment({ | |
| issue_number: prNumber, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `The changes in this PR were just released in [${release.name}](https://github.com/${context.repo.owner}/${context.repo.repo}/releases/tag/${release.tag_name}) 🎉.` | |
| }) | |
| } |