#!/usr/bin/env bash set -euo pipefail # Each runner slot has its own root and runs one job at a time. Namespace persistent build # state by workflow file and job, without the ref: same-repository PRs and main share one warm # cache instead of each PR starting cold and filling the runner disk. Fork PRs never reach these # runners, and release builds use their own workflow scope, so PR code cannot reach what ships. scope=$(printf '%s\n' "$GITHUB_REPOSITORY_ID" "${GITHUB_WORKFLOW_REF%@*}" "$GITHUB_JOB" | sha256sum | cut -c1-20) cache="${CI_CACHE_ROOT:?}/$scope" mkdir -p "$cache" touch "$cache" case "$1" in raw) mkdir -p "$cache/target" "$cache/cargo" "$cache/rustup" { echo "CARGO_TARGET_DIR=$cache/target" echo "CARGO_HOME=$cache/cargo" echo "RUSTUP_HOME=$cache/rustup" echo "npm_config_store_dir=$cache/pnpm-store" } >> "$GITHUB_ENV" echo "$cache/cargo/bin" >> "$GITHUB_PATH" ;; docker) export DOCKER_CONFIG DOCKER_CONFIG=$(mktemp -d "${RUNNER_TEMP:?}/incus-docker.XXXXXX") docker buildx create --name incus --driver remote "${CI_BUILDKIT_ENDPOINT:?}" >/dev/null { echo "DOCKER_CONFIG=$DOCKER_CONFIG" echo "BUILDX_BUILDER=incus" echo "CI_BUILD_SCOPE=$scope-${CI_SLOT:?}" echo "CARGO_BUILD_JOBS=${CARGO_BUILD_JOBS:?}" } >> "$GITHUB_ENV" ;; *) exit 2 ;; esac