33name : Update 3rdparty command
44
55on :
6- issue_comment :
6+ issue_comment : # zizmor: ignore[dangerous-triggers]
77 types : created
88
99permissions :
@@ -14,11 +14,40 @@ jobs:
1414 runs-on : ubuntu-latest
1515 permissions :
1616 contents : none
17+ pull-requests : read
1718
1819 # On pull requests and if the comment starts with `/update-3rdparty`
1920 if : github.event.issue.pull_request != '' && startsWith(github.event.comment.body, '/update-3rdparty')
2021
2122 steps :
23+ # issue_comment events carry no pull_request context in their payload, so we
24+ # must fetch the PR via the API. This also gives us base.ref for free, avoiding
25+ # a second API call. The GITHUB_TOKEN needs pull-requests:read (granted above).
26+ - name : Get pull request metadata
27+ uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
28+ id : get-pr
29+ with :
30+ github-token : ${{ secrets.GITHUB_TOKEN }}
31+ script : |
32+ const pull = await github.rest.pulls.get({
33+ owner: context.repo.owner,
34+ repo: context.repo.repo,
35+ pull_number: context.issue.number,
36+ });
37+ core.setOutput('head_repo', pull.data.head.repo?.full_name ?? '');
38+ core.setOutput('base_ref', pull.data.base.ref);
39+
40+ - name : Disabled on forks
41+ if : steps.get-pr.outputs.head_repo != github.repository
42+ run : |
43+ echo 'Can not execute /update-3rdparty on forks'
44+ exit 1
45+
46+ - name : Check actor permission
47+ uses : skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0
48+ with :
49+ require : write
50+
2251 - name : Add reaction on start
2352 uses : peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
2453 with :
@@ -27,43 +56,31 @@ jobs:
2756 comment-id : ${{ github.event.comment.id }}
2857 reactions : ' +1'
2958
30- - name : Disabled on forks
31- if : ${{ github.event.pull_request.head.repo.full_name != github.repository }}
32- run : |
33- echo 'Can not execute /update-3rdparty on forks'
34- exit 1
35-
3659 - name : Init branch
3760 uses : xt0rted/pull-request-comment-branch@e8b8daa837e8ea7331c0003c9c316a64c6d8b0b1 # v3.0.0
3861 id : comment-branch
3962
4063 - name : Checkout ${{ steps.comment-branch.outputs.head_ref }}
41- uses : actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 .0.1
64+ uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 .0.1
4265 with :
4366 persist-credentials : false
4467 fetch-depth : 0
4568 token : ${{ secrets.COMMAND_BOT_PAT }}
4669 ref : ${{ steps.comment-branch.outputs.head_ref }}
4770
4871 - name : Register server reference to fallback to master branch
49- uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
50- with :
51- github-token : ${{secrets.GITHUB_TOKEN}}
52- script : |
53- const baseRef = context.payload.pull_request.base.ref
54- if (baseRef === 'main' || baseRef === 'master') {
55- core.exportVariable('server_ref', 'master');
56- console.log('Setting server_ref to master');
57- } else {
58- const regex = /^stable(\d+)$/
59- const match = baseRef.match(regex)
60- if (match) {
61- core.exportVariable('server_ref', match[0]);
62- console.log('Setting server_ref to ' + match[0]);
63- } else {
64- console.log('Not based on master/main/stable*, so skipping pull 3rdparty command');
65- }
66- }
72+ env :
73+ base_ref : ${{ steps.get-pr.outputs.base_ref }}
74+ run : |
75+ if [[ "$base_ref" == "main" || "$base_ref" == "master" ]]; then
76+ echo "server_ref=master" >> "$GITHUB_ENV"
77+ echo "Setting server_ref to master"
78+ elif [[ "$base_ref" =~ ^stable[0-9]+$ ]]; then
79+ echo "server_ref=$base_ref" >> "$GITHUB_ENV"
80+ echo "Setting server_ref to $base_ref"
81+ else
82+ echo "Not based on master/main/stable*, so skipping pull 3rdparty command"
83+ fi
6784
6885 - name : Setup git
6986 run : |
0 commit comments