diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d63e1b7e..37079da8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -428,10 +428,20 @@ jobs: cache-to: type=gha,mode=max,scope=app # The renderer is rebuilt only when its inputs change, so its digest (and the running renderers) stay put # through deploys that only touch the app. Rebuilding an unchanged renderer would give a new digest and roll - # the renderers mid-build for nothing. + # the renderers mid-build for nothing. Its inputs: the workspace crates it's built from, the toolchain, the + # workspace's build settings (Cargo.toml without the version, which every CLI release bumps), and the exact + # crates it's built from (its dependency tree, without the workspace's own crates, whose sources are hashed + # here already). The whole Cargo.lock also holds app/'s and the CLI's dependencies, which never reach it. + - run: rustup show active-toolchain || rustup toolchain install - id: renderer_inputs run: | - hash=$(git ls-files -s docker/renderer.Dockerfile docker/renderer.version crates/visualci-core crates/visualci-renderer Cargo.toml Cargo.lock rust-toolchain.toml | sha256sum | cut -c1-24) + set -euo pipefail + tree=$(cargo tree --locked -p visualci-renderer -e normal,build --prefix none --format '{p}' | sort -u) + # The workspace's own crates it uses (visualci-core, snapshot-diff, itself): their sources, by path. + paths=$(echo "$tree" | sed -n 's|.* (\(/.*\))$|\1|p' | sed "s|^$PWD/||") + deps=$(echo "$tree" | grep -v ' (/') + # shellcheck disable=SC2086 + hash=$( { git ls-files -s docker/renderer.Dockerfile docker/renderer.version rust-toolchain.toml $paths; grep -v '^version = ' Cargo.toml; echo "$deps"; } | sha256sum | cut -c1-24) echo "tag=ghcr.io/docspring/visualci-renderer:inputs-$hash" >>"$GITHUB_OUTPUT" if digest=$(docker buildx imagetools inspect "ghcr.io/docspring/visualci-renderer:inputs-$hash" --format '{{json .Manifest}}' 2>/dev/null | python3 -c 'import json,sys; print(json.load(sys.stdin)["digest"])'); then echo "existing=$digest" >>"$GITHUB_OUTPUT"