8000 fix(libkrun-ci): use patches in cache key by twitchyliquid64 · Pull Request #910 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions .github/actions/setup-libkrun-macos/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,22 @@ runs:
exit 1
fi
script_hash="$(shasum -a 256 scripts/build-libkrun-macos.sh | cut -d' ' -f1)"
# Hash the carried patches (name + content, in apply order) so editing,
# adding, or removing a patch invalidates the build. `shasum` over each
# file emits `<hash> <path>`; sort pins a stable order, then a final
# digest folds them into one value. No patches => digest of empty input,
# still deterministic.
patches_hash="$(find vendor/libkrun/patches -name '*.patch' -type f -exec shasum -a 256 {} + 2>/dev/null | sort | shasum -a 256 | cut -d' ' -f1)"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High setup-libkrun-macos/action.yml:34

When all carried patches are removed, Git deletes the empty vendor/libkrun/patches directory, so find exits nonzero. Because GitHub Actions' default shell uses -e -o pipefail, the patches_hash assignment aborts the step instead of producing the documented "digest of empty input." The build fails on the exact case this change is supposed to support. Consider guarding the directory, e.g. patches_hash="$([ -d vendor/libkrun/patches ] && find vendor/libkrun/patches -name '*.patch' -type f -exec shasum -a 256 {} + | sort | shasum -a 256 | cut -d' ' -f1 || echo -n | shasum -a 256 | cut -d' ' -f1)".

Suggested change
patches_hash="$(find vendor/libkrun/patches -name '*.patch' -type f -exec shasum -a 256 {} + 2>/dev/null | sort | shasum -a 256 | cut -d' ' -f1)"
patches_hash="$([ -d vendor/libkrun/patches ] && find vendor/libkrun/patches -name '*.patch' -type f -exec shasum -a 256 {} + | sort | shasum -a 256 | cut -d' ' -f1 || echo -n | shasum -a 256 | cut -d' ' -f1)"
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @.github/actions/setup-libkrun-macos/action.yml around line 34:

When all carried patches are removed, Git deletes the empty `vendor/libkrun/patches` directory, so `find` exits nonzero. Because GitHub Actions' default shell uses `-e -o pipefail`, the `patches_hash` assignment aborts the step instead of producing the documented "digest of empty input." The build fails on the exact case this change is supposed to support. Consider guarding the directory, e.g. `patches_hash="$([ -d vendor/libkrun/patches ] && find vendor/libkrun/patches -name '*.patch' -type f -exec shasum -a 256 {} + | sort | shasum -a 256 | cut -d' ' -f1 || echo -n | shasum -a 256 | cut -d' ' -f1)"`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Pin the sorting locale for a stable digest.

sort is locale-sensitive, and its ordering feeds the final SHA-256. Different runner locales can therefore produce different patches_hash values for identical patches, causing avoidable cache misses and divergent prefixes. Use LC_ALL=C sort.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/actions/setup-libkrun-macos/action.yml at line 34, Update the
patches_hash computation to invoke locale-independent sorting by setting
LC_ALL=C on the sort command. Preserve the existing file hashing and final
digest pipeline while ensuring identical patch sets produce the same hash across
runner locales.

{
echo "commit=$commit"
# The prefix embeds BOTH build inputs (pinned commit + build-script
# hash) so the persistent mini rebuilds when either changes — the
# same invalidation the actions/cache key gives GitHub-hosted
# runners. Stale sibling prefixes on the mini are inert (nothing
# references them) and may be deleted by hand.
echo "prefix=$HOME/.cache/minimal-ci/libkrun/$commit-${script_hash:0:12}"
# The prefix embeds ALL build inputs (pinned commit + build-script
# hash + patches hash) so the persistent mini rebuilds when any
# changes — the same invalidation the actions/cache key gives
# GitHub-hosted runners. Stale sibling prefixes on the mini are inert
# (nothing references them) and may be deleted by hand.
echo "prefix=$HOME/.cache/minimal-ci/libkrun/$commit-${script_hash:0:12}-${patches_hash:0:12}"
echo "script_hash=$script_hash"
echo "patches_hash=$patches_hash"
} >> "$GITHUB_OUTPUT"
- name: Cache built libkrun (GitHub-hosted)
# The mini needs no cache action: the input-keyed prefix under $HOME
Expand All @@ -43,7 +50,7 @@ runs:
uses: actions/cache@v6
with:
path: ~/.cache/minimal-ci/libkrun
key: libkrun-macos-${{ runner.arch }}-${{ steps.pin.outputs.commit }}-${{ steps.pin.outputs.script_hash }}
key: libkrun-macos-${{ runner.arch }}-${{ steps.pin.outputs.commit }}-${{ steps.pin.outputs.script_hash }}-${{ steps.pin.outputs.patches_hash }}
- name: Build libkrun from source (on miss)
shell: bash
env:
Expand Down
0