Persist WSL source and build caches outside Woodpecker temporary home
ci/woodpecker/push/woodpecker Pipeline was canceled

This commit is contained in:
geruipu committed 2026-10-05 17:00:15 +08:00
1 parent f387e280a2
commit 558e3b2454
1 file changed
+23 -4
+23 -4
View File
@@ -1,10 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$SCRIPT_ROOT"
TOOLCHAIN_IMAGE="ghcr.io/greepar/staticlink.avalonia-zig@sha256:a88b5ea9f76f659978cda36dda06233d7fdc9121046eedf945044fc908d24b85"
export CROSS_RID=linux-x64
RESULTS="${HOME}/staticlink-ci-artifacts/${CI_REPO_NAME:-StaticLink.Avalonia}/${CI_COMMIT_BRANCH:?}/${CI_PIPELINE_NUMBER:?}"
AGENT_HOME="$(getent passwd "$(id -u)" | cut -d: -f6)"
if [ -z "$AGENT_HOME" ] || [ "$AGENT_HOME" = / ]; then
echo "Cannot find a persistent home directory for the agent user" >&2
exit 1
fi
CACHE_KEY="$(printf '%s\n' "${CI_REPO_OWNER:?}/${CI_REPO_NAME:?}" "${CI_COMMIT_BRANCH:?}" "$TOOLCHAIN_IMAGE" "$CROSS_RID" | sha256sum | cut -c1-24)"
CACHE_ROOT="$AGENT_HOME/.cache/staticlink-woodpecker/$CACHE_KEY"
RESULTS="$AGENT_HOME/staticlink-ci-artifacts/${CI_REPO_OWNER}/${CI_REPO_NAME}/${CI_COMMIT_BRANCH}/${CI_PIPELINE_NUMBER:?}"
mkdir -p "$CACHE_ROOT"
exec 9>"$CACHE_ROOT/build.lock"
echo "Waiting for exclusive access to persistent cache: $CACHE_ROOT"
flock 9
if [ ! -d "$CACHE_ROOT/source/.git" ]; then
git clone --no-hardlinks "$SCRIPT_ROOT" "$CACHE_ROOT/source"
fi
git -C "$CACHE_ROOT/source" fetch --depth=1 "$SCRIPT_ROOT" HEAD
git -C "$CACHE_ROOT/source" checkout --detach FETCH_HEAD
cd "$CACHE_ROOT/source"
cp build/linux-toolchain/sources.lock.json build/linux-toolchain/release.lock.json
mkdir -p "$RESULTS/environment"
df -h .
free -h
@@ -21,7 +38,9 @@ if [ "$AVAILABLE_KB" -lt 41943040 ]; then
fi
echo "Persistent test results: $RESULTS"
exec > >(tee "$RESULTS/build.log") 2>&1
trap 'result=$?; trap - EXIT; mkdir -p "$RESULTS/native"; if [ -d External/NativeStatic/linux-x64/native ]; then cp -a External/NativeStatic/linux-x64/native/. "$RESULTS/native/"; fi; printf "%s\n" "$result" > "$RESULTS/exit-code"; echo "Results retained at $RESULTS"; exit "$result"' EXIT
trap 'result=$?; trap - EXIT; if [ "$result" -eq 0 ] && [ -d External/NativeStatic/linux-x64/native ]; then mkdir -p "$RESULTS/native"; cp -a External/NativeStatic/linux-x64/native/. "$RESULTS/native/"; fi; printf "%s\n" "$result" > "$RESULTS/exit-code"; echo "Results retained at $RESULTS"; exit "$result"' EXIT
git rev-parse HEAD > "$RESULTS/commit"
printf '%s\n' "$TOOLCHAIN_IMAGE" > "$RESULTS/toolchain-image"
docker pull "$TOOLCHAIN_IMAGE"
docker run --rm --user "$(id -u):$(id -g)" \
-e HOME=/tmp -e DOTNET_CLI_HOME=/tmp -e ZIG_GLOBAL_CACHE_DIR=/tmp/zig-cache \
@@ -35,7 +54,7 @@ docker run --rm --user "$(id -u):$(id -g)" \
-e ZIG_GLOBAL_CACHE_DIR=/src/External/NativeStatic/.work/zig-global \
-v "$PWD:/src" -w /src --entrypoint bash "$TOOLCHAIN_IMAGE" -c '
set -euo pipefail
export SOURCE_LOCK=/src/build/linux-toolchain/sources.lock.json
export SOURCE_LOCK=/src/build/linux-toolchain/release.lock.json
source scripts/prepare-cross-sources.sh
python3 build/linux-toolchain/build-cross.py \
--target "$CROSS_RID" --sources-manifest "$WORK_DIR/cross-sources.json" \