Skip to content

Commit c9aaad1

Browse files
fix(ci): harden test262 PR workflow security (#5159)
Closes #5158. This replaces the old `test262_pr.yml` flow with a safer two-phase setup: - `test262.yml`: runs under `pull_request` with minimal permissions and executes the test262 suite on PR code - `test262_comment.yml`: runs under `workflow_run` in the base repository context and updates the PR comment from an uploaded artifact Main changes: - remove untrusted execution from `pull_request_target` - disable persisted checkout credentials in the run workflow - keep the trusted comment workflow isolated from PR code - pass results through an artifact and use `body-path` for comment updates This preserves the reporting behavior while avoiding execution of PR code in a privileged workflow context.
1 parent 5dec9b2 commit c9aaad1

File tree

3 files changed

+136
-113
lines changed

3 files changed

+136
-113
lines changed

.github/workflows/test262.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: test262
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
- releases/**
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
run_test262:
18+
name: Run the test262 test suite
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 60
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
24+
with:
25+
path: boa
26+
persist-credentials: false
27+
28+
- name: Install Rust toolchain
29+
uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
30+
with:
31+
toolchain: stable
32+
33+
- name: Cache cargo
34+
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5
35+
with:
36+
path: |
37+
boa/target
38+
~/.cargo/git
39+
~/.cargo/registry
40+
key: ${{ runner.os }}-${{ runner.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }}
41+
42+
- name: Checkout the data repo
43+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
44+
with:
45+
repository: boa-dev/data
46+
path: data
47+
persist-credentials: false
48+
49+
- name: Run the test262 test suite
50+
run: |
51+
cd boa
52+
mkdir -p ../results/test262
53+
cargo run --release --bin boa_tester -- run -v -o ../results/test262
54+
cd ..
55+
56+
- name: Compare results
57+
shell: bash
58+
run: |
59+
cd boa
60+
61+
base_results="../data/test262/refs/heads/main/latest.json"
62+
pr_results="../results/test262/pull/latest.json"
63+
output_dir="../results/outputs"
64+
65+
test -f "$base_results"
66+
test -f "$pr_results"
67+
68+
comment="$(./target/release/boa_tester compare "$base_results" "$pr_results" -m)"
69+
maincommit="$(jq -r '.c' "$base_results")"
70+
71+
mkdir -p "$output_dir"
72+
{
73+
echo "<!-- test262-compliance-report -->"
74+
echo "### Test262 conformance changes"
75+
echo
76+
echo "$comment"
77+
echo
78+
echo "Tested main commit: [\`${maincommit}\`](${{ github.event.pull_request.base.repo.html_url }}/commit/${maincommit})"
79+
echo "Tested PR commit: [\`${{ github.event.pull_request.head.sha }}\`](${{ github.event.pull_request.head.repo.html_url }}/commit/${{ github.event.pull_request.head.sha }})"
80+
echo "Compare commits: ${{ github.event.pull_request.base.repo.html_url }}/compare/${maincommit}...${{ github.event.pull_request.head.sha }}"
81+
} > "$output_dir/comment.md"
82+
83+
echo "${{ github.event.pull_request.number }}" > "$output_dir/pr_number.txt"
84+
85+
- name: Upload results
86+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
87+
with:
88+
name: test262-results
89+
path: results/outputs
90+
retention-days: 1
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: test262_comment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["test262"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
13+
jobs:
14+
comment:
15+
name: Post results to PR
16+
runs-on: ubuntu-latest
17+
if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}
18+
steps:
19+
- name: Download results
20+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
21+
with:
22+
name: test262-results
23+
github-token: ${{ secrets.GITHUB_TOKEN }}
24+
run-id: ${{ github.event.workflow_run.id }}
25+
path: downloaded-results
26+
27+
- name: Read results
28+
id: results
29+
shell: bash
30+
run: |
31+
echo "pr_number=$(cat downloaded-results/pr_number.txt)" >> $GITHUB_OUTPUT
32+
33+
- name: Find Previous Comment
34+
uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4
35+
id: previous-comment
36+
with:
37+
issue-number: ${{ steps.results.outputs.pr_number }}
38+
body-includes: "<!-- test262-compliance-report -->"
39+
40+
- name: Update or create comment
41+
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5
42+
with:
43+
comment-id: ${{ steps.previous-comment.outputs.comment-id }}
44+
issue-number: ${{ steps.results.outputs.pr_number }}
45+
body-path: downloaded-results/comment.md
46+
edit-mode: replace

.github/workflows/test262_pr.yml

Lines changed: 0 additions & 113 deletions
This file was deleted.

0 commit comments

Comments
 (0)