|
1 | 1 | name: test |
2 | 2 |
|
3 | | -# Runs the Node test suite on every PR and on pushes to main. Originally |
4 | | -# Ubuntu-only (#198): PR checks were Cursor Bugbot + Security, neither of |
5 | | -# which runs `npm test`, so a green PR did NOT mean the tests passed. |
| 3 | +# Runs PR governance checks and the Node test suite. |
6 | 4 | # |
7 | | -# This workflow now also runs the suite on Windows + macOS via a second job |
8 | | -# (test-cross). #198 explicitly flagged Windows / macOS as a follow-up: the |
9 | | -# suite still has Linux-specific assumptions (symlink reliance, hard-coded |
10 | | -# ~/.volta layout, POSIX-style path equality) that would fail on those |
11 | | -# hosts. test-cross runs on PRs in **advisory** mode (continue-on-error) |
12 | | -# so those red signals are visible to reviewers without blocking merge |
13 | | -# while the suite is being made hermetic. Each fix can flip its tests |
14 | | -# from "red on Win/Mac" to "green on Win/Mac" incrementally. Once the |
15 | | -# remaining failures are cleaned up, drop `continue-on-error: true` and |
16 | | -# add `test-cross` to required checks to make cross-platform green a |
17 | | -# hard merge gate. |
| 5 | +# Pull requests use pull_request_target on self-hosted Linux runners and only |
| 6 | +# execute trusted base-branch code against PR metadata. They intentionally do not |
| 7 | +# checkout, install, or test PR-controlled code on the self-hosted runner. |
| 8 | +# Pushes to main run the full Node suite on the merged repository state. |
18 | 9 | # |
19 | | -# main pushes skip test-cross to keep private-repo billing predictable |
20 | | -# (macos-latest is 10x and windows-latest is 2x the ubuntu rate). |
| 10 | +# Cross-platform Windows/macOS coverage remains a future advisory lane once it |
| 11 | +# can run on available self-hosted runners or an explicitly funded hosted pool. |
21 | 12 |
|
22 | 13 | on: |
23 | | - pull_request: |
| 14 | + pull_request_target: |
24 | 15 | push: |
25 | 16 | branches: [main] |
26 | 17 |
|
27 | 18 | permissions: |
28 | 19 | contents: read |
| 20 | + pull-requests: read |
29 | 21 |
|
30 | 22 | concurrency: |
31 | | - group: test-${{ github.workflow }}-${{ github.ref }} |
| 23 | + group: test-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
32 | 24 | cancel-in-progress: true |
33 | 25 |
|
34 | 26 | jobs: |
35 | 27 | test: |
36 | | - runs-on: ubuntu-latest |
| 28 | + runs-on: [self-hosted, Linux, X64] |
37 | 29 | steps: |
38 | | - - uses: actions/checkout@v4 |
| 30 | + - name: Checkout trusted base for PR guard |
| 31 | + if: github.event_name == 'pull_request_target' |
| 32 | + uses: actions/checkout@v4 |
| 33 | + with: |
| 34 | + ref: ${{ github.event.pull_request.base.sha }} |
| 35 | + fetch-depth: 1 |
| 36 | + |
| 37 | + - name: Checkout merged code for main tests |
| 38 | + if: github.event_name == 'push' |
| 39 | + uses: actions/checkout@v4 |
39 | 40 |
|
40 | 41 | - uses: actions/setup-node@v4 |
41 | 42 | with: |
42 | 43 | node-version: '22' # engines: node >=22.12 |
43 | 44 | cache: npm |
44 | 45 |
|
45 | | - - name: Install dependencies |
46 | | - run: npm ci |
47 | | - |
48 | | - - name: Run tests (node --test) |
49 | | - run: npm test |
50 | | - |
51 | | - test-cross: |
52 | | - # Advisory cross-platform run: PR-only (skips main push to save billing), |
53 | | - # continue-on-error so a known Win/Mac regression does not block merge |
54 | | - # while the suite is being hardened. Reviewers still see the result and |
55 | | - # can opt-in to wait for a fix on a per-PR basis. |
56 | | - if: github.event_name == 'pull_request' |
57 | | - strategy: |
58 | | - fail-fast: false |
59 | | - matrix: |
60 | | - os: [windows-latest, macos-latest] |
61 | | - runs-on: ${{ matrix.os }} |
62 | | - continue-on-error: true |
63 | | - steps: |
64 | | - - uses: actions/checkout@v4 |
| 46 | + - name: Collect changed files for governance guard |
| 47 | + if: github.event_name == 'pull_request_target' |
| 48 | + env: |
| 49 | + GH_TOKEN: ${{ github.token }} |
| 50 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 51 | + REPO: ${{ github.repository }} |
| 52 | + run: | |
| 53 | + gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files" --jq '.[].filename' > pr-changed-files.txt |
65 | 54 |
|
66 | | - - uses: actions/setup-node@v4 |
67 | | - with: |
68 | | - node-version: '22' |
69 | | - cache: npm |
| 55 | + - name: Harness/evaluator governance guard |
| 56 | + if: github.event_name == 'pull_request_target' |
| 57 | + env: |
| 58 | + PR_BODY: ${{ github.event.pull_request.body }} |
| 59 | + PR_CHANGED_FILES_FILE: pr-changed-files.txt |
| 60 | + run: node scripts/harness-governance-check.js |
70 | 61 |
|
71 | 62 | - name: Install dependencies |
| 63 | + if: github.event_name == 'push' |
72 | 64 | run: npm ci |
73 | 65 |
|
74 | 66 | - name: Run tests (node --test) |
| 67 | + if: github.event_name == 'push' |
75 | 68 | run: npm test |
0 commit comments