Skip to content

Commit 16870f6

Browse files
committed
release: only add the PR comment about the announcement at the end
It makes little sense to add the PR comment that advises how to announce the release before the release actually is available. So let's prepare the PR comment like before, but only add it after the GitHub Release has been published. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7c2c9db commit 16870f6

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

.github/actions/github-release/action.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ inputs:
4242
git_artifacts_aarch64_workflow_run_id:
4343
description: 'ID of the git-artifacts (aarch64) workflow run'
4444
required: true
45+
pull-request-number:
46+
description: 'The number of the pull request to comment on'
47+
required: false
48+
pull-request-comment:
49+
description: 'The comment to add to the pull request'
50+
required: false
4551
outputs:
4652
github-release-url:
4753
description: "The GitHub Release URL"
@@ -72,6 +78,7 @@ runs:
7278
path: bundle-artifacts
7379
- name: create release and upload release assets
7480
uses: actions/github-script@v7
81+
id: release
7582
with:
7683
script: |
7784
const {
@@ -171,6 +178,21 @@ runs:
171178
console.log(`::warning::could not create Discussion`)
172179
console.log(e)
173180
}
181+
core.setOutput('token', state.accessToken)
182+
- name: Add a comment about the announcement email to the Pull Request
183+
if: inputs.pull-request-number != ''
184+
uses: actions/github-script@v7
185+
with:
186+
github-token: ${{ steps.release.outputs.token }}
187+
script: |
188+
const req = {
189+
owner: ${{ toJSON(inputs.owner) }},
190+
repo: ${{ toJSON(inputs.repo) }},
191+
issue_number: ${{ inputs.pull-request-number }},
192+
body: ${{ toJSON(inputs.pull-request-comment) }},
193+
}
194+
195+
await github.rest.issues.createComment(req)
174196
- name: update check-run
175197
if: always()
176198
uses: ./.github/actions/check-run-action

.github/workflows/release-git.yml

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
ver: ${{ steps.bundle-artifacts.outputs.ver }}
3333
git-rev: ${{ steps.bundle-artifacts.outputs.git-rev }}
3434
release-notes: ${{ steps.bundle-artifacts.outputs.release-notes }}
35+
pull-request-number: ${{ steps.announcement.outputs.pull-request-number }}
36+
pull-request-comment: ${{ steps.announcement.outputs.pull-request-comment }}
3537
steps:
3638
- uses: actions/checkout@v4
3739
- name: The `release` branch must be up to date
@@ -110,28 +112,20 @@ jobs:
110112
name: bundle-artifacts
111113
path: bundle-artifacts
112114
- name: Publish announcement mail as a stand-alone artifact
113-
id: announcement
115+
id: announcement-email
114116
uses: actions/upload-artifact@v4
115117
with:
116118
name: announcement
117119
path: bundle-artifacts/announce-*
118-
- uses: actions/create-github-app-token@v1
119-
id: app-token
120-
with:
121-
app-id: ${{ secrets.GH_APP_ID }}
122-
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
123-
owner: ${{ env.OWNER }}
124-
repositories: |
125-
${{ env.REPO }}
126-
- name: Add a comment about the announcement email to the Pull Request
120+
- name: Prepare a comment about the announcement email to the Pull Request
121+
id: announcement
127122
uses: actions/github-script@v7
128123
with:
129-
github-token: ${{ steps.app-token.outputs.token }}
130124
script: |
131125
const gitSHA = ${{ toJson(steps.bundle-artifacts.outputs.git-rev) }}
132126
const tagName = ${{ toJson(steps.bundle-artifacts.outputs.tag-name) }}
133127
const ver = ${{ toJson(steps.bundle-artifacts.outputs.ver) }}
134-
const announcementURL = ${{ toJson(steps.announcement.outputs.artifact-url) }}
128+
const announcementURL = ${{ toJson(steps.announcement-email.outputs.artifact-url) }}
135129
136130
const nth = (n) => {
137131
const suffix = ((n + 89) % 100) > 2 && ['th', 'st', 'nd', 'rd'][n % 10] || 'th'
@@ -152,16 +146,11 @@ jobs:
152146
const { data } = await github.rest.search.issuesAndPullRequests({ q })
153147
if (data.items.length === 1) {
154148
const author = data.items[0].user.login
155-
const req = {
156-
owner: process.env.OWNER,
157-
repo: process.env.REPO,
158-
issue_number: data.items[0].number,
159-
body: `@${author}, ${body}`,
160-
}
161-
162-
await github.rest.issues.createComment(req)
149+
core.setOutput('pull-request-number', data.items[0].number)
150+
core.setOutput('pull-request-comment', `@${author}, ${body}`)
151+
core.info(`Prepared a comment to add to ${data.items[0].html_url}:\n@${author}, ${body}`)
163152
} else {
164-
core.warning(`${data.items.length} PRs found for ${gitSHA}, not posting a comment, would have posted\n${body}`)
153+
core.warning(`${data.items.length} PRs found for ${gitSHA}, not posting a comment, would have posted:\n${body}`)
165154
}
166155
github-release:
167156
needs: ['setup']
@@ -183,6 +172,8 @@ jobs:
183172
git_artifacts_i686_workflow_run_id: ${{ env.I686_WORKFLOW_RUN_ID }}
184173
git_artifacts_x86_64_workflow_run_id: ${{ env.X86_64_WORKFLOW_RUN_ID }}
185174
git_artifacts_aarch64_workflow_run_id: ${{ env.AARCH64_WORKFLOW_RUN_ID }}
175+
pull-request-number: ${{ needs.setup.outputs.pull-request-number }}
176+
pull-request-comment: ${{ needs.setup.outputs.pull-request-comment }}
186177
gitforwindows-site:
187178
needs: ['setup', 'github-release']
188179
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)