Skip to content

feat: cache rocks in build-artifacts workflow#51

Open
javierdelapuente wants to merge 1 commit into
mainfrom
feat/rock-caching
Open

feat: cache rocks in build-artifacts workflow#51
javierdelapuente wants to merge 1 commit into
mainfrom
feat/rock-caching

Conversation

@javierdelapuente
Copy link
Copy Markdown
Collaborator

Summary

Caches built rocks between CI runs to avoid redundant rockcraft pack invocations. Modelled directly on operator-workflows' build.ts caching strategy.

Closes #13

What's cached

Only the partial artifacts.build.yaml manifest (contains the GHCR image: ref), not the .rock file itself — the GHCR image persists across runs with its original tag.

Cache key structure

rock-<name>-<arch>-<hash-of-source-dir>-<YYYY-WNN>
  • hash: SHA-256 over all non-.rock files in the pack-dir (or rockcraft.yaml parent dir), matching operator-workflows' hashFiles() approach.
  • YYYY-WNN (ISO week): explicit weekly rotation — GitHub's 7-day LRU also applies but this is more predictable.
  • No restore-keys fallback — a partial hit would restore a manifest with a stale GHCR image ref built from different source files.

Behaviour

Scenario Result
Cache hit (registry mode) LXD, rockcraft, GHCR login, and rockcraft pack are all skipped; restored manifest is uploaded by the existing unconditional step
Cache miss (registry mode) Build proceeds as before; manifest is saved to cache afterwards
Artifact mode (fork PRs) No caching — GH artifacts are run-scoped; the .rock file is too large to cache efficiently

Changes

.github/workflows/build-artifacts.yml

  • New Compute rock cache metadata step: computes source-dir hash + ISO week, emits cache key.
  • New Restore rock cache step: actions/cache/restore@v4.
  • LXD install, rockcraft install, GHCR login, and main build steps conditionalized on cache miss.
  • New Save rock cache step: actions/cache/save@v4 on cache miss only.

src/opcli/core/artifacts.py

  • artifacts_matrix() now includes rockcraft-yaml and pack-dir fields in rock matrix entries (needed by the workflow to locate the source directory for hash computation).

tests/unit/test_artifacts.py

  • Updated existing matrix test + 2 new tests for the new fields.

Cache built rocks between CI runs to avoid redundant rockcraft pack
invocations. Modelled on operator-workflows' build.ts caching strategy.

What is cached:
- The partial artifacts.build.yaml manifest (contains the GHCR image:
  ref), NOT the .rock file itself — the GHCR image persists across runs
  with its original tag.

Cache key:
  rock-<name>-<arch>-<hash-of-source-dir>-<YYYY-WNN>
where:
- hash covers all non-.rock files in the pack-dir (or rockcraft.yaml
  parent directory), matching operator-workflows' hashFiles() approach.
- YYYY-WNN (ISO week) provides explicit weekly rotation; GitHub's 7-day
  LRU eviction also applies but the weekly key is more predictable.

Behaviour:
- Cache hit: LXD install, rockcraft install, GHCR login and rockcraft
  pack are all skipped; restored manifest is uploaded as-is by the
  existing unconditional 'Upload partial build manifest' step.
- Cache miss: build proceeds as before, then manifest is saved to cache.
- Artifact mode (fork PRs): no caching — GH artifacts are run-scoped
  and the .rock file would be too large to cache efficiently.

opcli changes:
- artifacts_matrix() now includes rockcraft-yaml and pack-dir fields in
  rock matrix entries so the workflow can locate the source directory
  for hash computation.

Closes #13

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rock caching and speed improvements (operator-workflows parity)

1 participant