Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CI Scripts

The project has pipelines set up to run at regular points in the development cycle. These are all run via the ci.py script.

Help is available from the ci script
$ ci.py --help
usage: ci [-h] [--deploy-dir DEPLOY_DIR]
          {check,build,deploy,versions,docs,clean-nightly} ...

Amygdala CI runner

positional arguments:
  {check,build,deploy,versions,docs,clean-nightly}
    check               Lint, format, test etc
    build               Build and save artifacts
    deploy              Deploy built products
    versions            List versions of tools being used
    docs                Build and publish the documentation book
    clean-nightly       Remove old nightly releases from deployment directory

options:
  -h, --help            show this help message and exit
  --deploy-dir DEPLOY_DIR
                        Directory where releases should be deployed

CI tasks

Check

Check that the code passes all required checks

$ ci.py check --help
usage: ci check [-h]

options:
  -h, --help  show this help message and exit

This checks that:

  • the versions make sense

    A release version of either gda or amygdala cannot depend on a pre-release version of amygdala-api. In practice, amygdala-api should be kept on release versions as each change should be usable in its own right and not tied into application changes.

  • the versions don't conflict with previously released versions.

    A version cannot match a previously released version, that is a new commit to the project cannot be marked as a release if that version has already been deployed to the filesystem.

    If a crate is marked as a pre-release version the version it is previewing (eg 1.2.0 for 1.2.0-dev) must not already have been released.

    Additionally, the previous version must have been release. Eg, if a crate is versioned as 1.2.3, version 1.2.2 must have already been published. This prevents versions being skipped. If a major or minor version is bumped, the next number in the version must be 0, eg, going from 1.2.3 to 1.3.0 is fine whereas 1.2.3 to 1.3.3 is not.

  • the code is well formatted

    This runs cargo +nightly fmt --check and enforces the code style standards in all rust code. Running this locally (without the --check flag) will fix any issues.

  • the code compiles and the tests pass

    The workspace is compiled (with the dev profile for speed) and the tests are run. As part of this clippy is run to ensure any denied lints are caught. Warnings will be logged but do not prevent the build continuing. These should be fixed wherever possible.

Build

Build the workspace in release mode and store the build products as artifacts.

$ ci.py build --help
usage: ci build [-h]

options:
  -h, --help  show this help message and exit

This will also include any resources listed in the [package.includes] section of each crates Cargo.toml. This enables scripts to be deployed automatically without having to be handled explicitly anywhere.

The artifacts are copied to the `artifacts` directory into a subdirectory named after the project.

At time of writing, this creates a directory similar to

artifacts
├── amygdala
│  └── amygdala
└── gda
   ├── gda
   ├── gda-gui
   └── gda-logpanel

Deploy

The deploy subcommands deploys the build applications to various locations

$ ci.py deploy --help
usage: ci deploy [-h] {apps,registry} ...

positional arguments:
  {apps,registry}
    apps           Deploy to apps directory
    registry       Deploy to CI registry

options:
  -h, --help       show this help message and exit

Apps

Applications at Diamond are made available via the module system. This requires the executables to be copied to a specific location (set via $DEPLOY_DIR or --deploy-dir to the main ci command) and a module file describing how the application be made available to be written to a directory included on users' $MODULEPATH (set via $MODULE_DIR or --module-dir).

Registry

Release versions of the applications (i.e. not the nightly builds) are published to the gitlab 'generic package registry' for the project. These builds are kept indefinitely and can be linked from releases.

The tags and releases are not yet created as part of the CI and need to be managed manually for now.

Documentation

The docs subcommand builds and deploys the documentation (this book) to alfred.

$ ci.py docs --help
usage: ci docs [-h] {build,publish} ...

positional arguments:
  {build,publish}
    build          Build the documentation site
    publish        Publish the documentation

options:
  -h, --help       show this help message and exit

