#!/usr/bin/env bash # Run a job's cargo phases one after another inside ONE build slot, and name the phase that broke. # # scripts/ci/cargo-phases.sh "::" ["::"...] # # WHY ONE STEP. Since 2026-09-27 a job's cargo work runs inside a single # `scripts/ci/build-slot.sh run`, because the slot's lease has to be held from # the first cargo to the last: the corruption the per-branch target directory # answered (#404) was a neighbour writing the shared directory BETWEEN two steps # of one job, and a lease that ended with each step would open that window # again. A Forgejo step is one process, so one lease means one step. # # WHAT IS KEPT FROM THE OLD SHAPE. A red bar used to name the step that broke # ("rust: unit tests", "rust: the client build"). This does the same inside the # one step: every phase is a `::group::` in the log, and the first failing phase # is announced as `::error:: failed (exit N)` — the line the run page # shows — and nothing after it runs, exactly as a failed step stopped the steps # after it. # # Each argument is `::`; the command is run by `bash -c` from # `crates/` (the cargo workspace), with the environment `build-slot.sh` set up: # CARGO_TARGET_DIR under the slot, COTTON_CARGO_LOCK_HELD for the retry wrapper. # # Guard: `scripts/__tests__/cargo-phases.test.ts`. set -uo pipefail if [ $# -lt 1 ]; then echo "usage: cargo-phases.sh \"::\" ..." >&2 exit 2 fi for spec in "$@"; do case "$spec" in *::*) [ -n "${spec%%::*}" ] && [ -n "${spec#*::}" ] || { echo "cargo-phases: '$spec' needs a name and a command around '::'" >&2; exit 2; } ;; *) echo "cargo-phases: '$spec' is not '::'" >&2; exit 2 ;; esac done WORKSPACE="${COTTON_CARGO_WORKSPACE:-crates}" cd "$WORKSPACE" || { echo "cargo-phases: no '$WORKSPACE' directory under $(pwd)" >&2; exit 1; } n=0 for spec in "$@"; do n=$(( n + 1 )) name="${spec%%::*}" command="${spec#*::}" echo "::group::$name" echo "[cargo-phases] $(date +%H:%M:%S) phase $n of $#: $name" echo "[cargo-phases] $ $command" started=$(date +%s) bash -c "$command" status=$? took=$(( $(date +%s) - started )) echo "::endgroup::" if [ "$status" -ne 0 ]; then echo "::error::$name failed (exit $status) after $(( took / 60 ))m$(( took % 60 ))s — the phases after it did not run" exit "$status" fi echo "[cargo-phases] $name passed in $(( took / 60 ))m$(( took % 60 ))s" done