ci: reduce change planner startup time

This commit is contained in:
luo jiyin authored and GitHub committed 2026-09-29 12:35:50 +08:00
1 parent 475f618d4b
commit ef1fd7a195
4 files changed
+39 -8

No files matched your search

+7 -3
View File
@@ -26,6 +26,12 @@ export function knownJavaDrivers(root, nativeDrivers) {
} }
} }
export function cargoMetadata(root, execute = execFileSync) {
return JSON.parse(execute("cargo", ["+stable", "metadata", "--locked", "--offline", "--no-deps", "--format-version", "1"], {
cwd: root, encoding: "utf8", maxBuffer: 16 * 1024 * 1024,
}));
}
export function planCi({ files, metadata, root, eventName = "pull_request", rustChanged = false, agentsChanged = false, javaDrivers }) { export function planCi({ files, metadata, root, eventName = "pull_request", rustChanged = false, agentsChanged = false, javaDrivers }) {
const unknownDiff = files === null; const unknownDiff = files === null;
files ??= []; files ??= [];
@@ -97,9 +103,7 @@ export function planCi({ files, metadata, root, eventName = "pull_request", rust
if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) { if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
const root = process.cwd(); const root = process.cwd();
const metadata = JSON.parse(execFileSync("cargo", ["metadata", "--locked", "--offline", "--no-deps", "--format-version", "1"], { const metadata = cargoMetadata(root);
cwd: root, encoding: "utf8", maxBuffer: 16 * 1024 * 1024,
}));
const plan = planCi({ const plan = planCi({
files: changedPaths(process.env.BASE_SHA, root), metadata, root, eventName: process.env.GITHUB_EVENT_NAME, files: changedPaths(process.env.BASE_SHA, root), metadata, root, eventName: process.env.GITHUB_EVENT_NAME,
rustChanged: process.env.RUST_CHANGED === "true", agentsChanged: process.env.AGENTS_CHANGED === "true", rustChanged: process.env.RUST_CHANGED === "true", agentsChanged: process.env.AGENTS_CHANGED === "true",
+13 -1
View File
@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";
import path from "node:path"; import path from "node:path";
import { execFileSync } from "node:child_process"; import { execFileSync } from "node:child_process";
import { goAgents, integrationCases, rustGroups } from "./ci-config.mjs"; import { goAgents, integrationCases, rustGroups } from "./ci-config.mjs";
import { changedPaths, planCi } from "./ci-plan.mjs"; import { cargoMetadata, changedPaths, planCi } from "./ci-plan.mjs";
import { rustCommand } from "./ci-rust.mjs"; import { rustCommand } from "./ci-rust.mjs";
import { gateFailures } from "./ci-gate.mjs"; import { gateFailures } from "./ci-gate.mjs";
import { assertCoverage, parseCoverage } from "./ci-rust-coverage.mjs"; import { assertCoverage, parseCoverage } from "./ci-rust-coverage.mjs";
@@ -40,6 +40,18 @@ const metadata = {
}; };
const plan = (files, options = {}) => planCi({ files, metadata, root, ...options }); const plan = (files, options = {}) => planCi({ files, metadata, root, ...options });
const groups = (result) => result.rust_matrix.include.map((entry) => entry.group); const groups = (result) => result.rust_matrix.include.map((entry) => entry.group);
test("the planner uses the runner stable Cargo only for metadata", () => {
let invocation;
const result = cargoMetadata("/workspace", (command, args, options) => {
invocation = { command, args, options };
return '{"packages":[],"workspace_members":[]}';
});
assert.deepEqual(result, { packages: [], workspace_members: [] });
assert.equal(invocation.command, "cargo");
assert.deepEqual(invocation.args, ["+stable", "metadata", "--locked", "--offline", "--no-deps", "--format-version", "1"]);
assert.equal(invocation.options.cwd, "/workspace");
});
// Keep the gate fixtures in sync with ci-gate.mjs routedJobs. Both Windows jobs // Keep the gate fixtures in sync with ci-gate.mjs routedJobs. Both Windows jobs
// share the windows_win7_bundle routing output. // share the windows_win7_bundle routing output.
const routedJobs = { frontend: "frontend", packages: "packages", "github-scripts": "github_scripts", const routedJobs = { frontend: "frontend", packages: "packages", "github-scripts": "github_scripts",
+5
View File
@@ -172,7 +172,12 @@ test("Windows compatibility jobs cache Rust compilation without wrapping C or C+
test("the planner uses the exact event base and preserves a single workflow cancellation scope", () => { test("the planner uses the exact event base and preserves a single workflow cancellation scope", () => {
const changes = job("changes"); const changes = job("changes");
assert.ok(changes.includes("github.event.pull_request.base.sha || github.event.before")); assert.ok(changes.includes("github.event.pull_request.base.sha || github.event.before"));
assert.ok(changes.includes('git fetch --no-tags --depth=1 origin "$BASE_SHA"'));
assert.ok(changes.includes("base: ${{ steps.change-base.outputs.sha }}"));
assert.ok(changes.includes("BASE_SHA: ${{ steps.change-base.outputs.sha }}"));
assert.ok(changes.includes("node .github/scripts/ci-plan.mjs")); assert.ok(changes.includes("node .github/scripts/ci-plan.mjs"));
assert.doesNotMatch(changes, /fetch-depth:\s*0/);
assert.doesNotMatch(changes, /dtolnay\/rust-toolchain/);
for (const flag of ["rust", "rust_full", "rust_matrix", "agents", "agent_go", "agent_rust", "agent_integration", "plan"]) { for (const flag of ["rust", "rust_full", "rust_matrix", "agents", "agent_go", "agent_rust", "agent_integration", "plan"]) {
assert.ok(changes.includes(`steps.plan.outputs.${flag}`)); assert.ok(changes.includes(`steps.plan.outputs.${flag}`));
} }
+14 -4
View File
@@ -1051,12 +1051,24 @@ jobs:
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v7
with: with:
fetch-depth: 0 fetch-depth: 1
- name: Fetch change base
id: change-base
env:
BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
run: |
if [[ -z "$BASE_SHA" || "$BASE_SHA" =~ ^0+$ ]]; then
exit 0
fi
git fetch --no-tags --depth=1 origin "$BASE_SHA"
echo "sha=$BASE_SHA" >> "$GITHUB_OUTPUT"
- name: Detect changed areas - name: Detect changed areas
uses: dorny/paths-filter@v4 uses: dorny/paths-filter@v4
id: filter id: filter
with: with:
base: ${{ steps.change-base.outputs.sha }}
filters: | filters: |
frontend: frontend:
- 'apps/desktop/**' - 'apps/desktop/**'
@@ -1174,12 +1186,10 @@ jobs:
- '.github/workflows/ci.yml' - '.github/workflows/ci.yml'
- 'apps/desktop/src/types/database.ts' - 'apps/desktop/src/types/database.ts'
- 'crates/dbx-core/assets/database-drivers.manifest.json' - 'crates/dbx-core/assets/database-drivers.manifest.json'
- name: Setup Rust
uses: dtolnay/rust-toolchain@1.97.1
- name: Plan dependency-aware CI jobs - name: Plan dependency-aware CI jobs
id: plan id: plan
env: env:
BASE_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} BASE_SHA: ${{ steps.change-base.outputs.sha }}
RUST_CHANGED: ${{ steps.filter.outputs.rust }} RUST_CHANGED: ${{ steps.filter.outputs.rust }}
AGENTS_CHANGED: ${{ steps.filter.outputs.agents }} AGENTS_CHANGED: ${{ steps.filter.outputs.agents }}
run: node .github/scripts/ci-plan.mjs run: node .github/scripts/ci-plan.mjs