Skip to content

Push Spack packages to the build cache as they are built - #4716

Draft
garth-wells wants to merge 12 commits into
mainfrom
ci/spack-autopush
Draft

garth-wells wants to merge 12 commits into
mainfrom
ci/spack-autopush

Conversation

@garth-wells

@garth-wells garth-wells commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Spack CI pushed packages to ghcr.io/fenics/spack-buildcache only after spack install finished. The push steps had if: !cancelled(), so a run that was cancelled or timed out lost everything it had built. On pull requests this happens on every new commit, which makes cold-cache rebuilds (e.g. after a packages_ref bump) slow to warm the cache.

This enables Spack's mirror autopush in ci.yml and ci-spack.yml, so each package is pushed as soon as it is built from source.

Changes

  • Autopush is turned on with spack mirror set --autopush local-buildcache, only when the run can push. A CACHE_PUSH env flag, computed once per workflow, excludes pull requests from forks, which have a read-only token.
  • Push steps removed. Their remaining jobs were:
    • Copying in packages from Spack's public github-actions-buildcache. Not needed: in the latest run of each workflow, 0 of the ~175 cache-installed packages came from the public cache. That mirror is now turned off (buildcache: false in setup-spack).
    • Attaching a base image. Not used by Spack installs.
    • Updating the index. Now done by a new update-buildcache-index job in each workflow that runs once per workflow run, after the matrix legs:
      • Each leg checks whether it built anything from source that autopush sends, with a short inline spack python -c check. It looks for the .spack/binary_distribution file that cache installs carry, and applies the mirror's push filters. A leg that built something sets the job output built_from_source=true. Legs only ever set true, so one that built nothing cannot overwrite it.
      • The job rebuilds the index only if that output is true.
      • The check and the job run with always(), so a cancelled run still indexes what autopush pushed before the cancellation. A job killed by its timeout does not reach the check.
      • Both workflows' jobs use the concurrency group spack-buildcache-index. Group names are repository-wide, so rebuilds are serialised across the two workflows. Rebuilds running at the same time could overwrite each other's updates, because each one lists the cache and uploads a whole index.
      • The rebuild scans the whole registry, so packages pushed by an earlier run whose index update did not happen get indexed too.
  • Push exclusions live in the env files:
    • dev_path=* and ^dev_path=* in gh-actions-env-test.yml. Develop specs are never reused, and the old flow uploaded several of them.
    • intel-oneapi-compilers in gh-actions-rh.yml. buildcache push skips non-redistributable packages, but autopush ignores redistribute, so without this it would upload the Intel compilers to the public registry.

Trade-offs

  • A failed upload now fails the build, rather than a later push step.
  • Packages pushed by autopush have no base image.
  • On rebuilds, each upload adds to the build's critical path.

Testing

  • The config and filters were checked against Spack v1.2.2 locally: the autopush flag and push-only filters resolve as intended.
  • The built-from-source check returned true after a source build and false when all installs carried the cache marker. This was tested as a standalone script, before it was moved inline; the inline form was checked only for parsing and Python syntax.
  • actionlint reported nothing new before the index job and check were moved inline. It has not been re-run since.
  • Not yet run in CI. A run where something is built from source is needed to see autopush uploads and the index job. A cancelled run is needed to confirm the index job still gets the build job's output.

AI assistance: I used Claude Code (Claude Opus 5.5) to draft parts of this PR. I reviewed, edited, tested, and take responsibility for the final contribution.

🤖 Generated with Claude Code

garth-wells and others added 8 commits November 22, 2026 12:03
Enable autopush on the build cache mirror so each package built from
source is pushed straight after it installs. A run that is cancelled
(e.g. superseded on a pull request) or times out keeps what it built,
rather than losing everything before the post-install push.

The DOLFINx packages built at the current commit are excluded from
pushes, as they are never reused. The existing push steps are kept:
they copy in packages taken from Spack's public cache, attach the
base image and update the index. Autopush, like the RHEL workflow's
push step, is skipped for pull requests from forks, which have a
read-only token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With autopush, every package built from source is already in the
cache, so the push steps only rebuilt the index. Recent runs took no
packages from Spack's public cache, so there is nothing to copy in.
Replace the push steps with 'buildcache update-index'.

Exclude intel-oneapi-compilers from pushes: autopush ignores a
package's 'redistribute' setting, which 'buildcache push' honoured, so
it would otherwise be uploaded to the public cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rebuilding the index scans the whole cache, and running it on every
leg of every run was a regression from the push steps it replaced,
which rebuilt it only after an upload. Check whether any pushable
package was built from source first, and move the step to the end of
the ci.yml job so the tests do not wait for it.

Move the push exclusions into the environment files next to the
mirror definition. Exclude develop specs and their dependents with
'dev_path=*' rather than naming two of them: no develop spec is
reused, so none is worth pushing.

Compute the fork pull request check once per workflow, move 'spack
debug report' out of the cache step so fork runs keep it, and fix a
stale comment on fail-fast.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Legs rebuilding the index concurrently could overwrite each other's
updates: each lists the cache and uploads a whole index, so the last
upload wins even if its listing is older. Legs now upload a marker when
they pushed something, and a follow-up job rebuilds the index once,
in a concurrency group shared by both Spack workflows.

A failure of built_from_source.py now fails its step, instead of being
hidden by the command substitution in a test. Add the file header.

Turn off Spack's public build cache in setup-spack: recent runs took
none of their packages from it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@garth-wells garth-wells added the ci Continuous Integration label Nov 24, 2026
garth-wells and others added 4 commits November 24, 2026 10:19
Move the reusable index workflow into each Spack workflow as a job,
and run the built-from-source check via 'spack python -c', removing
two files. Concurrency groups are repository-wide, so index rebuilds
still serialise across both workflows.

Run the check and the index job with always() rather than
!cancelled(), so packages autopush sent before a cancellation are
indexed and reused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
'spack python -c' compiles its argument as a single interactive
statement, so the multi-statement check failed with a SyntaxError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Lets a maintainer force an index rebuild, e.g. after a failed or
skipped update, by running the workflow by hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The OCI index rebuild fetches every package's manifest and config.
That is network-bound, but Spack sizes its pool to the CPU count (4
on a standard runner): a full rebuild took 34.5 min. Use 32 workers,
past which ghcr.io throughput falls off, and raise the connection
timeout from 10 s to 60 s, since one fetch that exhausts its retries
aborts the whole rebuild.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continuous Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant