|
7 | 7 | description: 'Enter release PR number'
|
8 | 8 | required: true
|
9 | 9 | type: number
|
| 10 | + issue_comment: |
| 11 | + types: [created] |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + pull-requests: write |
10 | 16 |
|
11 | 17 | jobs:
|
12 | 18 | release_notes:
|
13 | 19 | 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') }} |
14 | 22 | steps:
|
15 |
| - - uses: actions/checkout@v3 |
| 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 |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + ref: refs/pull/${{ github.event_name == 'issue_comment' && github.event.issue.number || inputs.releasePr }}/head |
| 45 | + |
16 | 46 |
|
| 47 | + # Setup Node.js and npm install |
17 | 48 | - name: actions/setup
|
18 | 49 | uses: ./.github/actions/setup
|
19 | 50 |
|
|
42 | 73 | HIGHLIGHTS: ${{ steps.highlights.outputs.highlights }}
|
43 | 74 |
|
44 | 75 | # 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 }} |
46 | 77 | shell: bash
|
47 | 78 | env:
|
48 | 79 | GITHUB_TOKEN: ${{ github.token }}
|
0 commit comments