mirror of
https://github.com/storytold/craft-common-actions.git
synced 2026-11-15 23:12:33 +00:00
ci: preserve dependency cache reuse across root manifest updates (#108)
* ci: preserve dependency cache reuse across root manifest updates * docs: align gate cache overview with profile keys and dispatch opt-in
This commit is contained in:
1 parent
fa5ef18780
commit
2b3fb9dc05
3 files changed
+83
-11
No files matched your search
@@ -81,6 +81,11 @@ on:
|
||||
type: string
|
||||
required: false
|
||||
default: "v1"
|
||||
cache-save-on-dispatch:
|
||||
description: "Allow manually dispatched branch runs to save their branch-scoped dependency cache; pull requests never write"
|
||||
type: boolean
|
||||
required: false
|
||||
default: false
|
||||
timeout-minutes:
|
||||
description: "Timeout of each leg"
|
||||
type: number
|
||||
@@ -197,14 +202,34 @@ jobs:
|
||||
with:
|
||||
tool: ${{ inputs.tools }}
|
||||
|
||||
# Only the default branch writes, so PR caches never evict its entry; a failing gate still
|
||||
# saves. rust-cache hashes only the members' manifests, so the root Cargo.toml goes in the key
|
||||
# or a profile change in a virtual root keeps restoring the old cache.
|
||||
# Root workspace profiles are not among rust-cache's member manifests. Hash only
|
||||
# those profiles here: a dependency/version/comment change must not discard the
|
||||
# fallback cache for every other dependency. rust-cache still hashes the lockfile,
|
||||
# toolchain, member manifests and build environment, and Cargo checks fingerprints.
|
||||
- name: Cache profile key
|
||||
id: cache-profile
|
||||
shell: bash
|
||||
run: |
|
||||
python - <<'PYTHON'
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import tomllib
|
||||
from pathlib import Path
|
||||
manifest = tomllib.loads(Path("Cargo.toml").read_text(encoding="utf-8"))
|
||||
profiles = json.dumps(manifest.get("profile", {}), sort_keys=True, separators=(",", ":"))
|
||||
key = hashlib.sha256(profiles.encode("utf-8")).hexdigest()
|
||||
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
|
||||
output.write(f"key={key}\n")
|
||||
PYTHON
|
||||
|
||||
# Default-branch writes remain the default. Maintainers can explicitly opt manual
|
||||
# branch runs into branch-scoped writes; pull-request runs never save a cache.
|
||||
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
|
||||
with:
|
||||
prefix-key: ${{ inputs.cache-version }}-rust
|
||||
key: ${{ hashFiles('Cargo.toml') }}
|
||||
save-if: ${{ github.event_name != 'pull_request' && github.ref_name == github.event.repository.default_branch }}
|
||||
key: ${{ steps.cache-profile.outputs.key }}
|
||||
save-if: ${{ github.event_name != 'pull_request' && (github.ref_name == github.event.repository.default_branch || (inputs.cache-save-on-dispatch && github.event_name == 'workflow_dispatch')) }}
|
||||
cache-on-failure: true
|
||||
|
||||
- name: Gate
|
||||
|
||||
Reference in new issue
Block a user