Open History to see the last commit
1name: PR
2
3on:
4 pull_request:
5
6concurrency:
7 group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
8 cancel-in-progress: true
9
10env:
11 NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
12
13permissions:
14 contents: read
15
16jobs:
17 test:
18 name: Test
19 runs-on: ubuntu-latest
20 steps:
21 - name: Checkout
22 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
23 with:
24 fetch-depth: 0
25 persist-credentials: false
26 - name: Setup Tools
27 uses: TanStack/config/.github/setup@190f659075ff0845850e330883eb26d7ffd0671f # main
28 - name: Get base and head commits for `nx affected`
29 uses: nrwl/nx-set-shas@3e9ad7370203c1e93d109be57f3b72eb0eb511b1 # v4.4.0
30 with:
31 main-branch-name: main
32 - name: Run Checks
33 run: pnpm run test:pr
34 coverage:
35 name: Coverage
36 runs-on: ubuntu-latest
37 steps:
38 - name: Checkout
39 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
40 with:
41 fetch-depth: 0
42 persist-credentials: false
43 - name: Setup Tools
44 uses: TanStack/config/.github/setup@190f659075ff0845850e330883eb26d7ffd0671f # main
45 - name: Get base and head commits for `nx affected`
46 uses: nrwl/nx-set-shas@3e9ad7370203c1e93d109be57f3b72eb0eb511b1 # v4.4.0
47 with:
48 main-branch-name: main
49 # Stashed outside the working tree because checking out the merge base
50 # would otherwise remove it — the script may be added or changed by the
51 # very PR under test. Both runs and the comparison use this copy, so all
52 # three agree on the version.
53 - name: Stage the coverage script
54 run: cp scripts/coverage-check.mjs "$RUNNER_TEMP/coverage-check.mjs"
55 # The set of packages to measure is decided once, here, so that the base
56 # run measures exactly what the head run does. `--with-target` keeps out
57 # projects that have no test:coverage script, so a docs-only PR resolves
58 # to an empty list rather than erroring in run-many.
59 - name: Resolve affected packages
60 id: affected
61 run: |
62 list=$(pnpm exec nx show projects --affected --with-target=test:coverage --exclude='examples/**,testing/**' --json | jq -r 'sort | join(",")')
63 echo "list=$list" >> "$GITHUB_OUTPUT"
64 echo "Measuring: ${list:-<none>}"
65 - name: Coverage for this PR
66 if: steps.affected.outputs.list != ''
67 # Via env, not `${{ }}` inside run: project names come from the PR's own
68 # files, so interpolating them into the shell would be injectable.
69 env:
70 PROJECTS: ${{ steps.affected.outputs.list }}
71 run: |
72 rm -rf packages/*/coverage
73 pnpm exec nx run-many --targets=test:coverage --projects="$PROJECTS" --outputStyle=static -- --coverage.reporter=json-summary --coverage.include='src/**'
74 node "$RUNNER_TEMP/coverage-check.mjs" --collect "$RUNNER_TEMP/cov-head" --expect "$PROJECTS"
75 # Re-measuring the merge-base is normally a set of Nx Cloud cache
76 # restores seeded by the Coverage workflow on main: the task hashes are
77 # identical, and `test:coverage` declares its coverage dir as an output,
78 # so the summaries come back without the tests re-running.
79 - name: Coverage for the merge base
80 if: steps.affected.outputs.list != ''
81 env:
82 PROJECTS: ${{ steps.affected.outputs.list }}
83 run: |
84 git checkout --force --detach "$NX_BASE"
85 # coverage/ is gitignored, so the checkout leaves this PR's results in
86 # place — without this the base collection silently re-reads head's
87 # numbers and every delta comes out as 0.00.
88 rm -rf packages/*/coverage
89 pnpm install --frozen-lockfile
90 # Intersect with projects that have test:coverage on the base commit
91 # (added packages, or packages that gained the script in this PR).
92 printf '%s\n' "$PROJECTS" | tr ',' '\n' | sort > /tmp/wanted
93 pnpm exec nx show projects --with-target=test:coverage --json | jq -r '.[]' | sort > /tmp/available
94 base_list=$(comm -12 /tmp/wanted /tmp/available | paste -sd, -)
95 if [ -z "$base_list" ]; then
96 echo "No affected package has test:coverage on the base commit; treating all as new."
97 mkdir -p "$RUNNER_TEMP/cov-base"
98 exit 0
99 fi
100 # Extra reporters/include so a merge-base whose scripts are still
101 # `vitest run --coverage` still writes coverage-summary.json.
102 pnpm exec nx run-many --targets=test:coverage --projects="$base_list" --outputStyle=static -- --coverage.reporter=json-summary --coverage.include='src/**'
103 node "$RUNNER_TEMP/coverage-check.mjs" --collect "$RUNNER_TEMP/cov-base" --expect "$base_list"
104 - name: Compare
105 if: steps.affected.outputs.list != ''
106 run: |
107 node "$RUNNER_TEMP/coverage-check.mjs" \
108 --base "$RUNNER_TEMP/cov-base" \
109 --head "$RUNNER_TEMP/cov-head"
110 preview:
111 name: Preview
112 runs-on: ubuntu-latest
113 permissions:
114 contents: read
115 pull-requests: write
116 steps:
117 - name: Checkout
118 uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
119 with:
120 persist-credentials: false
121 - name: Setup Tools
122 uses: TanStack/config/.github/setup@190f659075ff0845850e330883eb26d7ffd0671f # main
123 - name: Build Packages
124 run: pnpm run build:all
125 - name: Publish Previews
126 run: pnpx pkg-pr-new publish --pnpm './packages/*'