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.

chore(ci): migrate pulumi PR previews to namespace + cargo x workflows (#4504)

teo29cc97e43a12
diff --git a/.github/workflows/pulumi-preview-pr.yml b/.github/workflows/pulumi-preview-pr.yml
deleted file mode 100644
index 43fe6da724..0000000000
--- a/.github/workflows/pulumi-preview-pr.yml
+++ /dev/null
@@ -1,118 +0,0 @@
-name: Pulumi Preview on PR
-on:
- pull_request:
- branches: [ 'main' ]
- paths:
- - 'rust/cloud-storage/**'
- - '.github/workflows/pulumi-preview-pr.yml'
- - '.github/workflows/reusable-preview-service.yml'
- - '.github/actions/preview-cloud-storage-pulumi/**'
- - '.github/services-config.json'
-
-# Cancel in-progress runs of the same workflow on the same PR
-concurrency:
- group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
- cancel-in-progress: true
-
-permissions:
- contents: read
- pull-requests: write
- id-token: write
-
-jobs:
- detect-changes:
- name: Detect Changed Services
- runs-on: ubuntu-latest
- outputs:
- services: ${{ steps.detect.outputs.services }}
- has-changes: ${{ steps.detect.outputs.has-changes }}
- steps:
- - uses: actions/checkout@v6
- - name: Get changed files
- id: changed-files
- uses: tj-actions/changed-files@v47
- with:
- files: |
- rust/cloud-storage/**
- .github/services-config.json
- - name: Detect affected services
- id: detect
- run: |
- services=()
-
- # Read service config
- config=$(cat .github/services-config.json)
-
- # Check each service for changes
- for service in $(echo "$config" | jq -r '.services | keys[]'); do
- service_changed=false
-
- # Get paths for this service
- source_path=$(echo "$config" | jq -r --arg s "$service" '.services[$s].source_path // ""')
- stack_path=$(echo "$config" | jq -r --arg s "$service" '.services[$s].stack_path // ""')
- additional_paths=$(echo "$config" | jq -r --arg s "$service" '.services[$s].additional_paths[]? // ""')
-
- # Check if any changed files match service paths
- for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
- if [[ -n "$source_path" && "$file" == $source_path ]]; then
- service_changed=true
- elif [[ -n "$stack_path" && "$file" == $stack_path ]]; then
- service_changed=true
- elif [[ -n "$additional_paths" ]]; then
- for path in $additional_paths; do
- if [[ "$file" == $path ]]; then
- service_changed=true
- fi
- done
- fi
- done
-
- if [[ "$service_changed" == "true" ]]; then
- services+=("$service")
- fi
- done
-
- if [ ${#services[@]} -eq 0 ]; then
- echo "has-changes=false" >> $GITHUB_OUTPUT
- echo "services=[]" >> $GITHUB_OUTPUT
- echo "No services affected by changes"
- else
- echo "has-changes=true" >> $GITHUB_OUTPUT
- services_json=$(printf '%s\n' "${services[@]}" | jq -R . | jq -s -c .)
- echo "services=${services_json}" >> $GITHUB_OUTPUT
- echo "Services to preview: ${services[@]}"
- fi
-
- preview-services:
- name: Preview ${{ matrix.service }}
- needs: detect-changes
- if: ${{ needs.detect-changes.outputs.has-changes == 'true' }}
- strategy:
- fail-fast: false
- matrix:
- service: ${{ fromJson(needs.detect-changes.outputs.services) }}
- uses: ./.github/workflows/reusable-preview-service.yml
- with:
- environment: dev
- service-name: ${{ matrix.service }}
- github-token: ${{ github.token }}
- secrets: inherit
-
- preview-status:
- name: Preview Status
- runs-on: ubuntu-latest
- needs: [detect-changes, preview-services]
- if: always()
- steps:
- - name: Summary
- run: |
- if [[ "${{ needs.detect-changes.outputs.has-changes }}" == "false" ]]; then
- echo "ℹ️ No services were affected by the changes in this PR"
- elif [[ "${{ needs.preview-services.result }}" == "failure" ]]; then
- echo "❌ One or more Pulumi previews failed"
- exit 1
- elif [[ "${{ needs.preview-services.result }}" == "success" ]]; then
- echo "✅ All Pulumi previews completed successfully"
- elif [[ "${{ needs.preview-services.result }}" == "skipped" ]]; then
- echo "ℹ️ No services were affected by the changes in this PR"
- fi
diff --git a/.github/workflows/pulumi_preview_pr.yml b/.github/workflows/pulumi_preview_pr.yml
new file mode 100644
index 0000000000..f85c344eae
--- /dev/null
+++ b/.github/workflows/pulumi_preview_pr.yml
@@ -0,0 +1,123 @@
+# DO NOT EDIT — regenerate with `cargo x workflows` (from rust/cloud-storage).
+# Source: rust/cloud-storage/tools/xtask/src/workflows/pulumi_preview_pr.rs
+name: Pulumi Preview on PR
+on:
+ pull_request:
+ branches:
+ - main
+ paths:
+ - rust/cloud-storage/**
+ - .github/workflows/pulumi_preview_pr.yml
+ - .github/workflows/reusable_preview_service.yml
+ - .github/actions/preview-cloud-storage-pulumi/**
+ - .github/services-config.json
+permissions:
+ contents: read
+ pull-requests: write
+ id-token: write
+jobs:
+ detect-changes:
+ name: Detect Changed Services
+ runs-on: namespace-profile-linux-small
+ outputs:
+ services: ${{ steps.detect.outputs.services }}
+ has-changes: ${{ steps.detect.outputs.has-changes }}
+ steps:
+ - name: Checkout Repo
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
+ - id: changed-files
+ name: Get changed files
+ uses: tj-actions/changed-files@24d32ffd492484c1d75e0c0b894501ddb9d30d62
+ with:
+ files: |-
+ rust/cloud-storage/**
+ .github/services-config.json
+ - id: detect
+ name: Detect affected services
+ run: |
+ services=()
+
+ # Read service config
+ config=$(cat .github/services-config.json)
+
+ # Check each service for changes
+ for service in $(echo "$config" | jq -r '.services | keys[]'); do
+ service_changed=false
+
+ # Get paths for this service
+ source_path=$(echo "$config" | jq -r --arg s "$service" '.services[$s].source_path // ""')
+ stack_path=$(echo "$config" | jq -r --arg s "$service" '.services[$s].stack_path // ""')
+ additional_paths=$(echo "$config" | jq -r --arg s "$service" '.services[$s].additional_paths[]? // ""')
+
+ # Check if any changed files match service paths. CHANGED_FILES is a
+ # space-separated list passed via env — never inlined into the script
+ # body, so a crafted filename can't inject shell syntax.
+ for file in $CHANGED_FILES; do
+ if [[ -n "$source_path" && "$file" == $source_path ]]; then
+ service_changed=true
+ elif [[ -n "$stack_path" && "$file" == $stack_path ]]; then
+ service_changed=true
+ elif [[ -n "$additional_paths" ]]; then
+ for path in $additional_paths; do
+ if [[ "$file" == $path ]]; then
+ service_changed=true
+ fi
+ done
+ fi
+ done
+
+ if [[ "$service_changed" == "true" ]]; then
+ services+=("$service")
+ fi
+ done
+
+ if [ ${#services[@]} -eq 0 ]; then
+ echo "has-changes=false" >> $GITHUB_OUTPUT
+ echo "services=[]" >> $GITHUB_OUTPUT
+ echo "No services affected by changes"
+ else
+ echo "has-changes=true" >> $GITHUB_OUTPUT
+ services_json=$(printf '%s\n' "${services[@]}" | jq -R . | jq -s -c .)
+ echo "services=${services_json}" >> $GITHUB_OUTPUT
+ echo "Services to preview: ${services[@]}"
+ fi
+ env:
+ CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
+ preview-services:
+ needs:
+ - detect-changes
+ if: ${{ needs.detect-changes.outputs.has-changes == 'true' }}
+ name: Preview ${{ matrix.service }}
+ uses: ./.github/workflows/reusable_preview_service.yml
+ strategy:
+ matrix:
+ service: ${{ fromJson(needs.detect-changes.outputs.services) }}
+ fail-fast: false
+ with:
+ environment: dev
+ service-name: ${{ matrix.service }}
+ github-token: ${{ github.token }}
+ secrets: inherit
+ preview-status:
+ needs:
+ - detect-changes
+ - preview-services
+ if: always()
+ name: Preview Status
+ runs-on: namespace-profile-linux-small
+ steps:
+ - name: Summary
+ run: |
+ if [[ "${{ needs.detect-changes.outputs.has-changes }}" == "false" ]]; then
+ echo "ℹ️ No services were affected by the changes in this PR"
+ elif [[ "${{ needs.preview-services.result }}" == "failure" ]]; then
+ echo "❌ One or more Pulumi previews failed"
+ exit 1
+ elif [[ "${{ needs.preview-services.result }}" == "success" ]]; then
+ echo "✅ All Pulumi previews completed successfully"
+ elif [[ "${{ needs.preview-services.result }}" == "skipped" ]]; then
+ echo "ℹ️ No services were affected by the changes in this PR"
+ fi
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
diff --git a/.github/workflows/reusable-preview-service.yml b/.github/workflows/reusable-preview-service.yml
deleted file mode 100644
index 7ddda28bf2..0000000000
--- a/.github/workflows/reusable-preview-service.yml
+++ /dev/null
@@ -1,73 +0,0 @@
-name: Reusable Preview Service
-on:
- workflow_call:
- inputs:
- environment:
- required: true
- type: string
- description: The environment to preview
- service-name:
- required: true
- type: string
- description: The name of the service to preview
- pulumi-stack-name:
- required: false
- type: string
- description: Override pulumi stack name (defaults to service-name)
- use-docker:
- required: false
- type: boolean
- default: true
- description: Whether to setup docker
- use-lfs:
- required: false
- type: boolean
- default: false
- description: Whether to checkout LFS content
- github-token:
- required: false
- type: string
- description: GitHub token for PR comments
- secrets:
- AWS_ACCESS_KEY:
- required: true
- AWS_SECRET_ACCESS_KEY:
- required: true
- PULUMI_ACCESS_TOKEN:
- required: true
- DD_APP_KEY:
- required: true
- DD_API_KEY:
- required: true
- CACHIX_AUTH_TOKEN:
- required: true
- SCCACHE_BUCKET:
- required: false
-
-jobs:
- preview:
- runs-on: linux-extra-beefy
- steps:
- - uses: actions/checkout@v6
-
- - name: Get project name
- id: project-name
- uses: ./.github/actions/get-project-name
- with:
- service-name: ${{ inputs.service-name }}
-
- - uses: ./.github/actions/preview-cloud-storage-pulumi
- with:
- environment: ${{ inputs.environment }}
- aws-access-key: ${{ secrets.AWS_ACCESS_KEY }}
- aws-secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- pulumi-access-token: ${{ secrets.PULUMI_ACCESS_TOKEN }}
- pulumi-service-name: ${{ inputs.pulumi-stack-name || steps.project-name.outputs.project-name }}
- dd-app-key: ${{ secrets.DD_APP_KEY }}
- dd-api-key: ${{ secrets.DD_API_KEY }}
- use-docker: ${{ inputs.use-docker }}
- use-lfs: ${{ inputs.use-lfs }}
- github-token: ${{ inputs.github-token }}
- cloud-storage-service-name: ${{ inputs.service-name }}
- cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
- sccache-bucket: ${{ vars.SCCACHE_BUCKET || secrets.SCCACHE_BUCKET }}
diff --git a/.github/workflows/reusable_preview_service.yml b/.github/workflows/reusable_preview_service.yml
new file mode 100644
index 0000000000..f58d7a47e7
--- /dev/null
+++ b/.github/workflows/reusable_preview_service.yml
@@ -0,0 +1,81 @@
+# DO NOT EDIT — regenerate with `cargo x workflows` (from rust/cloud-storage).
+# Source: rust/cloud-storage/tools/xtask/src/workflows/reusable_preview_service.rs
+name: Reusable Preview Service
+on:
+ workflow_call:
+ inputs:
+ environment:
+ required: true
+ type: string
+ description: The environment to preview
+ service-name:
+ required: true
+ type: string
+ description: The name of the service to preview
+ pulumi-stack-name:
+ required: false
+ type: string
+ description: Override pulumi stack name (defaults to service-name)
+ use-docker:
+ required: false
+ type: boolean
+ default: true
+ description: Whether to setup docker
+ use-lfs:
+ required: false
+ type: boolean
+ default: false
+ description: Whether to checkout LFS content
+ github-token:
+ required: false
+ type: string
+ description: GitHub token for PR comments
+ secrets:
+ AWS_ACCESS_KEY:
+ required: true
+ AWS_SECRET_ACCESS_KEY:
+ required: true
+ PULUMI_ACCESS_TOKEN:
+ required: true
+ DD_APP_KEY:
+ required: true
+ DD_API_KEY:
+ required: true
+ CACHIX_AUTH_TOKEN:
+ required: true
+jobs:
+ preview:
+ runs-on: namespace-profile-linux-small
+ steps:
+ - name: Checkout Repo
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
+ - name: Mount /nix cache volume
+ uses: namespacelabs/nscloud-cache-action@15799a6b54e5765f85b2aac25b3f0df43ed571c0
+ with:
+ path: /nix
+ continue-on-error: true
+ - name: Setup Nix
+ uses: ./.github/actions/setup-nix
+ - id: project-name
+ name: Get project name
+ uses: ./.github/actions/get-project-name
+ with:
+ service-name: ${{ inputs.service-name }}
+ - name: Preview pulumi stack
+ uses: ./.github/actions/preview-cloud-storage-pulumi
+ with:
+ environment: ${{ inputs.environment }}
+ aws-access-key: ${{ secrets.AWS_ACCESS_KEY }}
+ aws-secret-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
+ pulumi-access-token: ${{ secrets.PULUMI_ACCESS_TOKEN }}
+ pulumi-service-name: ${{ inputs.pulumi-stack-name || steps.project-name.outputs.project-name }}
+ dd-app-key: ${{ secrets.DD_APP_KEY }}
+ dd-api-key: ${{ secrets.DD_API_KEY }}
+ use-docker: ${{ inputs.use-docker }}
+ use-lfs: ${{ inputs.use-lfs }}
+ github-token: ${{ inputs.github-token }}
+ cloud-storage-service-name: ${{ inputs.service-name }}
+ cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}
+ - name: Teardown Nix
+ if: always()
+ uses: ./.github/actions/teardown-nix
diff --git a/rust/cloud-storage/tools/xtask/src/workflows/mod.rs b/rust/cloud-storage/tools/xtask/src/workflows/mod.rs
index 81f9f531e1..4a116d16a4 100644
--- a/rust/cloud-storage/tools/xtask/src/workflows/mod.rs
+++ b/rust/cloud-storage/tools/xtask/src/workflows/mod.rs
@@ -19,6 +19,8 @@ mod check_node_modules_nix;
mod code_check_cloud_storage;
mod code_check_infra;
mod deploy_preview;
+mod pulumi_preview_pr;
+mod reusable_preview_service;
mod runners;
mod steps;
mod vars;
@@ -47,6 +49,35 @@ fn render_gh_workflow(build: fn() -> Workflow) -> impl Fn() -> Result<String> {
move || build().to_string().map_err(|e| anyhow::anyhow!("{e:?}"))
}
+/// Render a `gh_workflow::Workflow`, then apply a structural patch to the YAML
+/// for constructs gh-workflow 0.8 cannot express: reusable-workflow caller
+/// `with:` / `secrets: inherit`, and `workflow_call`/`workflow_dispatch` input
+/// blocks (the crate models those as unordered `HashMap`s, which would
+/// serialize in nondeterministic order and trip the drift guard).
+fn render_patched(
+ build: fn() -> Workflow,
+ patch: fn(&mut serde_yaml::Value) -> Result<()>,
+) -> Result<String> {
+ let yaml = render_gh_workflow(build)()?;
+ let mut root: serde_yaml::Value =
+ serde_yaml::from_str(&yaml).context("re-parsing generated workflow YAML")?;
+ patch(&mut root)?;
+ serde_yaml::to_string(&root).context("serializing patched workflow YAML")
+}
+
+/// Parse a YAML fragment (used by workflow `patch` fns to build ordered blocks).
+fn yaml_fragment(s: &str) -> Result<serde_yaml::Value> {
+ serde_yaml::from_str(s).context("parsing YAML fragment")
+}
+
+/// Look up `jobs.<id>` in a rendered workflow as a mutable mapping.
+fn job_mut<'a>(root: &'a mut serde_yaml::Value, id: &str) -> Result<&'a mut serde_yaml::Mapping> {
+ root.get_mut("jobs")
+ .and_then(|jobs| jobs.get_mut(id))
+ .and_then(serde_yaml::Value::as_mapping_mut)
+ .with_context(|| format!("job `{id}` not found in rendered workflow"))
+}
+
/// Every workflow we generate. Add new workflows here.
const WORKFLOWS: &[WorkflowFile] = &[
WorkflowFile {
@@ -89,6 +120,26 @@ const WORKFLOWS: &[WorkflowFile] = &[
file_name: "deploy_preview.yml",
render_yaml: || render_gh_workflow(deploy_preview::deploy_preview)(),
},
+ WorkflowFile {
+ slug: "pulumi_preview_pr",
+ file_name: "pulumi_preview_pr.yml",
+ render_yaml: || {
+ render_patched(
+ pulumi_preview_pr::pulumi_preview_pr,
+ pulumi_preview_pr::patch,
+ )
+ },
+ },
+ WorkflowFile {
+ slug: "reusable_preview_service",
+ file_name: "reusable_preview_service.yml",
+ render_yaml: || {
+ render_patched(
+ reusable_preview_service::reusable_preview_service,
+ reusable_preview_service::patch,
+ )
+ },
+ },
WorkflowFile {
slug: "check_node_modules_nix",
file_name: "check_node_modules_nix.yml",
diff --git a/rust/cloud-storage/tools/xtask/src/workflows/pulumi_preview_pr.rs b/rust/cloud-storage/tools/xtask/src/workflows/pulumi_preview_pr.rs
new file mode 100644
index 0000000000..57676cc12a
--- /dev/null
+++ b/rust/cloud-storage/tools/xtask/src/workflows/pulumi_preview_pr.rs
@@ -0,0 +1,198 @@
+//! `Pulumi Preview on PR` — detects which cloud-storage services a PR touches
+//! and fans out a pulumi preview per service via `reusable_preview_service`.
+//! Generated into `pulumi_preview_pr.yml` (replaces the hand-written
+//! `pulumi-preview-pr.yml`).
+
+use anyhow::Result;
+use gh_workflow::{
+ Concurrency, Env, Event, Expression, Job, Level, Permissions, PullRequest, Run, Step, Strategy,
+ Use, Workflow,
+};
+
+use crate::workflows::runners;
+
+/// 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("rust/cloud-storage/**")
+ .add_path(".github/workflows/pulumi_preview_pr.yml")
+ .add_path(".github/workflows/reusable_preview_service.yml")
+ .add_path(".github/actions/preview-cloud-storage-pulumi/**")
+ .add_path(".github/services-config.json"),
+ ))
+ .concurrency(
+ Concurrency::new(Expression::new(
+ "${{ github.workflow }}-${{ github.event.pull_request.number }}",
+ ))
+ .cancel_in_progress(true),
+ )
+ .permissions(
+ Permissions::default()
+ .contents(Level::Read)
+ .pull_requests(Level::Write)
+ .id_token(Level::Write),
+ )
+ .add_job("detect-changes", detect_changes())
+ .add_job("preview-services", preview_services())
+ .add_job("preview-status", preview_status())
+}
+
+/// Add what gh-workflow cannot express on the caller job, and drop the
+/// `runs-on: ubuntu-latest` that `Job::default()` injects — a job that `uses`
+/// a reusable workflow must not declare a runner.
+pub fn patch(root: &mut serde_yaml::Value) -> Result<()> {
+ let job = crate::workflows::job_mut(root, "preview-services")?;
+ job.remove("runs-on");
+ job.insert(
+ "with".into(),
+ crate::workflows::yaml_fragment(indoc::indoc! {r#"
+ environment: dev
+ service-name: ${{ matrix.service }}
+ github-token: ${{ github.token }}
+ "#})?,
+ );
+ job.insert("secrets".into(), "inherit".into());
+ Ok(())
+}
+
+fn detect_changes() -> Job {
+ Job::default()
+ .name("Detect Changed Services")
+ .runs_on(runners::Runner::Small.to_string())
+ .add_output("services", "${{ steps.detect.outputs.services }}")
+ .add_output("has-changes", "${{ steps.detect.outputs.has-changes }}")
+ .add_step(checkout())
+ .add_step(changed_files())
+ .add_step(detect_affected_services())
+}
+
+fn preview_services() -> Job {
+ Job::default()
+ .name("Preview ${{ matrix.service }}")
+ .needs(vec!["detect-changes".to_string()])
+ .cond(Expression::new(
+ "${{ needs.detect-changes.outputs.has-changes == 'true' }}",
+ ))
+ .strategy(Strategy {
+ fail_fast: Some(false),
+ matrix: Some(serde_json::json!({
+ "service": "${{ fromJson(needs.detect-changes.outputs.services) }}",
+ })),
+ max_parallel: None,
+ })
+ .uses("./.github/workflows/reusable_preview_service.yml")
+}
+
+fn preview_status() -> Job {
+ Job::default()
+ .name("Preview Status")
+ .needs(vec![
+ "detect-changes".to_string(),
+ "preview-services".to_string(),
+ ])
+ .cond(Expression::new("always()"))
+ .runs_on(runners::Runner::Small.to_string())
+ .add_step(summary())
+}
+
+fn checkout() -> Step<Use> {
+ Step::new("Checkout Repo").uses(
+ "actions",
+ "checkout",
+ "df4cb1c069e1874edd31b4311f1884172cec0e10",
+ ) // v6
+}
+
+fn changed_files() -> Step<Use> {
+ Step::new("Get changed files")
+ .uses(
+ "tj-actions",
+ "changed-files",
+ "24d32ffd492484c1d75e0c0b894501ddb9d30d62",
+ ) // v47
+ .id("changed-files")
+ .add_with((
+ "files",
+ indoc::indoc! {r#"
+ rust/cloud-storage/**
+ .github/services-config.json
+ "#}
+ .trim_end(),
+ ))
+}
+
+fn detect_affected_services() -> Step<Run> {
+ Step::new("Detect affected services")
+ .run(indoc::indoc! {r#"
+ services=()
+
+ # Read service config
+ config=$(cat .github/services-config.json)
+
+ # Check each service for changes
+ for service in $(echo "$config" | jq -r '.services | keys[]'); do
+ service_changed=false
+
+ # Get paths for this service
+ source_path=$(echo "$config" | jq -r --arg s "$service" '.services[$s].source_path // ""')
+ stack_path=$(echo "$config" | jq -r --arg s "$service" '.services[$s].stack_path // ""')
+ additional_paths=$(echo "$config" | jq -r --arg s "$service" '.services[$s].additional_paths[]? // ""')
+
+ # Check if any changed files match service paths. CHANGED_FILES is a
+ # space-separated list passed via env — never inlined into the script
+ # body, so a crafted filename can't inject shell syntax.
+ for file in $CHANGED_FILES; do
+ if [[ -n "$source_path" && "$file" == $source_path ]]; then
+ service_changed=true
+ elif [[ -n "$stack_path" && "$file" == $stack_path ]]; then
+ service_changed=true
+ elif [[ -n "$additional_paths" ]]; then
+ for path in $additional_paths; do
+ if [[ "$file" == $path ]]; then
+ service_changed=true
+ fi
+ done
+ fi
+ done
+
+ if [[ "$service_changed" == "true" ]]; then
+ services+=("$service")
+ fi
+ done
+
+ if [ ${#services[@]} -eq 0 ]; then
+ echo "has-changes=false" >> $GITHUB_OUTPUT
+ echo "services=[]" >> $GITHUB_OUTPUT
+ echo "No services affected by changes"
+ else
+ echo "has-changes=true" >> $GITHUB_OUTPUT
+ services_json=$(printf '%s\n' "${services[@]}" | jq -R . | jq -s -c .)
+ echo "services=${services_json}" >> $GITHUB_OUTPUT
+ echo "Services to preview: ${services[@]}"
+ fi
+ "#})
+ .id("detect")
+ .add_env(Env::new(
+ "CHANGED_FILES",
+ "${{ steps.changed-files.outputs.all_changed_files }}",
+ ))
+}
+
+fn summary() -> Step<Run> {
+ Step::new("Summary").run(indoc::indoc! {r#"
+ if [[ "${{ needs.detect-changes.outputs.has-changes }}" == "false" ]]; then
+ echo "ℹ️ No services were affected by the changes in this PR"
+ elif [[ "${{ needs.preview-services.result }}" == "failure" ]]; then
+ echo "❌ One or more Pulumi previews failed"
+ exit 1
+ elif [[ "${{ needs.preview-services.result }}" == "success" ]]; then
+ echo "✅ All Pulumi previews completed successfully"
+ elif [[ "${{ needs.preview-services.result }}" == "skipped" ]]; then
+ echo "ℹ️ No services were affected by the changes in this PR"
+ fi
+ "#})
+}
diff --git a/rust/cloud-storage/tools/xtask/src/workflows/reusable_preview_service.rs b/rust/cloud-storage/tools/xtask/src/workflows/reusable_preview_service.rs
new file mode 100644
index 0000000000..50ad268fb6
--- /dev/null
+++ b/rust/cloud-storage/tools/xtask/src/workflows/reusable_preview_service.rs
@@ -0,0 +1,128 @@
+//! `Reusable Preview Service` — pulumi preview (dry run) for one cloud-storage
+//! service, called per changed service by `pulumi_preview_pr`. Generated into
+//! `reusable_preview_service.yml` (replaces the hand-written
+//! `reusable-preview-service.yml`).
+//!
+//! The preview job is pulumi-preview + occasional Lambda Nix builds (warm runs
+//! are pure cache substitution), so `linux-small` suffices; it mounts the
+//! profile's default `/nix` volume, with `setup-nix` before use and
+//! `teardown-nix` after. Cold Lambda closures fall back to Cachix.
+
+use anyhow::Result;
+use gh_workflow::{Event, Job, Step, Use, Workflow, WorkflowCall};
+
+use crate::workflows::{runners, steps};
+
+/// Build the workflow. The `workflow_call` input/secret block is filled in by
+/// [`patch`] (gh-workflow models it as unordered maps).
+pub fn reusable_preview_service() -> Workflow {
+ Workflow::new("Reusable Preview Service")
+ .on(Event::default().workflow_call(WorkflowCall::default()))
+ .add_job("preview", preview())
+}
+
+/// Fill in the ordered `workflow_call` inputs/secrets block.
+///
+/// Relative to the hand-written workflow this drops the `SCCACHE_BUCKET`
+/// secret and its pass-through: Lambda artifacts build inside Nix derivations,
+/// where S3 sccache never applied (the sole caller uses `secrets: inherit`, so
+/// no caller change is needed).
+pub fn patch(root: &mut serde_yaml::Value) -> Result<()> {
+ let on = root
+ .get_mut("on")
+ .and_then(serde_yaml::Value::as_mapping_mut)
+ .ok_or_else(|| anyhow::anyhow!("rendered workflow has no `on` mapping"))?;
+ on.insert(
+ "workflow_call".into(),
+ crate::workflows::yaml_fragment(indoc::indoc! {r#"
+ inputs:
+ environment:
+ required: true
+ type: string
+ description: The environment to preview
+ service-name:
+ required: true
+ type: string
+ description: The name of the service to preview
+ pulumi-stack-name:
+ required: false
+ type: string
+ description: Override pulumi stack name (defaults to service-name)
+ use-docker:
+ required: false
+ type: boolean
+ default: true
+ description: Whether to setup docker
+ use-lfs:
+ required: false
+ type: boolean
+ default: false
+ description: Whether to checkout LFS content
+ github-token:
+ required: false
+ type: string
+ description: GitHub token for PR comments
+ secrets:
+ AWS_ACCESS_KEY:
+ required: true
+ AWS_SECRET_ACCESS_KEY:
+ required: true
+ PULUMI_ACCESS_TOKEN:
+ required: true
+ DD_APP_KEY:
+ required: true
+ DD_API_KEY:
+ required: true
+ CACHIX_AUTH_TOKEN:
+ required: true
+ "#})?,
+ );
+ Ok(())
+}
+
+fn preview() -> Job {
+ Job::default()
+ .runs_on(runners::Runner::Small.to_string())
+ .add_step(checkout())
+ .add_step(steps::mount_nix_cache_volume())
+ .add_step(steps::setup_nix())
+ .add_step(get_project_name())
+ .add_step(preview_pulumi())
+ .add_step(steps::teardown_nix())
+}
+
+fn checkout() -> Step<Use> {
+ Step::new("Checkout Repo").uses(
+ "actions",
+ "checkout",
+ "df4cb1c069e1874edd31b4311f1884172cec0e10",
+ ) // v6
+}
+
+fn get_project_name() -> Step<Use> {
+ steps::uses_local("Get project name", "./.github/actions/get-project-name")
+ .id("project-name")
+ .add_with(("service-name", "${{ inputs.service-name }}"))
+}
+
+fn preview_pulumi() -> Step<Use> {
+ steps::uses_local(
+ "Preview pulumi stack",
+ "./.github/actions/preview-cloud-storage-pulumi",
+ )
+ .add_with(("environment", "${{ inputs.environment }}"))
+ .add_with(("aws-access-key", "${{ secrets.AWS_ACCESS_KEY }}"))
+ .add_with(("aws-secret-key", "${{ secrets.AWS_SECRET_ACCESS_KEY }}"))
+ .add_with(("pulumi-access-token", "${{ secrets.PULUMI_ACCESS_TOKEN }}"))
+ .add_with((
+ "pulumi-service-name",
+ "${{ inputs.pulumi-stack-name || steps.project-name.outputs.project-name }}",
+ ))
+ .add_with(("dd-app-key", "${{ secrets.DD_APP_KEY }}"))
+ .add_with(("dd-api-key", "${{ secrets.DD_API_KEY }}"))
+ .add_with(("use-docker", "${{ inputs.use-docker }}"))
+ .add_with(("use-lfs", "${{ inputs.use-lfs }}"))
+ .add_with(("github-token", "${{ inputs.github-token }}"))
+ .add_with(("cloud-storage-service-name", "${{ inputs.service-name }}"))
+ .add_with(("cachix-auth-token", "${{ secrets.CACHIX_AUTH_TOKEN }}"))
+}