Skip to content

Commit 19af702

Browse files
committed
wip: duplicate formal to fix posting comments
Duplicate formal so the event trigger can be set to pull_request_target and fix posting comments. This event allows the workflow to do things like label or comment on pull requests from forks, but it's not recommended for build jobs due to security implications. The build jobs still depends on formal that's why it has a duplicate one with less privileges. It doesn't look like there's an easy and secure way to have a workflow with lower privileges (e.g. build) depend on workflow with higher ones (e.g. formal or labeler that modify a PR). There's only the reverse with going from lower privileges to higher ones with workflow_run, for example when posting build results after a build to a PR. Either switching existing combined workflow to pull_request_target or splitting it into formal and build and switching build to workflow_run gives build unsafe privileges. Splitting and switching build to workflow_dispatch requires a custom token. wip: switch to workflow_dispatch Fixes: 7658669 ("multi-arch-test-build: post formal summaries to PR") Link: https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target Link: https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/ Signed-off-by: George Sapkin <[email protected]>
1 parent 944166f commit 19af702

File tree

3 files changed

+343
-39
lines changed

3 files changed

+343
-39
lines changed

.github/workflows/formal.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Test Formalities
2+
3+
on:
4+
pull_request_target:
5+
6+
permissions:
7+
contents: read
8+
pull-requests: write
9+
10+
jobs:
11+
formalities:
12+
name: Test Formalities
13+
uses: openwrt/actions-shared-workflows/.github/workflows/formal.yml@main
14+
with:
15+
post_comment: true
16+
17+
label_formality_status:
18+
name: Add Formality Status
19+
runs-on: ubuntu-slim
20+
needs: formalities
21+
if: always()
22+
23+
steps:
24+
- name: Trigger build
25+
if: needs.formalities.result == 'success'
26+
uses: actions/github-script@v8
27+
with:
28+
github-token: ${{ secrets.DEFAULT_TOKEN }}
29+
script: |
30+
await github.rest.actions.createWorkflowDispatch({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
workflow_id: 'multi-arch-test-build.yml',
34+
ref: 'master',
35+
inputs: {
36+
pr_number: context.issue.number.toString(),
37+
},
38+
});
39+
40+
- name: Add 'not following guidelines' label
41+
if: needs.formalities.result == 'failure'
42+
uses: buildsville/[email protected]
43+
with:
44+
token: ${{ secrets.GITHUB_TOKEN }}
45+
labels: "not following guidelines"
46+
type: add
47+
48+
- name: Remove 'not following guidelines' label
49+
if: needs.formalities.result == 'success'
50+
uses: buildsville/[email protected]
51+
with:
52+
token: ${{ secrets.GITHUB_TOKEN }}
53+
labels: "not following guidelines"
54+
type: remove

.github/workflows/labeler.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
name: 'Pull Request Labeler'
1+
name: Labeler
2+
23
on:
3-
- pull_request_target
4+
pull_request_target:
45

56
permissions:
67
contents: read
78
pull-requests: write
89

910
jobs:
1011
labeler:
11-
permissions:
12-
contents: read
13-
pull-requests: write
14-
15-
name: Pull Request Labeler
12+
name: Labeler
1613
runs-on: ubuntu-slim
1714
steps:
18-
- uses: actions/labeler@v6
15+
- name: Label pull request
16+
uses: actions/labeler@v6
1917
with:
2018
repo-token: '${{ secrets.GITHUB_TOKEN }}'
2119
sync-labels: true

0 commit comments

Comments
 (0)