The documentation site is only a single version so will only reflect the latest version of the repository. For this reason docs should be make note of features that require specific versions of the applications and not immediately remove docs when features are removed (instead marking them as deprecated/unsupported).

Clean Nightly

As nightly builds have a fairly short useful lifetime, old versions should be deleted regularly. The exact number to keep is not fixed as if many updates are made in a short time frame, it can be useful to retain more past versions to help compare new features.

The clean-nightly command deletes nightly builds from the app directory. It has three options to control which builds are deleted. A minimum and maximum count. The newest builds up the minimum count will always be kept however old they are. Any builds over the maximum count will always be deleted however new they are. Between the two limits, anything older than the maximum age will be deleted.

$ ci.py clean-nightly --help
usage: ci clean-nightly [-h] [--min-builds MIN_BUILDS]
                        [--max-builds MAX_BUILDS] [--max-age MAX_AGE]

options:
  -h, --help            show this help message and exit
  --min-builds MIN_BUILDS, -n MIN_BUILDS
                        Minimum number of builds to keep - these will be kept
                        even if older than threshold
  --max-builds MAX_BUILDS, -x MAX_BUILDS
                        Maximum number of builds to keep - beyond this, builds
                        will be deleted even if newer than threshold
  --max-age MAX_AGE, -a MAX_AGE
                        Age (in days) of oldest builds to keep

Versions

This subcommand does nothing other than list the versions of all the applications in the environment being used to help debugging any discrepancies between jobs run in CI and across developer environments.

$ ci.py versions --help
usage: ci versions [-h]

options:
  -h, --help  show this help message and exit

Pipelines and when they run

Merge Requests

For every merge request to the gitlab repo (and every commit to an existing MR) the check ci task is run. This must complete successfully for the MR to be mergable.

Every Commit to main

For every commit to main (i.e. every MR that gets merged), the check, build, deploy and docs commands are run, updating the nightly module version, the latest module version (for release versions) and the documentation site with the latest versions.

On Request

As the check stage of the CI does not store any artifacts, it is not possible to download builds of merge requests for testing. To make this feasible without having to build locally, it is possible to trigger a build for a merge request.

From the gitlab repo page, go to Build > Pipelines > Run Pipeline, then select the branch backing the merge request from the branch drop down and select Run Pipeline. This will just run the build stage and keep the built artifacts for 7 days. These can be downloaded via Build > Artifacts and selecting the relevant file from the browse menu next to the pipeline once it completes.

Schedule

Scheduled CI runs only run the clean-nightly job to remove any old nightly builds. This is currently configured to run weekly.

Gitlab specific features

Section headers/footers

The functions in the ci script and import utilities are wrapped in section headers. These are managed by the section decorator and allow the individual stages in the pipelines to be collapsed in the pipeline log viewer in gitlab. Due to the way they are designed, the scripts still work when run from the terminal but may produce surprising results when redirected to file, eg running ./ci.py versions gives

$ ci.py versions
section_start:1791983609:run_versions-0[collapsed=true]
Version Report
$ /usr/bin/python3 --version
Python 3.12.11
$ cargo --version
cargo 1.90.0 (840b83a10 2025-07-30)
$ rustc --version
rustc 1.90.0 (1159e78c4 2025-09-14)
$ mdbook --version
mdbook v0.4.52
section_end:1791983609:run_versions-0


Gitlab package repository

As part of the deploy stage, if the version of either application is a release version, it is published to the gitlab package repository for the project. This allows the built products to be linked to releases and made downloadable in a way that will not expire.

This uses several environment variables defined by gitlab

  • CI_API_V4_API The root api address for the gitlab instance
  • CI_JOB_TOKEN An authentication token that allows the job to publish to the repository.
  • CI_PROJECT_ID A unique ID for the project within gitlab used to identify the package repository.

For details on publishing to the package repository, see gitlab documentation. The generic package repository is used as gitlab currently doesn't support rust crates.