From d8cc0c70f1200888ab4a0bcb043ea656f1e17fd9 Mon Sep 17 00:00:00 2001 From: geoknee Date: Thu, 8 Oct 2026 21:27:45 +0100 Subject: [PATCH] fix: key melange cache by cargo profile The melange cache key hashed only the lockfiles, so caches saved by default-branch maxperf builds were restored by fast-build PR builds as an exact hit. Nothing in a maxperf target/ is reusable under fast-build, so PRs paid the multi-GB restore and then recompiled every crate (2002 crates on optimism's op-stack-rust leg). Include the cargo profile in both the key and the restore-keys prefix, terminated with '.' so one profile's prefix never matches another's. Co-Authored-By: Claude Opus 5.5 (1M context) --- .github/workflows/melange-build.yaml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/melange-build.yaml b/.github/workflows/melange-build.yaml index 228d507..2a902d9 100644 --- a/.github/workflows/melange-build.yaml +++ b/.github/workflows/melange-build.yaml @@ -220,9 +220,17 @@ jobs: steps.cache-policy.outputs.restore == 'true' || steps.cache-policy.outputs.save == 'true' id: cache-key + env: + CARGO_PROFILE: ${{ inputs.cargo-profile }} run: | set -euo pipefail - key="melange-v2-${{ inputs.stack }}-${{ inputs.arch }}" + # Builds under different cargo profiles share no target/ artifacts, so + # a cache saved by one profile is dead weight for another. The '.' + # terminator cannot appear in a cargo profile name, so the restore + # prefix for one profile never matches another it is a prefix of + # (release vs release-perf). + prefix="melange-v2-${{ inputs.stack }}-${{ inputs.arch }}-${CARGO_PROFILE:-none}." + key="$prefix" files="${{ inputs.cache-key-files }}" if [ -n "$files" ]; then IFS=',' read -ra paths <<< "$files" @@ -238,9 +246,10 @@ jobs: hash_inputs+=("$path") done if [ "${#hash_inputs[@]}" -gt 0 ]; then - key="${key}-$(sha256sum "${hash_inputs[@]}" | sha256sum | cut -d' ' -f1)" + key="${key}$(sha256sum "${hash_inputs[@]}" | sha256sum | cut -d' ' -f1)" fi fi + echo "prefix=$prefix" >> "$GITHUB_OUTPUT" echo "key=$key" >> "$GITHUB_OUTPUT" - name: Restore melange cache @@ -251,7 +260,7 @@ jobs: path: melange-cache key: ${{ steps.cache-key.outputs.key }} restore-keys: | - melange-v2-${{ inputs.stack }}-${{ inputs.arch }}- + ${{ steps.cache-key.outputs.prefix }} - name: Report restored cache if: steps.cache-policy.outputs.restore == 'true'