Skip to content

Commit 8aa4036

Browse files
committed
ci: split formal and build to fix posting comments
Separate formal from build so the event trigger can be set to pull_request_target and fix posting comments. This event allows 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. Posting comments from formal, and listening to them in build requires a custom token as well. The default GITHUB_TOKEN can't trigger workflows. 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 bbaa539 commit 8aa4036

File tree

3 files changed

+44
-41
lines changed

3 files changed

+44
-41
lines changed

.github/workflows/formal.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 Check Labels
19+
runs-on: ubuntu-slim
20+
needs: formalities
21+
if: always()
22+
23+
steps:
24+
- name: Add 'not following guidelines' label
25+
if: needs.formalities.result == 'failure'
26+
uses: buildsville/[email protected]
27+
with:
28+
token: ${{ secrets.GITHUB_TOKEN }}
29+
labels: "not following guidelines"
30+
type: add
31+
32+
- name: Remove 'not following guidelines' label
33+
if: needs.formalities.result == 'success'
34+
uses: buildsville/[email protected]
35+
with:
36+
token: ${{ secrets.GITHUB_TOKEN }}
37+
labels: "not following guidelines"
38+
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

.github/workflows/multi-arch-test-build.yml

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,8 @@ on:
55

66
permissions:
77
contents: read
8-
pull-requests: write
98

109
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 check labels
19-
runs-on: ubuntu-slim
20-
needs: formalities
21-
if: always()
22-
permissions:
23-
pull-requests: write
24-
25-
steps:
26-
- name: Add 'not following guidelines' label
27-
if: needs.formalities.result == 'failure'
28-
uses: buildsville/[email protected]
29-
with:
30-
token: ${{ secrets.GITHUB_TOKEN }}
31-
labels: "not following guidelines"
32-
type: add
33-
34-
- name: Remove 'not following guidelines' label
35-
if: needs.formalities.result == 'success'
36-
uses: buildsville/[email protected]
37-
with:
38-
token: ${{ secrets.GITHUB_TOKEN }}
39-
labels: "not following guidelines"
40-
type: remove
41-
4210
build:
4311
name: Feeds Package Test Build
44-
needs: formalities
4512
uses: openwrt/actions-shared-workflows/.github/workflows/multi-arch-test-build.yml@main

0 commit comments

Comments
 (0)