From fa5116997ba98fce389bfbf519f1b3338fd0e6a7 Mon Sep 17 00:00:00 2001 From: Brady Holt Date: Tue, 9 Jul 2024 16:24:38 -0500 Subject: [PATCH] Comment on PRs when released --- .github/workflows/publish.yml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2d4f0ab..09bf768 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -46,7 +46,34 @@ jobs: name: npm-logs path: ~/.npm/_logs - name: Create a Release + id: create-release uses: softprops/action-gh-release@v1 with: tag_name: ${{ steps.push.outputs.tag-name }} - generate_release_notes: true + generate_release_notes: true + - name: Comment on PRs with link to release they are included in + uses: actions/github-script@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}) 🎉.` + }) + }