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.

fix(ci): run Pulumi Preview on PR only for infra changes (#7176)

teo6efb9d2ade28
diff --git a/.github/workflows/pulumi_preview_pr.yml b/.github/workflows/pulumi_preview_pr.yml
index eb164bccbe..2e214c2f93 100644
--- a/.github/workflows/pulumi_preview_pr.yml
+++ b/.github/workflows/pulumi_preview_pr.yml
@@ -6,32 +6,15 @@ on:
branches:
- main
paths:
- - Cargo.toml
- - Cargo.lock
- - Cross.toml
- - clippy.toml
- - rust-toolchain.toml
- - .cargo/**
- - .config/**
- - .sqlx/**
- - crates/**
- - services/**
- - tooling/just/**
- - static_assets/**
- - docker/**
- - flake.nix
- - flake.lock
- - nix/**
- - nix-support/**
- infra/**
+ - .github/kafka-cluster-topics.json
+ - .github/services-config.json
- .github/workflows/pulumi_preview_pr.yml
- .github/workflows/reusable_preview_service.yml
- .github/actions/preview-cloud-storage-pulumi/**
- .github/actions/setup-nix/**
- .github/actions/teardown-nix/**
- .github/scripts/build-cloud-storage-lambdas-nix.sh
- - .github/services-config.json
- - .github/workspace-dep-closures.json
permissions:
contents: read
pull-requests: write
@@ -51,32 +34,15 @@ jobs:
uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62
with:
files: |-
- Cargo.toml
- Cargo.lock
- Cross.toml
- clippy.toml
- rust-toolchain.toml
- .cargo/**
- .config/**
- .sqlx/**
- crates/**
- services/**
- tooling/just/**
- static_assets/**
- docker/**
- flake.nix
- flake.lock
- nix/**
- nix-support/**
infra/**
+ .github/kafka-cluster-topics.json
+ .github/services-config.json
.github/workflows/pulumi_preview_pr.yml
.github/workflows/reusable_preview_service.yml
.github/actions/preview-cloud-storage-pulumi/**
.github/actions/setup-nix/**
.github/actions/teardown-nix/**
.github/scripts/build-cloud-storage-lambdas-nix.sh
- .github/services-config.json
- .github/workspace-dep-closures.json
json: 'true'
escape_json: 'false'
write_output_files: 'true'
@@ -92,98 +58,48 @@ jobs:
changed_files=.github/outputs/changed_files.txt
jq -r '.[]' .github/outputs/all_modified_files.json > "$changed_files"
- # Read service config
config=$(cat .github/services-config.json)
- # Check each service for changes
- for service in $(echo "$config" | jq -r '.services | keys[]'); do
+ # Shared infra code, root infra manifests, and the preview's own
+ # machinery can change every stack.
+ preview_all=false
+ while IFS= read -r file; do
+ if [[ "$file" == infra/packages/* || \
+ ( "$file" == infra/* && "${file#infra/}" != */* ) || \
+ "$file" == ".github/services-config.json" || \
+ "$file" == ".github/workflows/pulumi_preview_pr.yml" || \
+ "$file" == ".github/workflows/reusable_preview_service.yml" || \
+ "$file" == .github/actions/preview-cloud-storage-pulumi/* || \
+ "$file" == .github/actions/setup-nix/* || \
+ "$file" == .github/actions/teardown-nix/* || \
+ "$file" == ".github/scripts/build-cloud-storage-lambdas-nix.sh" ]]; then
+ preview_all=true
+ break
+ fi
+ done < "$changed_files"
+
+ for service in $(jq -r '.services | keys[]' <<< "$config"); do
bootstrap_pending=$(jq -r --arg s "$service" '.services[$s].bootstrap_pending // empty' <<< "$config")
if jq -e --arg s "$service" '.services[$s].bootstrap_pending != null' <<< "$config" > /dev/null; then
echo "::notice::Deferring $service live infrastructure checks: $bootstrap_pending"
continue
fi
- service_changed=false
-
- # Workspace/build-system changes can affect every deployable.
- # `.sqlx/` lives at the repo root, so a snapshot-only edit would
- # otherwise match no service path or dependency-closure entry.
- # A crate source edit is not in this list: those preview only the
- # services whose deploy binaries depend on the crate.
- while IFS= read -r file; do
- if [[ "$file" == "Cargo.toml" || "$file" == "Cargo.lock" || \
- "$file" == "Cross.toml" || \
- "$file" == "rust-toolchain.toml" || "$file" == .cargo/* || \
- "$file" == .config/* || "$file" == .sqlx/* || \
- "$file" == tooling/just/* || "$file" == static_assets/* || \
- "$file" == docker/* || "$file" == "flake.nix" || \
- "$file" == "flake.lock" || "$file" == nix/* || \
- "$file" == nix-support/* || "$file" == infra/packages/* ]]; then
- service_changed=true
- break
- fi
- # Root infra manifests/configuration are shared by every stack.
- if [[ "$file" == infra/* && "${file#infra/}" != */* ]]; then
- service_changed=true
- break
- fi
- if [[ "$file" == ".github/services-config.json" || \
- "$file" == ".github/workflows/pulumi_preview_pr.yml" || \
- "$file" == ".github/workflows/reusable_preview_service.yml" || \
- "$file" == .github/actions/preview-cloud-storage-pulumi/* || \
- "$file" == .github/actions/setup-nix/* || \
- "$file" == .github/actions/teardown-nix/* || \
- "$file" == ".github/scripts/build-cloud-storage-lambdas-nix.sh" || \
- "$file" == ".github/workspace-dep-closures.json" ]]; then
- service_changed=true
- break
- fi
- done < "$changed_files"
-
- # Get all source and stack globs for this service.
- service_paths=$(echo "$config" | jq -r --arg s "$service" \
- '(.services[$s].source_paths // [])[], (.services[$s].stack_path // empty)')
+ service_changed=$preview_all
- # Check if any changed files match service paths. The action writes
- # the list to disk so very large PRs cannot exceed the runner's
- # environment/argument-size limit.
- if [[ "$service_changed" != "true" ]]; then
+ stack_path=$(jq -r --arg s "$service" '.services[$s].stack_path // empty' <<< "$config")
+ if [[ "$service_changed" != "true" && -n "$stack_path" ]]; then
while IFS= read -r file; do
- while IFS= read -r path; do
- if [[ -n "$path" && "$file" == $path ]]; then
- service_changed=true
- break 2
- fi
- done <<< "$service_paths"
+ if [[ "$file" == $stack_path ]]; then
+ service_changed=true
+ break
+ fi
done < "$changed_files"
fi
- # Match crate/service source against each deployable's workspace
- # dependency closure so `crates/foo` previews foo's consumers, not
- # every stack. Binary names that are not package names are mapped
- # onto the crate that contains them.
- if [[ "$service_changed" != "true" ]]; then
- crates=$(echo "$config" | jq -r --arg s "$service" '
- [(.services[$s].deploy_binaries // [])[], (.services[$s].deploy_lambdas // [])[]]
- | map(
- if . == "connection_gateway_service" then "connection_gateway"
- elif . == "service" then "scheduled_action"
- elif . == "pubsub_workers" then "email_service"
- else . end
- )
- | unique | .[]
- ')
- while IFS= read -r crate; do
- [[ -z "$crate" ]] && continue
- while IFS= read -r dir; do
- [[ -z "$dir" ]] && continue
- while IFS= read -r file; do
- if [[ "$file" == "$dir" || "$file" == "$dir"/* ]]; then
- service_changed=true
- break 3
- fi
- done < "$changed_files"
- done < <(jq -r --arg c "$crate" '.closures[$c] // empty | .[]' .github/workspace-dep-closures.json)
- done <<< "$crates"
+ # The kafka-cluster stack reads its topics from this generated file.
+ if [[ "$service" == "kafka-cluster" ]] && \
+ grep -qxF .github/kafka-cluster-topics.json "$changed_files"; then
+ service_changed=true
fi
if [[ "$service_changed" == "true" ]]; then
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr.rs
index 61eb0e82f1..bcc918b97c 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr.rs
@@ -9,55 +9,39 @@ use gh_workflow::{
Workflow,
};
+use xtask_paths::RepoGlob;
+
use crate::workflows::runners;
#[cfg(test)]
mod test;
+/// Inputs that can change a stack's definition. Crate and service code is left
+/// out on purpose: its preview is always the same "Lambda code / image changed"
+/// diff, and producing it costs a from-scratch Lambda build per stack.
+const TRIGGER_PATHS: &[RepoGlob<'static>] = &[
+ RepoGlob::new("infra/**"),
+ // `infra/stacks/kafka-cluster` reads its topics from this generated file.
+ RepoGlob::new(".github/kafka-cluster-topics.json"),
+ RepoGlob::new(".github/services-config.json"),
+ RepoGlob::new(".github/workflows/pulumi_preview_pr.yml"),
+ RepoGlob::new(".github/workflows/reusable_preview_service.yml"),
+ RepoGlob::new(".github/actions/preview-cloud-storage-pulumi/**"),
+ RepoGlob::new(".github/actions/setup-nix/**"),
+ RepoGlob::new(".github/actions/teardown-nix/**"),
+ RepoGlob::new(".github/scripts/build-cloud-storage-lambdas-nix.sh"),
+];
+
/// Build the workflow. The reusable-workflow caller job's `with:` and
/// `secrets: inherit` are filled in by [`patch`].
pub fn pulumi_preview_pr() -> Workflow {
Workflow::new("Pulumi Preview on PR")
- .on(Event::default().pull_request(
- PullRequest::default()
- .add_branch("main")
- .add_path(xtask_paths::repo_glob!("Cargo.toml"))
- .add_path(xtask_paths::repo_glob!("Cargo.lock"))
- .add_path(xtask_paths::repo_glob!("Cross.toml"))
- .add_path(xtask_paths::repo_glob!("clippy.toml"))
- .add_path(xtask_paths::repo_glob!("rust-toolchain.toml"))
- .add_path(xtask_paths::repo_glob!(".cargo/**"))
- .add_path(xtask_paths::repo_glob!(".config/**"))
- .add_path(xtask_paths::repo_glob!(".sqlx/**"))
- .add_path(xtask_paths::repo_glob!("crates/**"))
- .add_path(xtask_paths::repo_glob!("services/**"))
- .add_path(xtask_paths::repo_glob!("tooling/just/**"))
- .add_path(xtask_paths::repo_glob!("static_assets/**"))
- .add_path(xtask_paths::repo_glob!("docker/**"))
- .add_path(xtask_paths::repo_glob!("flake.nix"))
- .add_path(xtask_paths::repo_glob!("flake.lock"))
- .add_path(xtask_paths::repo_glob!("nix/**"))
- .add_path(xtask_paths::repo_glob!("nix-support/**"))
- .add_path(xtask_paths::repo_glob!("infra/**"))
- .add_path(xtask_paths::repo_glob!(
- ".github/workflows/pulumi_preview_pr.yml"
- ))
- .add_path(xtask_paths::repo_glob!(
- ".github/workflows/reusable_preview_service.yml"
- ))
- .add_path(xtask_paths::repo_glob!(
- ".github/actions/preview-cloud-storage-pulumi/**"
- ))
- .add_path(xtask_paths::repo_glob!(".github/actions/setup-nix/**"))
- .add_path(xtask_paths::repo_glob!(".github/actions/teardown-nix/**"))
- .add_path(xtask_paths::repo_glob!(
- ".github/scripts/build-cloud-storage-lambdas-nix.sh"
- ))
- .add_path(xtask_paths::repo_glob!(".github/services-config.json"))
- .add_path(xtask_paths::repo_glob!(
- ".github/workspace-dep-closures.json"
- )),
- ))
+ .on(
+ Event::default().pull_request(TRIGGER_PATHS.iter().copied().fold(
+ PullRequest::default().add_branch("main"),
+ PullRequest::add_path,
+ )),
+ )
.concurrency(
Concurrency::new(Expression::new(
"${{ github.workflow }}-${{ github.event.pull_request.number }}",
@@ -151,35 +135,11 @@ fn changed_files() -> Step<Use> {
.id("changed-files")
.add_with((
"files",
- indoc::indoc! {r#"
- Cargo.toml
- Cargo.lock
- Cross.toml
- clippy.toml
- rust-toolchain.toml
- .cargo/**
- .config/**
- .sqlx/**
- crates/**
- services/**
- tooling/just/**
- static_assets/**
- docker/**
- flake.nix
- flake.lock
- nix/**
- nix-support/**
- infra/**
- .github/workflows/pulumi_preview_pr.yml
- .github/workflows/reusable_preview_service.yml
- .github/actions/preview-cloud-storage-pulumi/**
- .github/actions/setup-nix/**
- .github/actions/teardown-nix/**
- .github/scripts/build-cloud-storage-lambdas-nix.sh
- .github/services-config.json
- .github/workspace-dep-closures.json
- "#}
- .trim_end(),
+ TRIGGER_PATHS
+ .iter()
+ .map(|path| path.as_str())
+ .collect::<Vec<_>>()
+ .join("\n"),
))
.add_with(("json", true))
.add_with(("escape_json", false))
@@ -198,98 +158,48 @@ fn detect_affected_services() -> Step<Run> {
changed_files=.github/outputs/changed_files.txt
jq -r '.[]' .github/outputs/all_modified_files.json > "$changed_files"
- # Read service config
config=$(cat .github/services-config.json)
- # Check each service for changes
- for service in $(echo "$config" | jq -r '.services | keys[]'); do
+ # Shared infra code, root infra manifests, and the preview's own
+ # machinery can change every stack.
+ preview_all=false
+ while IFS= read -r file; do
+ if [[ "$file" == infra/packages/* || \
+ ( "$file" == infra/* && "${file#infra/}" != */* ) || \
+ "$file" == ".github/services-config.json" || \
+ "$file" == ".github/workflows/pulumi_preview_pr.yml" || \
+ "$file" == ".github/workflows/reusable_preview_service.yml" || \
+ "$file" == .github/actions/preview-cloud-storage-pulumi/* || \
+ "$file" == .github/actions/setup-nix/* || \
+ "$file" == .github/actions/teardown-nix/* || \
+ "$file" == ".github/scripts/build-cloud-storage-lambdas-nix.sh" ]]; then
+ preview_all=true
+ break
+ fi
+ done < "$changed_files"
+
+ for service in $(jq -r '.services | keys[]' <<< "$config"); do
bootstrap_pending=$(jq -r --arg s "$service" '.services[$s].bootstrap_pending // empty' <<< "$config")
if jq -e --arg s "$service" '.services[$s].bootstrap_pending != null' <<< "$config" > /dev/null; then
echo "::notice::Deferring $service live infrastructure checks: $bootstrap_pending"
continue
fi
- service_changed=false
-
- # Workspace/build-system changes can affect every deployable.
- # `.sqlx/` lives at the repo root, so a snapshot-only edit would
- # otherwise match no service path or dependency-closure entry.
- # A crate source edit is not in this list: those preview only the
- # services whose deploy binaries depend on the crate.
- while IFS= read -r file; do
- if [[ "$file" == "Cargo.toml" || "$file" == "Cargo.lock" || \
- "$file" == "Cross.toml" || \
- "$file" == "rust-toolchain.toml" || "$file" == .cargo/* || \
- "$file" == .config/* || "$file" == .sqlx/* || \
- "$file" == tooling/just/* || "$file" == static_assets/* || \
- "$file" == docker/* || "$file" == "flake.nix" || \
- "$file" == "flake.lock" || "$file" == nix/* || \
- "$file" == nix-support/* || "$file" == infra/packages/* ]]; then
- service_changed=true
- break
- fi
- # Root infra manifests/configuration are shared by every stack.
- if [[ "$file" == infra/* && "${file#infra/}" != */* ]]; then
- service_changed=true
- break
- fi
- if [[ "$file" == ".github/services-config.json" || \
- "$file" == ".github/workflows/pulumi_preview_pr.yml" || \
- "$file" == ".github/workflows/reusable_preview_service.yml" || \
- "$file" == .github/actions/preview-cloud-storage-pulumi/* || \
- "$file" == .github/actions/setup-nix/* || \
- "$file" == .github/actions/teardown-nix/* || \
- "$file" == ".github/scripts/build-cloud-storage-lambdas-nix.sh" || \
- "$file" == ".github/workspace-dep-closures.json" ]]; then
- service_changed=true
- break
- fi
- done < "$changed_files"
-
- # Get all source and stack globs for this service.
- service_paths=$(echo "$config" | jq -r --arg s "$service" \
- '(.services[$s].source_paths // [])[], (.services[$s].stack_path // empty)')
+ service_changed=$preview_all
- # Check if any changed files match service paths. The action writes
- # the list to disk so very large PRs cannot exceed the runner's
- # environment/argument-size limit.
- if [[ "$service_changed" != "true" ]]; then
+ stack_path=$(jq -r --arg s "$service" '.services[$s].stack_path // empty' <<< "$config")
+ if [[ "$service_changed" != "true" && -n "$stack_path" ]]; then
while IFS= read -r file; do
- while IFS= read -r path; do
- if [[ -n "$path" && "$file" == $path ]]; then
- service_changed=true
- break 2
- fi
- done <<< "$service_paths"
+ if [[ "$file" == $stack_path ]]; then
+ service_changed=true
+ break
+ fi
done < "$changed_files"
fi
- # Match crate/service source against each deployable's workspace
- # dependency closure so `crates/foo` previews foo's consumers, not
- # every stack. Binary names that are not package names are mapped
- # onto the crate that contains them.
- if [[ "$service_changed" != "true" ]]; then
- crates=$(echo "$config" | jq -r --arg s "$service" '
- [(.services[$s].deploy_binaries // [])[], (.services[$s].deploy_lambdas // [])[]]
- | map(
- if . == "connection_gateway_service" then "connection_gateway"
- elif . == "service" then "scheduled_action"
- elif . == "pubsub_workers" then "email_service"
- else . end
- )
- | unique | .[]
- ')
- while IFS= read -r crate; do
- [[ -z "$crate" ]] && continue
- while IFS= read -r dir; do
- [[ -z "$dir" ]] && continue
- while IFS= read -r file; do
- if [[ "$file" == "$dir" || "$file" == "$dir"/* ]]; then
- service_changed=true
- break 3
- fi
- done < "$changed_files"
- done < <(jq -r --arg c "$crate" '.closures[$c] // empty | .[]' .github/workspace-dep-closures.json)
- done <<< "$crates"
+ # The kafka-cluster stack reads its topics from this generated file.
+ if [[ "$service" == "kafka-cluster" ]] && \
+ grep -qxF .github/kafka-cluster-topics.json "$changed_files"; then
+ service_changed=true
fi
if [[ "$service_changed" == "true" ]]; then
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr/test.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr/test.rs
index 307406cccb..0754ffed67 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr/test.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/pulumi_preview_pr/test.rs
@@ -2,84 +2,120 @@ use super::*;
#[test]
fn bootstrap_defers_preview_until_activation_without_hiding_paused_services() {
+ let mut config = serde_json::json!({"services": {
+ "ready": {},
+ "pending": {"bootstrap_pending": "Requires first-time setup"},
+ "paused": {"deploy_enabled": false}
+ }});
+ let changed = [".github/services-config.json"];
+ assert_eq!(
+ detect(&changed, &config),
+ serde_json::json!(["paused", "ready"])
+ );
+ config["services"]["pending"]
+ .as_object_mut()
+ .unwrap()
+ .remove("bootstrap_pending");
+ assert_eq!(
+ detect(&changed, &config),
+ serde_json::json!(["paused", "pending", "ready"])
+ );
+}
+
+/// Run the detect script against `changed` and return the services it picks.
+fn detect(changed: &[&str], config: &serde_json::Value) -> serde_json::Value {
let dir = tempfile::tempdir().unwrap();
let github = dir.path().join(".github");
std::fs::create_dir_all(github.join("outputs")).unwrap();
std::fs::write(
github.join("outputs/all_modified_files.json"),
- r#"[".github/services-config.json"]"#,
+ serde_json::to_string(changed).unwrap(),
)
.unwrap();
- let mut config = serde_json::json!({"services": {
- "ready": {},
- "pending": {"bootstrap_pending": "Requires first-time setup"},
- "paused": {"deploy_enabled": false}
- }});
- for expected in [
- serde_json::json!(["paused", "ready"]),
- serde_json::json!(["paused", "pending", "ready"]),
- ] {
- std::fs::write(github.join("services-config.json"), config.to_string()).unwrap();
- let output_path = dir.path().join("output");
- std::fs::write(&output_path, "").unwrap();
- let output = std::process::Command::new("bash")
- .args([
- "-euo",
- "pipefail",
- "-c",
- &detect_affected_services().value.run.unwrap(),
- ])
- .current_dir(dir.path())
- .env("GITHUB_OUTPUT", &output_path)
- .output()
- .unwrap();
- assert!(
- output.status.success(),
- "{}",
- String::from_utf8_lossy(&output.stderr)
- );
- let result = std::fs::read_to_string(output_path).unwrap();
- assert!(
- result
- .lines()
- .any(|line| line == format!("services={expected}")),
- "{result}"
- );
- config["services"]["pending"]
- .as_object_mut()
- .unwrap()
- .remove("bootstrap_pending");
- }
+ std::fs::write(github.join("services-config.json"), config.to_string()).unwrap();
+ let output_path = dir.path().join("output");
+ std::fs::write(&output_path, "").unwrap();
+ let output = std::process::Command::new("bash")
+ .args([
+ "-euo",
+ "pipefail",
+ "-c",
+ &detect_affected_services().value.run.unwrap(),
+ ])
+ .current_dir(dir.path())
+ .env("GITHUB_OUTPUT", &output_path)
+ .output()
+ .unwrap();
+ assert!(
+ output.status.success(),
+ "{}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ let result = std::fs::read_to_string(output_path).unwrap();
+ let services = result
+ .lines()
+ .find_map(|line| line.strip_prefix("services="))
+ .unwrap_or_else(|| panic!("no services output: {result}"));
+ serde_json::from_str(services).unwrap()
}
#[test]
-fn sqlx_changes_preview_every_service() {
- let detect = detect_affected_services();
- let run = detect
- .value
- .run
- .expect("detect step should be a run script");
- assert!(
- run.contains(r#"$file" == .sqlx/*"#),
- "a root-only .sqlx change must fan out to every stack, not services=[]: {run}"
- );
+fn previews_only_stacks_whose_infra_changed() {
+ let config = serde_json::json!({"services": {
+ "email-service": {
+ "source_paths": ["services/email_service/**", "crates/email/**"],
+ "stack_path": "infra/stacks/email-service/**",
+ "deploy_binaries": ["email_service"]
+ },
+ "kafka-cluster": {
+ "source_paths": ["crates/macro_event_topics/**"],
+ "stack_path": "infra/stacks/kafka-cluster/**"
+ }
+ }});
+ let all = serde_json::json!(["email-service", "kafka-cluster"]);
+ let none = serde_json::json!([]);
+ let cases: &[(&[&str], serde_json::Value)] = &[
+ // Code, lockfile, and query-cache changes never reach a stack definition.
+ (&["Cargo.lock"], none.clone()),
+ (&["Cargo.toml", ".sqlx/query-abc.json"], none.clone()),
+ (&["services/email_service/src/main.rs"], none.clone()),
+ (&["crates/email/src/lib.rs", "flake.lock"], none.clone()),
+ (&["crates/macro_event_topics/src/lib.rs"], none.clone()),
+ (&[".github/workspace-dep-closures.json"], none.clone()),
+ (
+ &["infra/stacks/email-service/index.ts"],
+ serde_json::json!(["email-service"]),
+ ),
+ (
+ &["infra/stacks/kafka-cluster/topics.ts", "Cargo.lock"],
+ serde_json::json!(["kafka-cluster"]),
+ ),
+ (
+ &[".github/kafka-cluster-topics.json"],
+ serde_json::json!(["kafka-cluster"]),
+ ),
+ // Unmapped stacks warn instead of previewing.
+ (&["infra/stacks/github-runners/runner.ts"], none.clone()),
+ (&["infra/local/compose.yml"], none.clone()),
+ // Shared infra code and root manifests affect every stack.
+ (&["infra/packages/resources/src/index.ts"], all.clone()),
+ (&["infra/bun.lock"], all.clone()),
+ (
+ &[".github/workflows/reusable_preview_service.yml"],
+ all.clone(),
+ ),
+ (
+ &[".github/scripts/build-cloud-storage-lambdas-nix.sh"],
+ all.clone(),
+ ),
+ ];
+ for (changed, expected) in cases {
+ assert_eq!(&detect(changed, &config), expected, "changed: {changed:?}");
+ }
}
#[test]
-fn detect_reads_the_json_changed_file_list() {
- let run = detect_affected_services()
- .value
- .run
- .expect("detect step should be a run script");
- assert!(
- !run.contains("all_changed_files.txt"),
- "the space-joined .txt output has no newline, so `while read` sees no files: {run}"
- );
- assert!(
- run.contains(r#"jq -r '.[]' .github/outputs/all_modified_files.json > "$changed_files""#)
- && run.matches(r#"done < "$changed_files""#).count() == 3,
- "every matching loop must read the JSON list, deletions included: {run}"
- );
+fn changed_files_action_emits_json_list() {
let with = serde_json::to_string(&changed_files().value.with).expect("with serializes");
assert!(
with.contains(r#""json":"true""#) && with.contains(r#""escape_json":"false""#),