Skip to content

Commit 569b5a4

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. Switch build to workflow_dispatch and trigger it from formal when it succeeds. Dispatching a workflow requires a fine-grained token, exposed through FORMAL_TOKEN secret. Since the workflow is no longer running in a PR context, it needs the PR info passed to it to manually make the appearance of being tied to said PR by setting run-name, and passing back individual matrix step statuses manually to the PR with all the correct info. To that end re-introduce the full build workflow that was moved to actions for easier testing with the expectation of moving it back to actions once it's fully tested. FORMAL_TOKEN requires actions: write permission. Build workflow can now be triggered from the UI, but it's limited to repo members. 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://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#workflow_dispatch Link: https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/ Link: https://securitylab.github.com/resources/github-actions-new-patterns-and-mitigations/ Signed-off-by: George Sapkin <[email protected]>
1 parent bbaa539 commit 569b5a4

File tree

3 files changed

+416
-39
lines changed

3 files changed

+416
-39
lines changed

.github/workflows/formal.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
check_formality_status:
18+
name: Check 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+
env:
27+
# Token needs actions: write
28+
TOKEN: ${{ secrets.FORMAL_TOKEN }}
29+
BASE_REF: ${{ github.base_ref }}
30+
# Workflow is running in target context, so we need to get head ref
31+
# from the event
32+
HEAD_REF: ${{ github.event.pull_request.head.ref }}
33+
PR_NAME: ${{ github.event.pull_request.title }}
34+
PR_NUMBER: ${{ github.event.pull_request.number }}
35+
run: |
36+
JSON_PAYLOAD=$(jq -n \
37+
--arg head_ref "$HEAD_REF" \
38+
--arg base_ref "$BASE_REF" \
39+
--arg pr_number "$PR_NUMBER" \
40+
--arg pr_name "$PR_NAME" \
41+
'{ref: $head_ref, inputs: {base_ref: $base_ref, pr_number: $pr_number, pr_name: $pr_name}}')
42+
43+
curl -L \
44+
-X POST \
45+
-H "Accept: application/vnd.github+json" \
46+
-H "Authorization: Bearer $TOKEN" \
47+
-H "X-GitHub-Api-Version: 2022-11-28" \
48+
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/multi-arch-test-build.yml/dispatches" \
49+
-d "$JSON_PAYLOAD"
50+
51+
- name: Add 'not following guidelines' label
52+
if: needs.formalities.result == 'failure'
53+
uses: buildsville/[email protected]
54+
with:
55+
token: ${{ secrets.GITHUB_TOKEN }}
56+
labels: "not following guidelines"
57+
type: add
58+
59+
- name: Remove 'not following guidelines' label
60+
if: needs.formalities.result == 'success'
61+
uses: buildsville/[email protected]
62+
with:
63+
token: ${{ secrets.GITHUB_TOKEN }}
64+
labels: "not following guidelines"
65+
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)