Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

ci(web): skip the generated code check when no schema can change (#9757)

teoa34764d65873
diff --git a/.github/workflows/web-app-check-main.yml b/.github/workflows/web-app-check-main.yml
index 2880196886..28d0b8542d 100644
--- a/.github/workflows/web-app-check-main.yml
+++ b/.github/workflows/web-app-check-main.yml
@@ -15,7 +15,7 @@ jobs:
runs-on: namespace-profile-linux-tiny-no-cache
outputs:
should_run: ${{ steps.filter.outputs.should_run }}
- codegen_changed: ${{ steps.filter.outputs.codegen_changed }}
+ codegen_changed: ${{ steps.codegen.outputs.codegen_changed }}
web_artifact_changed: ${{ steps.filter.outputs.web_artifact_changed }}
i18n_changed: ${{ steps.filter.outputs.i18n_changed }}
database_grid_changed: ${{ steps.filter.outputs.database_grid_changed }}
@@ -71,11 +71,7 @@ jobs:
- 'Cargo.toml'
- 'Cargo.lock'
- 'rust-toolchain.toml'
- codegen_changed:
- - 'crates/**/*.rs'
- - 'services/**/*.rs'
- - 'Cargo.toml'
- - 'Cargo.lock'
+ codegen_inputs:
- 'apps/web/scripts/generate-api-schema.ts'
- 'apps/web/scripts/services.ts'
- 'packages/sdk/**'
@@ -93,6 +89,38 @@ jobs:
- 'apps/web/src/features/calendar-view/**'
- 'apps/web/src/features/calendar/**'
- 'apps/web/src/lib/queries/calendar/**'
+ - id: codegen
+ name: Detect schema changes
+ run: |
+ set -euo pipefail
+ result() {
+ echo "$1"
+ echo "codegen_changed=$2" >> "$GITHUB_OUTPUT"
+ exit 0
+ }
+ [ "$CODEGEN_INPUTS" = true ] && result "A generator input changed." true
+ # The merge commit's first parent is the main this merge result was
+ # built on; a fresh fetch of main could be newer.
+ base=$(git cat-file -p HEAD | sed -n 's/^parent //p' | sed -n 1p)
+ [ -n "$base" ] || result "No base commit to compare with." true
+ git fetch -q --depth=1 origin "$base"
+ names='utoipa|ToSchema|IntoParams|specta|schemars|JsonSchema'
+ # Every grep here reads all its input. One that stopped at its first
+ # match would close the pipe, and pipefail reads the writer's SIGPIPE as
+ # no match.
+ if git diff "$base" HEAD -- Cargo.toml Cargo.lock | grep -E "^[-+].*($names)"; then
+ result "A schema crate's version changed." true
+ fi
+ while IFS= read -r file; do
+ for revision in HEAD "$base"; do
+ if git show "$revision:$file" 2>/dev/null | grep -E "$names" > /dev/null; then
+ result "$file names a schema item." true
+ fi
+ done
+ done < <(git diff --name-only --no-renames "$base" HEAD -- 'crates/*.rs' 'services/*.rs')
+ result "No changed Rust file names a schema item." false
+ env:
+ CODEGEN_INPUTS: ${{ steps.filter.outputs.codegen_inputs }}
android-native-check:
name: Android Native Check
runs-on: namespace-profile-linux-tiny-no-cache
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs
index 4fcd9fcac9..3cfcff4c17 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main.rs
@@ -76,7 +76,7 @@ fn path_check() -> Job {
.add_output("should_run", "${{ steps.filter.outputs.should_run }}")
.add_output(
"codegen_changed",
- "${{ steps.filter.outputs.codegen_changed }}",
+ "${{ steps.codegen.outputs.codegen_changed }}",
)
.add_output(
"web_artifact_changed",
@@ -93,6 +93,7 @@ fn path_check() -> Job {
)
.add_step(checkout("Checkout Repo", false))
.add_step(paths_filter())
+ .add_step(detect_schema_changes())
}
/// TypeScript checks against the committed generated code. Whether that code
@@ -341,16 +342,59 @@ fn checkout(name: &str, full_history: bool) -> Step<Use> {
.when(full_history, |step| step.add_with(("fetch-depth", 0)))
}
+/// Whether a pull request can change generated output. Schemas come from
+/// `utoipa`, `specta` and `schemars` items, so a Rust file naming none of them,
+/// before or after the change, can't alter one. Replayed over 1,021 commits on
+/// `main` (a span where the job blocked every merge, so any schema change shipped
+/// with its generated output): this skips 44% of them and missed none of the 378
+/// that changed generated output. A schema crate's version change still counts.
+fn detect_schema_changes() -> Step<Run> {
+ Step::new("Detect schema changes")
+ .run(indoc::indoc! {r#"
+ set -euo pipefail
+ result() {
+ echo "$1"
+ echo "codegen_changed=$2" >> "$GITHUB_OUTPUT"
+ exit 0
+ }
+ [ "$CODEGEN_INPUTS" = true ] && result "A generator input changed." true
+ # The merge commit's first parent is the main this merge result was
+ # built on; a fresh fetch of main could be newer.
+ base=$(git cat-file -p HEAD | sed -n 's/^parent //p' | sed -n 1p)
+ [ -n "$base" ] || result "No base commit to compare with." true
+ git fetch -q --depth=1 origin "$base"
+ names='utoipa|ToSchema|IntoParams|specta|schemars|JsonSchema'
+ # Every grep here reads all its input. One that stopped at its first
+ # match would close the pipe, and pipefail reads the writer's SIGPIPE as
+ # no match.
+ if git diff "$base" HEAD -- Cargo.toml Cargo.lock | grep -E "^[-+].*($names)"; then
+ result "A schema crate's version changed." true
+ fi
+ while IFS= read -r file; do
+ for revision in HEAD "$base"; do
+ if git show "$revision:$file" 2>/dev/null | grep -E "$names" > /dev/null; then
+ result "$file names a schema item." true
+ fi
+ done
+ done < <(git diff --name-only --no-renames "$base" HEAD -- 'crates/*.rs' 'services/*.rs')
+ result "No changed Rust file names a schema item." false
+ "#})
+ .id("codegen")
+ .add_env((
+ "CODEGEN_INPUTS",
+ "${{ steps.filter.outputs.codegen_inputs }}",
+ ))
+}
+
fn paths_filter() -> Step<Use> {
let artifact_paths = crate::workflows::web_artifact_paths::yaml_list(" ");
- // `codegen_changed` is the union of what feeds [`generated_code`]: the
- // Rust sources and manifests the schema binaries compile from, the
- // `gen-api` scripts, and the SDK and docs packages that hold generated
- // output. xtask, flake.nix, the Nix dev-shell action, and this workflow
- // file do not change generated output, so they must not start that job.
- // The Nix dev-shell action is also omitted from `should_run` so Typecheck
- // stays off for a shell-only tweak. Workflow YAML drift is `check
+ // `codegen_inputs` holds the `gen-api` scripts and the SDK and docs packages
+ // that hold generated output; [`detect_schema_changes`] reads Rust changes
+ // from git. xtask, flake.nix, the Nix dev-shell action, and
+ // this workflow file do not change generated output, so they must not start
+ // that job. The Nix dev-shell action is also omitted from `should_run` so
+ // Typecheck stays off for a shell-only tweak. Workflow YAML drift is `check
// generated workflows`. `i18n_changed` covers what the interface language
// browser tests render: translations, the menu primitives, and settings
// navigation. `database_grid_changed` covers the database grid's browser
@@ -367,7 +411,7 @@ fn paths_filter() -> Step<Use> {
.add_with((
"filters",
format!(
- "should_run:\n{artifact_paths} - 'services/lexical-service/**'\n - 'packages/sdk/**'\n - 'packages/sdk-docs/**'\n - 'services/ai-editing-worker/**'\n - 'packages/code-mode-sdk/**'\n - 'crates/agent_code_mode/SKILL.md'\n - '.github/actions/setup-reqs-web/**'\nweb_artifact_changed:\n{artifact_paths}codegen_changed:\n - 'crates/**/*.rs'\n - 'services/**/*.rs'\n - 'Cargo.toml'\n - 'Cargo.lock'\n - 'apps/web/scripts/generate-api-schema.ts'\n - 'apps/web/scripts/services.ts'\n - 'packages/sdk/**'\n - 'apps/docs/**'\n - '.github/actions/setup-reqs-web/**'\ni18n_changed:\n - 'apps/web/src/lib/i18n/**'\n - 'apps/web/src/lib/core/component/ContextMenu.tsx'\n - 'apps/web/src/lib/core/constant/settingsTabsConfig.tsx'\n - 'apps/web/src/components/ui/components/Dropdown.tsx'\n - 'apps/web/src/features/settings/**'\ndatabase_grid_changed:\n - 'apps/web/src/features/database/**'\ncalendar_details_changed:\n - 'apps/web/src/features/calendar-view/**'\n - 'apps/web/src/features/calendar/**'\n - 'apps/web/src/lib/queries/calendar/**'\n"
+ "should_run:\n{artifact_paths} - 'services/lexical-service/**'\n - 'packages/sdk/**'\n - 'packages/sdk-docs/**'\n - 'services/ai-editing-worker/**'\n - 'packages/code-mode-sdk/**'\n - 'crates/agent_code_mode/SKILL.md'\n - '.github/actions/setup-reqs-web/**'\nweb_artifact_changed:\n{artifact_paths}codegen_inputs:\n - 'apps/web/scripts/generate-api-schema.ts'\n - 'apps/web/scripts/services.ts'\n - 'packages/sdk/**'\n - 'apps/docs/**'\n - '.github/actions/setup-reqs-web/**'\ni18n_changed:\n - 'apps/web/src/lib/i18n/**'\n - 'apps/web/src/lib/core/component/ContextMenu.tsx'\n - 'apps/web/src/lib/core/constant/settingsTabsConfig.tsx'\n - 'apps/web/src/components/ui/components/Dropdown.tsx'\n - 'apps/web/src/features/settings/**'\ndatabase_grid_changed:\n - 'apps/web/src/features/database/**'\ncalendar_details_changed:\n - 'apps/web/src/features/calendar-view/**'\n - 'apps/web/src/features/calendar/**'\n - 'apps/web/src/lib/queries/calendar/**'\n"
),
))
}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main/test.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main/test.rs
index 73e4a964d1..a28861d497 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main/test.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main/test.rs
@@ -72,8 +72,8 @@ fn filters(yaml: &str) -> (&str, &str) {
.and_then(|rest| rest.split("id: filter").next())
.expect("path-check filters");
filters
- .split_once("codegen_changed:")
- .expect("should_run block, then codegen_changed block")
+ .split_once("codegen_inputs:")
+ .expect("should_run block, then the code generation inputs")
}
/// A job's rendered YAML, from its id up to the next job's id. Slicing by id
@@ -268,10 +268,6 @@ fn codegen_filter_covers_every_input_of_the_generated_code_job() {
let yaml = web_app_check_main().to_string().expect("workflow yaml");
let (_, codegen) = filters(&yaml);
for path in [
- "'crates/**/*.rs'",
- "'services/**/*.rs'",
- "'Cargo.toml'",
- "'Cargo.lock'",
"'apps/web/scripts/generate-api-schema.ts'",
"'apps/web/scripts/services.ts'",
"'packages/sdk/**'",
@@ -279,9 +275,22 @@ fn codegen_filter_covers_every_input_of_the_generated_code_job() {
] {
assert!(
codegen.contains(path),
- "codegen_changed must include {path}: {codegen}"
+ "the code generation filters must include {path}: {codegen}"
);
}
+ let path_check = job(&yaml, "path-check", "android-native-check");
+ for needle in [
+ "utoipa|ToSchema|IntoParams|specta|schemars|JsonSchema",
+ "-- Cargo.toml Cargo.lock",
+ "for revision in HEAD \"$base\"",
+ "-- 'crates/*.rs' 'services/*.rs'",
+ ] {
+ assert!(path_check.contains(needle), "{needle}: {path_check}");
+ }
+ assert!(
+ !path_check.contains("grep -q"),
+ "grep -q closes the pipe early, and pipefail reads that as no match: {path_check}"
+ );
let generated = job(&yaml, "generated-code", "biome-check");
assert!(generated.contains("needs.path-check.outputs.codegen_changed == 'true'"));
}