Skip to content

Commit e96df11

Browse files
committed
Base pre-ci:affected on origin/main and warn when local main has drifted
1 parent 30c870a commit e96df11

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

bin/ci-gates.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111
// affected — faster command for `pnpm pre-ci:affected` (defaults to `command`)
1212
// affectedWhen: 'codegen' — in affected mode, run only when the diff plausibly
1313
// changes generated output; otherwise skip with a reminder.
14+
//
15+
// Affected commands base on `origin/main` (not the local `main` that nx's
16+
// defaultBase would use), matching the codegen/vitest change detection so all of
17+
// pre-ci:affected reasons about the same diff.
1418

1519
export const CI_GATES = [
1620
// --- gates a contributor can reproduce locally before pushing ---
1721
// Ordered as pre-ci should run them: build precedes the oclif codegen check,
1822
// and the graphql check precedes the oclif check (their whole-repo `git status`
1923
// asserts otherwise cross-contaminate in a single working tree).
20-
{job: 'type-check', kind: 'pre-ci', command: 'pnpm type-check', affected: 'pnpm type-check:affected'},
21-
{job: 'lint', kind: 'pre-ci', command: 'pnpm lint', affected: 'pnpm lint:affected'},
22-
{job: 'bundle', kind: 'pre-ci', command: 'pnpm build', affected: 'pnpm build:affected'},
24+
{job: 'type-check', kind: 'pre-ci', command: 'pnpm type-check', affected: 'pnpm exec nx affected --target=type-check --base=origin/main'},
25+
{job: 'lint', kind: 'pre-ci', command: 'pnpm lint', affected: 'pnpm exec nx affected --target=lint --base=origin/main'},
26+
{job: 'bundle', kind: 'pre-ci', command: 'pnpm build', affected: 'pnpm exec nx affected --target=build --base=origin/main'},
2327
{job: 'knip', kind: 'pre-ci', command: 'pnpm knip'},
2428
{job: 'graphql-schema', kind: 'pre-ci', command: 'pnpm codegen:check:graphql', affectedWhen: 'codegen'},
2529
{job: 'oclif-checks', kind: 'pre-ci', command: 'pnpm codegen:check:oclif', affectedWhen: 'codegen'},

bin/pre-ci.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,27 @@ function touchesGeneratedOutput(files) {
4949
)
5050
}
5151

52+
// Affected mode bases on origin/main. Warn if the local main has drifted from it,
53+
// since that usually means origin/main is stale and the affected set may be off.
54+
function localMainDriftWarning() {
55+
try {
56+
const local = execSync('git rev-parse main', {encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore']}).trim()
57+
const remote = execSync('git rev-parse origin/main', {encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore']}).trim()
58+
if (local !== remote) {
59+
return 'Local `main` differs from `origin/main` (affected mode bases on `origin/main`). Run `git fetch origin main` if the affected set looks off.'
60+
}
61+
} catch {
62+
// No local `main` ref (e.g. a fresh worktree) — nothing to compare.
63+
}
64+
return null
65+
}
66+
5267
const diff = affected ? changedFiles() : null
5368
const codegenRelevant = affected ? touchesGeneratedOutput(diff) : true
5469

70+
const driftWarning = affected ? localMainDriftWarning() : null
71+
if (driftWarning) process.stdout.write(`\n⚠ ${driftWarning}\n`)
72+
5573
const steps = [{label: 'CI gate manifest in sync', command: 'pnpm check-ci-gates'}]
5674
const skipped = []
5775
for (const gate of PRE_CI_GATES) {

0 commit comments

Comments
 (0)