Skip to content

Harden the CI and update its pins monthly - #60

Merged
dimitrivlachos merged 11 commits into
mainfrom
harden-ci-and-pin-conda
Nov 12, 2026
Merged

dimitrivlachos merged 11 commits into
mainfrom
harden-ci-and-pin-conda

Conversation

@dimitrivlachos

@dimitrivlachos dimitrivlachos commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

This brings dx2 up to the same CI hardening that fast-feedback-service
picked up in #158, #161 and #164. Up until now, every workflow action
has been referenced by a mutable tag such as @v7, and every conda package
except hdf5 and its filter plugins float, so each CI run takes
whatever the action owners and conda-forge happen to be publishing that
day. A tag is a pointer that its owner, or whoever compromises them, can
move; a pinned commit SHA or exact version cannot.

Pinning makes updating a chore, so it is automated. For the actions,
Dependabot proposes one grouped pull request a month, and only for
releases that have been out for at least seven days, which is usually
long enough for a compromised release to be noticed and pulled.
Security advisories bypass both the schedule and the cooldown.

Dependabot can also update conda pins, but it bumps each one to its
latest on its own and ignores the constraints packages place on each
other. Its first run on fast-feedback-service (#162) produced an
environment that broke the build and failed its tests
(tests, image). The conda pins here are
instead kept current by a monthly workflow from #164, which loosens
every pin to a lower bound, lets the conda solver choose the newest set
that installs on both linux-64 and osx-arm64, and opens one pull request
with the result. requirements.txt becomes environment.yml, a full
environment file that names its channel, since the solves read the file
as it is.

Changes

  • Pinned every action to the commit its current major tag points at,
    with the exact release in a trailing comment
    (@3d3c42e... # v7.0.1). No versions change; these are the same pins
    fast-feedback-service uses where the two share an action.
  • Pinned every package in the conda environment exactly, at the
    versions the last green run on main (40922709935) installed on
    both Linux and macOS, so the build is unchanged. ccache moves into
    the environment from its own install step. hdf5 is held on 1.14.*,
    which the monthly update leaves alone, so the move to 2.x can follow
    as its own change.
  • Added a Dependabot config for the actions: monthly, one group, with a
    seven-day cooldown.
  • Added .github/scripts/conda_update.py, adapted from
    fast-feedback-service's conda/update.py. It moves the pins to the
    newest versions that solve together on linux-64 and osx-arm64, the two
    CI platforms, and prints each change as name old -> new. dx2 has one
    environment, and its compiler metapackages already supply clang on
    macOS, so it solves the same file on both.
  • Added the Conda update workflow, which runs on the 4th of each month
    at 06:36 UTC, pushes a conda-update branch, opens or updates the
    pull request, and dispatches the build on it, since a push made with
    the job token starts no workflows.
  • Scoped the workflow token permissions to the jobs that need them. The
    build workflow had no permissions: block and so inherited the
    repository default; it is now read-only. The docs workflow granted
    pages: write and id-token: write to every job, including the build
    on pull requests; those now sit on the deploy job only.
  • Restricted the push trigger to main and added
    workflow_dispatch, as fast-feedback-service did in 05e6e05. A
    branch pushed to this repository with a pull request open used to run
    both workflows twice.

The FetchContent pins for mdspan and googletest, and the docs
requirements, are left as they are. Dependabot has no CMake support, and
the docs packages can follow separately if they are wanted.

@dimitrivlachos dimitrivlachos changed the title Pin the CI actions and conda packages for Dependabot Harden the CI and update its pins monthly Nov 11, 2026
@dimitrivlachos dimitrivlachos self-assigned this Nov 11, 2026
@dimitrivlachos
dimitrivlachos marked this pull request as ready for review November 11, 2026 17:51
@dimitrivlachos
dimitrivlachos merged commit 29460ca into main Nov 12, 2026
5 checks passed
@dimitrivlachos
dimitrivlachos deleted the harden-ci-and-pin-conda branch November 12, 2026 11:35
dimitrivlachos added a commit that referenced this pull request Nov 13, 2026
This is the dx2 side of fast-feedback-service [#169]. Since [#60] every
package in `environment.yml` is pinned exactly and the Conda update
workflow moves the pins once a month, so a `git pull` can leave a local
environment behind without anyone noticing. The build then fails in
ways that do not name the cause; on fast-feedback-service an
environment still on fmt 11.2 against the 12.1 pin gave link errors
between `fmt::v11` symbols and `libfmt.so.12`, which say nothing about
the environment being out of date.

This adds the same configure-time check, which compares the
environment the build uses against `environment.yml` and warns with
every package that does not match, along with the command to update it:

```
CMake Warning at cmake/Modules/CheckCondaPins.cmake:69 (message):
  The conda environment at .../ENV does not match the pins in
  environment.yml:

    fmt 12.2.0, pinned 11.2.0

  Update it with:

    mamba env update -p .../ENV -f .../environment.yml
```

conda records every installed package as
`conda-meta/<name>-<version>-<build>.json`, so the check is a glob per
pin in plain CMake, with no Python and no conda call. The environment
is the one holding the C++ compiler, since that is where the headers
come from. It is only a warning, so building against a different
environment on purpose still works.

### Changes

- Added `cmake/Modules/CheckCondaPins.cmake`, ported from
  fast-feedback-service. The pin file and the environment's
  `conda-meta/history` are configure dependencies, so a pull that moves
  a pin, or an update to the environment, reruns the check on the next
  `ninja` without a manual reconfigure.
- Dropped the macOS handling the original carries. dx2 solves the one
  `environment.yml` on both platforms, so every pin applies on both and
  there is no derived file to suggest.
- Included it alongside the other build-configuration modules, so it
  only runs when dx2 is the top-level project and not when it is pulled
  in with `add_subdirectory`. A compiler from outside a conda
  environment skips the check entirely.

[#169]: DiamondLightSource/fast-feedback-service#169
[#60]: #60
dimitrivlachos added a commit that referenced this pull request Nov 13, 2026
This is the dx2 side of fast-feedback-service [#170]. In [#60] I pinned
every action to a commit SHA, since a tag such as `@v7` can be
repointed by whoever controls the action, as happened with tj-actions
and trivy-action, and a SHA cannot. It did trade neat pointers for
ungainly SHAs, and it still left two gaps: a SHA fixes which commit
runs but not whose repository it comes from, and it only reaches our
own workflow files, so an action that calls other actions internally is
only as pinned as its maintainers make it.

GitHub has now released [workflow dependency lockfiles], which do the
same job as the SHAs and close both gaps, so this PR moves dx2 over to
them. It adds `.github/workflows/actions.lock`, generated by
[`gh actions-lock`] v0.4.1, which records for each action its release
tag, its commit, and the numeric IDs of the account and repository it
belongs to. Once a workflow is in the lockfile, "the locked commit is
what runs when the workflow executes", a commit that is not reachable
from the recorded tag is rejected when the workflow runs. The 8
actions dx2 uses and the one they pull in transitively are all locked.

With the commit held in the lockfile, the neat pointers come back: the
workflows name exact releases (`actions/checkout@v7.0.1`), which is the
form the tool writes and keeps. Dependabot needs no new configuration;
when it bumps an action in a locked workflow, it regenerates the
lockfile entry in the same pull request.

### Changes

- Named every action by its exact release tag instead of its commit
  SHA, and updated the Dependabot header, which described it reading
  the version from the trailing comment. Every locked commit is the SHA
  it replaces, so no action changes version.
- Added the lockfile, generated by `gh actions-lock` and checked with
  `gh actions-lock --verify`, which passes on all three workflows.

After this merges, the lockfile can be made mandatory with an
Actions policy. Under Settings -> Actions -> Policies, create a new
policy, set its enforcement status to Active, target this repository's
workflows, and enable the "Require lockfile" protection. A targeted
workflow that is not in the lockfile is then blocked rather than
resolved live.
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.

1 participant