diff --git a/.github/actions/release/README.md b/.github/actions/release/README.md index 0f93d1d..41e9da5 100644 --- a/.github/actions/release/README.md +++ b/.github/actions/release/README.md @@ -7,9 +7,12 @@ and the notes are its description. ## Usage ```yaml +name: Release + on: pull_request: types: [closed] + # NOTE: some repos still use `master`. branches: [main] permissions: {} @@ -23,17 +26,19 @@ jobs: permissions: # Required to create the draft release. contents: write + # Required to comment the draft release on the pull request. + pull-requests: write steps: - # Pin to a commit of `mozilla/addons`. - uses: mozilla/addons/.github/actions/release@43401a931ebc09f2e511deed766171b0105414bc with: repo: ${{ github.repository }} sha: ${{ github.event.pull_request.merge_commit_sha }} + pr: ${{ github.event.pull_request.number }} github_token: ${{ secrets.GITHUB_TOKEN }} ``` -All three inputs are required. Outputs: `version` and `url`. +All four inputs are required. Outputs: `version` and `url`. ## Release process @@ -53,7 +58,9 @@ Here is an example for an `npm` package: # Write the release notes in the description of this commit, also the commit # title might just be "$version" or something more fancy, but it must have # the version number in it. - git commit --edit --message ":arrow_up: release $version" + # + # `--cleanup=scissors` is used to allow markdown headers in the commit body. + git commit --edit --message ":arrow_up: release $version" --cleanup=scissors git push -u origin "releases/$version" ``` diff --git a/.github/actions/release/action.yml b/.github/actions/release/action.yml index d1a9279..5110e3e 100644 --- a/.github/actions/release/action.yml +++ b/.github/actions/release/action.yml @@ -14,6 +14,9 @@ inputs: description: > The merge commit to release: it is the target of the release, its title has the version and its description has the release notes. + pr: + required: true + description: The number of the release pull request, to comment the draft on github_token: required: true description: The GitHub token @@ -36,6 +39,7 @@ runs: GH_TOKEN: ${{ inputs.github_token }} GH_REPO: ${{ inputs.repo }} sha: ${{ inputs.sha }} + pr: ${{ inputs.pr }} run: | set -o pipefail @@ -81,10 +85,16 @@ runs: echo "url=$url" >> "$GITHUB_OUTPUT" cat "$GITHUB_OUTPUT" - { - echo "### The draft release for \`$version\` is ready" - echo "" - echo "Nothing has been released yet. Publishing this draft creates the \`$version\` tag, which publishes the package:" - echo "" - echo "$url" - } >> "$GITHUB_STEP_SUMMARY" + body=$(printf '%s\n' \ + "### The draft release for \`$version\` is ready" \ + "" \ + "Nothing has been released yet. Publishing this draft creates the \`$version\` tag, which publishes the package:" \ + "" \ + "$url") + + printf '%s\n' "$body" >> "$GITHUB_STEP_SUMMARY" + + # Commenting is a convenience, so a missing `pull-requests: write` + # permission should not fail a release that has been drafted already. + printf '%s\n' "$body" | gh pr comment "$pr" --body-file - || + echo "::warning::could not comment on the release pull request."