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.

perf(ci): build the web app while the backend deploys (#7811)

Wolf Mermelsteinc70d11310aa7
diff --git a/.github/workflows/build_web_app.yml b/.github/workflows/build_web_app.yml
new file mode 100644
index 0000000000..da872b49f2
--- /dev/null
+++ b/.github/workflows/build_web_app.yml
@@ -0,0 +1,92 @@
+# DO NOT EDIT — regenerate with `cargo x workflows` (from the repository root).
+# Source: tooling/xtask/crates/xtask_workflows/src/workflows/build_web_app.rs
+name: Build Web App
+on:
+ workflow_call:
+ inputs:
+ environment:
+ required: true
+ type: string
+ description: The environment to build for. e.g. (dev, prod)
+ secrets:
+ SEGMENT_WRITE_KEY:
+ required: true
+ POSTHOG_API_KEY:
+ required: true
+jobs:
+ build:
+ name: Build
+ runs-on: namespace-profile-linux-mid;overrides.cache-tag=web-ci
+ env:
+ CI: 'true'
+ steps:
+ - name: Checkout Repo
+ uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
+ with:
+ ref: ${{ github.sha }}
+ - name: Mount Namespace cache volume
+ uses: namespacelabs/nscloud-cache-action@15799a6b54e5765f85b2aac25b3f0df43ed571c0
+ with:
+ cache: nix
+ path: |-
+ /home/runner/.bun/install/cache
+ /home/runner/.cargo/registry
+ /home/runner/.cargo/git
+ /home/runner/.cache/.wasm-pack
+ continue-on-error: true
+ - name: Setup Nix
+ uses: ./.github/actions/setup-nix
+ - name: Setup
+ uses: ./.github/actions/setup-reqs-web
+ - name: Configure Namespace remote sccache
+ if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || github.event.pull_request.head.repo.full_name == github.repository
+ run: |-
+ set -euo pipefail
+ env_file="$(mktemp "$RUNNER_TEMP/namespace-sccache.XXXXXX")"
+ trap 'rm -f "$env_file"' EXIT
+ if nsc cache sccache setup --cache_name web-ci > "$env_file"; then
+ # Register credential values as masked BEFORE exporting: GitHub only
+ # masks `secrets.*`, so without this SCCACHE_WEBDAV_TOKEN — a broad,
+ # ~24h Namespace workspace token (registry + cache write) — printed
+ # verbatim in every subsequent step's env dump. Masking is selective by
+ # key name: masking non-secrets like the endpoint URL or key prefix
+ # would redact those strings everywhere in the logs.
+ while IFS= read -r line; do
+ k="${line%%=*}"
+ v="${line#*=}"
+ [ -n "$v" ] && [ "$k" != "$line" ] || continue
+ case "$k" in
+ *TOKEN*|*SECRET*|*PASSWORD*) echo "::add-mask::$v" ;;
+ esac
+ done < "$env_file"
+ cat "$env_file" >> "$GITHUB_ENV"
+ # Force the next compiler invocation to start a server with the new remote
+ # backend even if a setup hook happened to launch one already.
+ sccache --stop-server >/dev/null 2>&1 || true
+ else
+ echo "::warning::Namespace remote sccache setup failed; using local cache fallback"
+ fi
+ - name: Start sccache server
+ run: sccache --start-server
+ - name: Build
+ run: just build-${{ inputs.environment }}
+ env:
+ VITE_SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }}
+ VITE_POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
+ VITE_OTEL_EXPORTER_URL: ${{ inputs.environment == 'prod' && 'https://macro-prox-prod.macroverse.workers.dev/i/otlp/v1/traces' || 'https://macro-prox-dev.macroverse.workers.dev/i/otlp/v1/traces' }}
+ VITE_OTEL_ENV: ${{ inputs.environment == 'prod' && 'prod' || 'development' }}
+ working-directory: apps/web
+ - name: show sccache stats
+ if: always()
+ run: sccache --show-stats || true
+ - name: Upload dist
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
+ with:
+ name: web-app-dist-${{ inputs.environment }}
+ path: apps/web/dist
+ if-no-files-found: error
+ retention-days: '1'
+ overwrite: 'true'
+ - name: Teardown Nix
+ if: always()
+ uses: ./.github/actions/teardown-nix
diff --git a/.github/workflows/deploy_on_push.yml b/.github/workflows/deploy_on_push.yml
index 0511438bc4..f19d4f5b5e 100644
--- a/.github/workflows/deploy_on_push.yml
+++ b/.github/workflows/deploy_on_push.yml
@@ -47,14 +47,24 @@ jobs:
environment: dev
secrets:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
+ build-web-app:
+ name: Build Web App
+ uses: ./.github/workflows/build_web_app.yml
+ with:
+ environment: dev
+ secrets:
+ SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_PRODUCTION }}
+ POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
deploy-web-app:
needs:
- deploy-cloud-storage
+ - build-web-app
name: Deploy Web App
uses: ./.github/workflows/deploy_web_app.yml
with:
notify: false
environment: dev
+ prebuilt: true
secrets:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
diff --git a/.github/workflows/deploy_web_app.yml b/.github/workflows/deploy_web_app.yml
index 9f1a11bf1b..78f9f9c223 100644
--- a/.github/workflows/deploy_web_app.yml
+++ b/.github/workflows/deploy_web_app.yml
@@ -11,6 +11,11 @@ on:
notify:
required: false
type: boolean
+ prebuilt:
+ required: false
+ type: boolean
+ default: false
+ description: The caller already ran build_web_app.yml in this run
secrets:
AWS_ACCESS_KEY:
required: true
@@ -40,7 +45,20 @@ on:
type: boolean
description: Whether to notify the Slack channel of the deployment completion
jobs:
- build-deploy:
+ build:
+ if: ${{ !inputs.prebuilt }}
+ name: Build
+ uses: ./.github/workflows/build_web_app.yml
+ with:
+ environment: ${{ inputs.environment }}
+ secrets:
+ SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }}
+ POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
+ deploy:
+ needs:
+ - build
+ if: ${{ !cancelled() && (needs.build.result == 'success' || needs.build.result == 'skipped') }}
+ name: Deploy
runs-on: namespace-profile-linux-mid;overrides.cache-tag=web-ci
env:
CI: 'true'
@@ -63,47 +81,11 @@ jobs:
uses: ./.github/actions/setup-nix
- name: Setup
uses: ./.github/actions/setup-reqs-web
- - name: Configure Namespace remote sccache
- if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || github.event.pull_request.head.repo.full_name == github.repository
- run: |-
- set -euo pipefail
- env_file="$(mktemp "$RUNNER_TEMP/namespace-sccache.XXXXXX")"
- trap 'rm -f "$env_file"' EXIT
- if nsc cache sccache setup --cache_name web-ci > "$env_file"; then
- # Register credential values as masked BEFORE exporting: GitHub only
- # masks `secrets.*`, so without this SCCACHE_WEBDAV_TOKEN — a broad,
- # ~24h Namespace workspace token (registry + cache write) — printed
- # verbatim in every subsequent step's env dump. Masking is selective by
- # key name: masking non-secrets like the endpoint URL or key prefix
- # would redact those strings everywhere in the logs.
- while IFS= read -r line; do
- k="${line%%=*}"
- v="${line#*=}"
- [ -n "$v" ] && [ "$k" != "$line" ] || continue
- case "$k" in
- *TOKEN*|*SECRET*|*PASSWORD*) echo "::add-mask::$v" ;;
- esac
- done < "$env_file"
- cat "$env_file" >> "$GITHUB_ENV"
- # Force the next compiler invocation to start a server with the new remote
- # backend even if a setup hook happened to launch one already.
- sccache --stop-server >/dev/null 2>&1 || true
- else
- echo "::warning::Namespace remote sccache setup failed; using local cache fallback"
- fi
- - name: Start sccache server
- run: sccache --start-server
- - name: Build
- run: just build-${{ inputs.environment }}
- env:
- VITE_SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }}
- VITE_POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
- VITE_OTEL_EXPORTER_URL: ${{ inputs.environment == 'prod' && 'https://macro-prox-prod.macroverse.workers.dev/i/otlp/v1/traces' || 'https://macro-prox-dev.macroverse.workers.dev/i/otlp/v1/traces' }}
- VITE_OTEL_ENV: ${{ inputs.environment == 'prod' && 'prod' || 'development' }}
- working-directory: apps/web
- - name: show sccache stats
- if: always()
- run: sccache --show-stats || true
+ - name: Download dist
+ uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0
+ with:
+ name: web-app-dist-${{ inputs.environment }}
+ path: apps/web/dist
- name: Install infra dependencies
run: bun install
working-directory: infra
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows.rs b/tooling/xtask/crates/xtask_workflows/src/workflows.rs
index 52cfb6a761..9a3c64905d 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows.rs
@@ -15,6 +15,7 @@ mod build_agent_daemon_on_tag;
mod build_appimage_on_tag;
mod build_desktop_on_tag;
mod build_dmg_on_tag;
+mod build_web_app;
mod cancel_stuck_cloud_storage_deploys;
mod cargo_deny;
mod cargo_workspace_dependency_check;
@@ -139,6 +140,11 @@ const WORKFLOWS: &[WorkflowFile] = &[
file_name: "code_check_infra.yml",
render_yaml: || render_gh_workflow(code_check_infra::code_check_infra)(),
},
+ WorkflowFile {
+ slug: "build_web_app",
+ file_name: "build_web_app.yml",
+ render_yaml: || render_patched(build_web_app::build_web_app, build_web_app::patch),
+ },
WorkflowFile {
slug: "cancel_stuck_cloud_storage_deploys",
file_name: "cancel_stuck_cloud_storage_deploys.yml",
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/build_web_app.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/build_web_app.rs
new file mode 100644
index 0000000000..19f887aba7
--- /dev/null
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/build_web_app.rs
@@ -0,0 +1,110 @@
+//! `Build Web App` — builds apps/web for one environment and uploads `dist` as
+//! the [`ARTIFACT`] run artifact. Call-only: [`crate::workflows::deploy_web_app`]
+//! uses it for standalone deploys, and [`crate::workflows::deploy_on_push`]
+//! calls it directly so the build overlaps the backend deploy and only the
+//! upload waits for it. Generated into `build_web_app.yml`.
+
+use anyhow::Result;
+use gh_workflow::{Env, Event, Job, Run, Step, Use, Workflow, WorkflowCall};
+
+use crate::workflows::{runners, steps, vars};
+
+#[cfg(test)]
+mod test;
+
+/// Artifacts are scoped to the workflow run, and a called workflow shares its
+/// caller's run, so the deploy job finds this regardless of which workflow
+/// called the build.
+pub const ARTIFACT: &str = "web-app-dist-${{ inputs.environment }}";
+
+pub fn build_web_app() -> Workflow {
+ Workflow::new("Build Web App")
+ .on(Event::default().workflow_call(WorkflowCall::default()))
+ .add_job("build", build_job())
+}
+
+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 build for. e.g. (dev, prod)
+ secrets:
+ SEGMENT_WRITE_KEY:
+ required: true
+ POSTHOG_API_KEY:
+ required: true
+ "#})?,
+ );
+ Ok(())
+}
+
+/// The build uses the shared Namespace `web-ci` sccache cache, so no sccache
+/// backend secret is needed here.
+fn build_job() -> Job {
+ Job::default()
+ .name("Build")
+ .runs_on(runners::Runner::Mid.with_cache_tag(vars::WEB_CI_CACHE_TAG))
+ .add_env(("CI", "true"))
+ .add_step(checkout())
+ .add_step(steps::mount_web_build_cache_volume())
+ .add_step(steps::setup_nix())
+ .add_step(steps::setup_reqs_web("Setup", false))
+ .add_step(steps::configure_namespace_sccache(vars::WEB_SCCACHE_NAME))
+ .add_step(steps::start_sccache_server())
+ .add_step(build())
+ .add_step(steps::show_sccache_stats())
+ .add_step(upload_dist())
+ .add_step(steps::teardown_nix())
+}
+
+/// The pushed commit, not the branch tip: a merge that lands while this run's
+/// backend deploys must not ship its frontend against the older backend.
+pub fn checkout() -> Step<Use> {
+ Step::new("Checkout Repo")
+ .uses(
+ "actions",
+ "checkout",
+ "df4cb1c069e1874edd31b4311f1884172cec0e10",
+ ) // v6
+ .add_with(("ref", "${{ github.sha }}"))
+}
+
+/// Build identical across dev/prod up to `MODE` (`just build-<env>`).
+fn build() -> Step<Run> {
+ Step::new("Build")
+ .run("just build-${{ inputs.environment }}")
+ .working_directory(xtask_paths::repo_dir!("apps/web"))
+ .add_env(Env::new("VITE_SEGMENT_WRITE_KEY", vars::SEGMENT_WRITE_KEY))
+ .add_env(Env::new("VITE_POSTHOG_API_KEY", vars::POSTHOG_API_KEY))
+ .add_env(Env::new(
+ "VITE_OTEL_EXPORTER_URL",
+ "${{ inputs.environment == 'prod' && 'https://macro-prox-prod.macroverse.workers.dev/i/otlp/v1/traces' || 'https://macro-prox-dev.macroverse.workers.dev/i/otlp/v1/traces' }}",
+ ))
+ .add_env(Env::new(
+ "VITE_OTEL_ENV",
+ "${{ inputs.environment == 'prod' && 'prod' || 'development' }}",
+ ))
+}
+
+fn upload_dist() -> Step<Use> {
+ Step::new("Upload dist")
+ .uses(
+ "actions",
+ "upload-artifact",
+ "ea165f8d65b6e75b540449e92b4886f43607fa02",
+ ) // v4
+ .add_with(("name", ARTIFACT))
+ .add_with(("path", xtask_paths::runtime_path!("apps/web/dist").as_str()))
+ .add_with(("if-no-files-found", "error"))
+ .add_with(("retention-days", 1))
+ // A full re-run of the same run uploads again under the same name.
+ .add_with(("overwrite", true))
+}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/deploy_web_app/test.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/build_web_app/test.rs
similarity index 61%
rename from tooling/xtask/crates/xtask_workflows/src/workflows/deploy_web_app/test.rs
rename to tooling/xtask/crates/xtask_workflows/src/workflows/build_web_app/test.rs
index d8b10b9d7e..300f154e00 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/deploy_web_app/test.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/build_web_app/test.rs
@@ -1,15 +1,12 @@
use super::*;
#[test]
-fn deploy_build_uses_remote_sccache_and_wasm_cache() {
- let yaml = deploy_web_app().to_string().expect("workflow yaml");
- let job = yaml
- .split("\n build-deploy:\n")
- .nth(1)
- .expect("build-deploy job");
+fn build_uses_remote_sccache_and_wasm_cache() {
+ let yaml = build_web_app().to_string().expect("workflow yaml");
+ let job = yaml.split("\n build:\n").nth(1).expect("build job");
assert!(
job.contains("nsc cache sccache setup --cache_name web-ci"),
- "deploy must use the shared web-ci remote sccache: {job}"
+ "build must use the shared web-ci remote sccache: {job}"
);
let configure = job
.find("nsc cache sccache setup")
@@ -21,10 +18,10 @@ fn deploy_build_uses_remote_sccache_and_wasm_cache() {
assert!(configure < start && start < build_command);
assert!(
job.contains(".wasm-pack"),
- "deploy must persist wasm-pack's wasm-opt cache: {job}"
+ "build must persist wasm-pack's wasm-opt cache: {job}"
);
assert!(
job.contains("just build-${{ inputs.environment }}"),
- "deploy still builds via just: {job}"
+ "build still runs via just: {job}"
);
}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/deploy_on_push.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/deploy_on_push.rs
index b9d8679c50..84d071d259 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/deploy_on_push.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/deploy_on_push.rs
@@ -1,6 +1,8 @@
//! `Deploy on Push` — the single push-to-main dev deploy pipeline. Mirrors the
//! production release flow: cloud storage first, then the sync service and web
-//! app, with every stage deploying unconditionally.
+//! app, with every stage deploying unconditionally. The web app *builds* in
+//! parallel with the backend; only its upload waits, so the frontend still
+//! goes live last.
//!
//! Nothing is path-gated, deliberately. The pipeline serializes on one
//! concurrency group, and GitHub cancels a *pending* run as soon as a newer one
@@ -71,6 +73,7 @@ pub fn deploy_on_push() -> Workflow {
)
.add_job("deploy-cloud-storage", deploy_cloud_storage())
.add_job("deploy-sync-service", deploy_sync_service())
+ .add_job("build-web-app", build_web_app())
.add_job("deploy-web-app", deploy_web_app())
}
@@ -108,6 +111,20 @@ pub fn patch(root: &mut serde_yaml::Value) -> Result<()> {
"#})?,
);
+ let web_build = crate::workflows::job_mut(root, "build-web-app")?;
+ web_build.remove("runs-on");
+ web_build.insert(
+ "with".into(),
+ crate::workflows::yaml_fragment("environment: dev")?,
+ );
+ web_build.insert(
+ "secrets".into(),
+ crate::workflows::yaml_fragment(indoc::indoc! {r#"
+ SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_PRODUCTION }}
+ POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
+ "#})?,
+ );
+
let web_app = crate::workflows::job_mut(root, "deploy-web-app")?;
web_app.remove("runs-on");
web_app.insert(
@@ -115,6 +132,7 @@ pub fn patch(root: &mut serde_yaml::Value) -> Result<()> {
crate::workflows::yaml_fragment(indoc::indoc! {r#"
notify: false
environment: dev
+ prebuilt: true
"#})?,
);
web_app.insert(
@@ -148,10 +166,22 @@ fn deploy_sync_service() -> Job {
.uses("./.github/workflows/deploy_sync_service.yml")
}
-/// Same ordering rationale as [`deploy_sync_service`].
+/// No `needs`: the build only reads the commit, so it overlaps the backend's
+/// ~15 minutes instead of adding ~4 after them.
+fn build_web_app() -> Job {
+ Job::default()
+ .name("Build Web App")
+ .uses("./.github/workflows/build_web_app.yml")
+}
+
+/// Same ordering rationale as [`deploy_sync_service`]; uploads the dist that
+/// [`build_web_app`] left in this run.
fn deploy_web_app() -> Job {
Job::default()
.name("Deploy Web App")
- .needs(vec!["deploy-cloud-storage".to_string()])
+ .needs(vec![
+ "deploy-cloud-storage".to_string(),
+ "build-web-app".to_string(),
+ ])
.uses("./.github/workflows/deploy_web_app.yml")
}
diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/deploy_web_app.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/deploy_web_app.rs
index a344b99e4e..48d5b3ab04 100644
--- a/tooling/xtask/crates/xtask_workflows/src/workflows/deploy_web_app.rs
+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/deploy_web_app.rs
@@ -1,5 +1,7 @@
-//! `Deploy Web App` — builds apps/web and deploys it via the web-app pulumi
-//! stack; reusable (workflow_call) and manually dispatchable. Generated into
+//! `Deploy Web App` — builds apps/web (via [`crate::workflows::build_web_app`])
+//! and deploys it via the web-app pulumi stack; reusable (workflow_call) and
+//! manually dispatchable. A caller that already ran the build in the same run
+//! passes `prebuilt: true` to skip straight to the upload. Generated into
//! `deploy_web_app.yml` (replaces the hand-written `deploy-web-app.yml`;
//! dispatch identity is the workflow *name*, so the rename doesn't affect
//! anyone's dispatch habits).
@@ -10,10 +12,7 @@ use gh_workflow::{
WorkflowDispatch,
};
-use crate::workflows::{runners, steps, vars};
-
-#[cfg(test)]
-mod test;
+use crate::workflows::{build_web_app, runners, steps, vars};
/// Build the workflow. The `workflow_dispatch`/`workflow_call` input blocks
/// are filled in by [`patch`] (choice options + ordered maps).
@@ -33,13 +32,12 @@ pub fn deploy_web_app() -> Workflow {
Concurrency::new(Expression::new("deploy-web-app-${{ inputs.environment }}"))
.cancel_in_progress(false),
)
- .add_job("build-deploy", build_deploy())
+ .add_job("build", build())
+ .add_job("deploy", deploy())
}
-/// Fill in the ordered dispatch/call input blocks.
-///
-/// The build uses the shared Namespace `web-ci` sccache cache, so no sccache
-/// backend secret is needed here.
+/// Fill in the ordered dispatch/call input blocks and the build call's
+/// `with:`/`secrets:`.
pub fn patch(root: &mut serde_yaml::Value) -> Result<()> {
let on = root
.get_mut("on")
@@ -73,6 +71,11 @@ pub fn patch(root: &mut serde_yaml::Value) -> Result<()> {
notify:
required: false
type: boolean
+ prebuilt:
+ required: false
+ type: boolean
+ default: false
+ description: The caller already ran build_web_app.yml in this run
secrets:
AWS_ACCESS_KEY:
required: true
@@ -90,21 +93,47 @@ pub fn patch(root: &mut serde_yaml::Value) -> Result<()> {
required: true
"#})?,
);
+
+ let build = crate::workflows::job_mut(root, "build")?;
+ build.remove("runs-on");
+ build.insert(
+ "with".into(),
+ crate::workflows::yaml_fragment("environment: ${{ inputs.environment }}")?,
+ );
+ build.insert(
+ "secrets".into(),
+ crate::workflows::yaml_fragment(indoc::indoc! {r#"
+ SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY }}
+ POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
+ "#})?,
+ );
Ok(())
}
-fn build_deploy() -> Job {
+/// `inputs.prebuilt` is unset under workflow_dispatch, so dispatches build.
+fn build() -> Job {
+ Job::default()
+ .name("Build")
+ .cond(Expression::new("${{ !inputs.prebuilt }}"))
+ .uses("./.github/workflows/build_web_app.yml")
+}
+
+/// Runs after either this run's build or the caller's: a skipped build means
+/// `prebuilt`, but the default `success()` would skip this job with it.
+fn deploy() -> Job {
Job::default()
+ .name("Deploy")
+ .needs(vec!["build".to_string()])
+ .cond(Expression::new(
+ "${{ !cancelled() && (needs.build.result == 'success' || needs.build.result == 'skipped') }}",
+ ))
.runs_on(runners::Runner::Mid.with_cache_tag(vars::WEB_CI_CACHE_TAG))
.add_env(("CI", "true"))
- .add_step(checkout())
+ .add_step(build_web_app::checkout())
.add_step(steps::mount_web_build_cache_volume())
.add_step(steps::setup_nix())
.add_step(steps::setup_reqs_web("Setup", false))
- .add_step(steps::configure_namespace_sccache(vars::WEB_SCCACHE_NAME))
- .add_step(steps::start_sccache_server())
- .add_step(build())
- .add_step(steps::show_sccache_stats())
+ .add_step(download_dist())
.add_step(install_infra_dependencies())
.add_step(configure_aws_credentials())
.add_step(pulumi_up())
@@ -113,34 +142,15 @@ fn build_deploy() -> Job {
.add_step(steps::teardown_nix())
}
-fn checkout() -> Step<Use> {
- Step::new("Checkout Repo")
+fn download_dist() -> Step<Use> {
+ Step::new("Download dist")
.uses(
"actions",
- "checkout",
- "df4cb1c069e1874edd31b4311f1884172cec0e10",
- ) // v6
- // The pushed commit, not the branch tip: a merge that lands while this
- // run's backend deploys must not ship its frontend against the older
- // backend.
- .add_with(("ref", "${{ github.sha }}"))
-}
-
-/// Build identical across dev/prod up to `MODE` (`just build-<env>`).
-fn build() -> Step<Run> {
- Step::new("Build")
- .run("just build-${{ inputs.environment }}")
- .working_directory(xtask_paths::repo_dir!("apps/web"))
- .add_env(Env::new("VITE_SEGMENT_WRITE_KEY", vars::SEGMENT_WRITE_KEY))
- .add_env(Env::new("VITE_POSTHOG_API_KEY", vars::POSTHOG_API_KEY))
- .add_env(Env::new(
- "VITE_OTEL_EXPORTER_URL",
- "${{ inputs.environment == 'prod' && 'https://macro-prox-prod.macroverse.workers.dev/i/otlp/v1/traces' || 'https://macro-prox-dev.macroverse.workers.dev/i/otlp/v1/traces' }}",
- ))
- .add_env(Env::new(
- "VITE_OTEL_ENV",
- "${{ inputs.environment == 'prod' && 'prod' || 'development' }}",
- ))
+ "download-artifact",
+ "634f93cb2916e3fdff6788551b99b062d0335ce0",
+ ) // v5
+ .add_with(("name", build_web_app::ARTIFACT))
+ .add_with(("path", xtask_paths::runtime_path!("apps/web/dist").as_str()))
}
fn install_infra_dependencies() -> Step<Run> {