Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(ci): avoid full history in the node rust selector (#127082)

posthog[bot]3845ef48aa2a
diff --git a/.github/workflows/ci-nodejs.yml b/.github/workflows/ci-nodejs.yml
index 157fee22f086..303745314648 100644
--- a/.github/workflows/ci-nodejs.yml
+++ b/.github/workflows/ci-nodejs.yml
@@ -161,6 +161,7 @@ jobs:
- 'proto/**'
- '.github/rust-images.yml'
- '.github/actions/rust-compute-affected/**'
+ - '.github/scripts/resolve-changed-files.sh'
# Node sources jest can resolve. Their paths feed --findRelatedTests.
node_src:
- 'nodejs/**/*.ts'
@@ -188,15 +189,15 @@ jobs:
- '.github/actions/setup-uv/**'
# Affected-crate detection is the only step below that reads the tree, and only a
- # rust/ or proto/ change reaches it. It diffs the merge base, so it needs the full
- # commit graph; it checks that out on its own rather than making every run pay for it.
+ # rust/ or proto/ change reaches it. The resolver supplies the merge base and
+ # complete change set, so this checkout needs no history.
# The cone is a superset of the tree ci-rust.yml's affected job gives the same binary.
- name: Check out the Rust tree for affected-crate detection
if: github.event_name != 'push' && github.event_name != 'schedule' && steps.filter.outputs.rust == 'true'
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
clean: false
- fetch-depth: 0
+ fetch-depth: 1
filter: blob:none
sparse-checkout: |
.github/
@@ -204,6 +205,21 @@ jobs:
rust/
sparse-checkout-cone-mode: false
+ - name: Resolve the Rust changed files
+ id: rust-changed-files
+ if: github.event_name != 'push' && github.event_name != 'schedule' && steps.filter.outputs.rust == 'true'
+ continue-on-error: true
+ env:
+ GH_TOKEN: ${{ steps.app-token.outputs.token || github.token }}
+ REPOSITORY: ${{ github.repository }}
+ MERGE_TARGET: ${{ github.event.pull_request.base.ref }}
+ run: |
+ if [ -f .github/scripts/resolve-changed-files.sh ]; then
+ bash .github/scripts/resolve-changed-files.sh
+ else
+ echo 'resolved=false' >> "$GITHUB_OUTPUT"
+ fi
+
- name: Install rust for affected-crate detection
# Not needed on schedule either: the decision step below already returns
# nodejs=true there without consulting the affected-crate set.
@@ -222,6 +238,9 @@ jobs:
event-name: ${{ github.event_name }}
pr-base-sha: ${{ github.event.pull_request.base.sha }}
push-before-sha: ${{ github.event.before }}
+ base-ref: ${{ steps.rust-changed-files.outputs.merge_base }}
+ changed-files: ${{ runner.temp }}/changed-files.txt
+ rebuild-all: ${{ (steps.rust-changed-files.outcome != 'success' || steps.rust-changed-files.outputs.resolved != 'true') && 'true' || 'false' }}
- name: Decide whether Node.js checks should run
id: nodejs-changes
diff --git a/tools/workflow-plan/tests/workflows.test.ts b/tools/workflow-plan/tests/workflows.test.ts
index 213618b65c26..c90794307833 100644
--- a/tools/workflow-plan/tests/workflows.test.ts
+++ b/tools/workflow-plan/tests/workflows.test.ts
@@ -1087,6 +1087,40 @@ describe('CI workflow run plans', () => {
expect(plan.jobs.affected?.steps.find((step) => step.name === 'Resolve the changed files')?.runs).toBe(runs)
})
+ it.each([
+ ['PR', pullRequest(), true, true],
+ ['fork', pullRequest({ fork: true }), true, true],
+ ['merge queue', mergeQueue(), true, true],
+ ['unrelated PR', pullRequest(), false, false],
+ ['push', push(), true, false],
+ ['schedule', schedule(), true, false],
+ ] as const)('Node Rust resolver on %s', (name, github, rustChanged, runs) => {
+ const plan = planWorkflow(workflow('ci-nodejs.yml'), {
+ name,
+ github,
+ steps: { changes: { filter: pathsFilter({ rust: rustChanged }) } },
+ })
+ expect(plan.errors).toEqual([])
+ expect(plan.jobs.changes?.steps.find((step) => step.id === 'rust-changed-files')?.runs).toBe(runs)
+ })
+
+ it.each([
+ ['success', 'true', 'false'],
+ ['success', 'false', 'true'],
+ ['success', '', 'true'],
+ ['failure', 'true', 'true'],
+ ])('Node Rust fallback for resolver %s, resolved=%j', (outcome, resolved, rebuildAll) => {
+ const step = workflow('ci-nodejs.yml').jobs.changes?.steps?.find((step) => step.id === 'rust-affected')
+ const functions = planFunctions({ dependenciesSucceeded: true, dependenciesFailed: false, cancelled: false })
+ expect(
+ evaluateValue(
+ step?.with?.['rebuild-all'],
+ { steps: { 'rust-changed-files': { outcome, outputs: { resolved } } } },
+ functions
+ )
+ ).toBe(rebuildAll)
+ })
+
it.each(['success', 'failure'] as const)(
'sccache counters survive a %s build without changing its verdict',
(outcome) => {