Skip to content

Commit 99cd066

Browse files
authored
chore(NODE-5768): add comment trigger for release notes (#638)
1 parent a382485 commit 99cd066

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

.github/workflows/release_notes.yml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,44 @@ on:
77
description: 'Enter release PR number'
88
required: true
99
type: number
10+
issue_comment:
11+
types: [created]
12+
13+
permissions:
14+
contents: write
15+
pull-requests: write
1016

1117
jobs:
1218
release_notes:
1319
runs-on: ubuntu-latest
20+
# Run only if dispatched or comment on a pull request
21+
if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'issue_comment' && github.event.issue.pull_request && github.event.comment.body == 'run release_notes') }}
1422
steps:
23+
# Determine if the triggering_actor is allowed to run this action
24+
# We only permit maintainers
25+
# Not only is 'triggering_actor' common between the trigger events it will also change if someone re-runs an old job
26+
- name: check if triggering_actor is allowed to generate notes
27+
env:
28+
GITHUB_TOKEN: ${{ github.token }}
29+
COMMENTER: ${{ github.triggering_actor && github.triggering_actor || 'empty_triggering_actor' }}
30+
API_ENDPOINT: /repos/${{ github.repository }}/collaborators?permission=maintain
31+
shell: bash
32+
run: |
33+
if [ $COMMENTER = "empty_triggering_actor" ]; then exit 1; fi
34+
set -o pipefail
35+
if gh api "$API_ENDPOINT" --paginate --jq ".[].login" | grep -q "^$COMMENTER\$"; then
36+
echo "$COMMENTER permitted to trigger notes!" && exit 0
37+
else
38+
echo "$COMMENTER not permitted to trigger notes" && exit 1
39+
fi
40+
41+
# checkout the HEAD ref from prNumber
1542
- uses: actions/checkout@v3
43+
with:
44+
ref: refs/pull/${{ github.event_name == 'issue_comment' && github.event.issue.number || inputs.releasePr }}/head
45+
1646

47+
# Setup Node.js and npm install
1748
- name: actions/setup
1849
uses: ./.github/actions/setup
1950

@@ -42,7 +73,7 @@ jobs:
4273
HIGHLIGHTS: ${{ steps.highlights.outputs.highlights }}
4374

4475
# Update the release PR body
45-
- run: gh pr edit ${{ inputs.releasePr }} --body-file ${{ steps.release_notes.outputs.release_notes_path }}
76+
- run: gh pr edit ${{ github.event_name == 'issue_comment' && github.event.issue.number || inputs.releasePr }} --body-file ${{ steps.release_notes.outputs.release_notes_path }}
4677
shell: bash
4778
env:
4879
GITHUB_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)