From 6a792367cdf8fe5baeb926d7a03623c0110b6750 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Tue, 5 Jul 2022 13:35:24 +0200 Subject: [PATCH] chore: in release-please PRs, at-mention participating authors (#340) * chore: add action to mention contributors in release * checkout everything so comparison works * use origin/ * returns .stdout * don't match first parens * format nicely * format * update text * is fetch-depth 0 needed? * yes it is * chore: parallelise calls * look at .login --- .../release-please-mention-contributors.yml | 51 +++++++++++++++++++ CHANGELOG.md | 2 + 2 files changed, 53 insertions(+) create mode 100644 .github/workflows/release-please-mention-contributors.yml diff --git a/.github/workflows/release-please-mention-contributors.yml b/.github/workflows/release-please-mention-contributors.yml new file mode 100644 index 0000000..7bcee6e --- /dev/null +++ b/.github/workflows/release-please-mention-contributors.yml @@ -0,0 +1,51 @@ +on: + pull_request: + paths: + - CHANGELOG.md + +name: "release-please: mention contributors" +jobs: + mention-contributors: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: actions/github-script@v6 + id: find-authors + with: + script: | + const { stdout: diff } = await exec.getExecOutput("git diff origin/${{ github.base_ref }} -U0 CHANGELOG.md") + console.log({ diff }) + + const COMMIT_URL_REGEX = /\/commit\/(\w+)\)/g + + const matches = [...diff.matchAll(COMMIT_URL_REGEX)] + const authors = (await Promise.all(matches.map(async match => { + const ref = match[1] + const [owner, repo] = "${{ github.repository }}".split("/") + const commit = await github.rest.repos.getCommit({ owner, repo, ref }) + return commit.data.author?.login + }))).filter(Boolean) + + console.log({ authors }) + core.setOutput('authors', authors.map(login => "@" + login).join(", ")) + + - name: Find existing comment + uses: peter-evans/find-comment@v2 + id: existing-comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: "github-actions[bot]" + body-includes: "This contains contributions by " + + - name: Create or update comment + uses: peter-evans/create-or-update-comment@v2 + with: + comment-id: ${{ steps.existing-comment.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + This contains contributions by ${{ steps.find-authors.outputs.authors }}. + Release by merging this PR. + edit-mode: replace diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ec3e72..0581c39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ * **deps:** update module go.mongodb.org/mongo-driver to v1.9.0 ([#324](https://github.com/netlify/netlify-commons/issues/324)) ([42cde20](https://github.com/netlify/netlify-commons/commit/42cde20b8049a705ffb503bd1098e94e1977c6ae)) +* **feat:** this is a test entry ([bf982f57](https://github.com/netlify/netlify-commons/commit/bf982f574dcf33b4227adfd985037ef551ffdc17)) + ## [0.61.0](https://github.com/netlify/netlify-commons/compare/v0.60.1...v0.61.0) (2022-03-03)