This repository contains GitHub actions for common workflows, such as interacting with conda packages, linting, and branch management.
These actions are designed to be reusable across different neutron science projects.
Some actions assume you have already built a .conda package. When using a local package artifact, place it in a conda-style channel directory (see conda-index).
Conda package actions:
- pkg-install: Create a micromamba environment and install a conda package into it.
- pkg-verify: Verify an already-installed conda package by importing it in Python and checking that the conda and Python versions match.
- pkg-remove: Clean up old conda packages from Anaconda Cloud.
- publish: Publish a conda package to Anaconda Cloud.
Other actions:
- branch-mapper: Map GitHub refs to standard environment names for use in CI workflows.
- grype: Run an Anchore Grype vulnerability scan and upload the SARIF results to GitHub Security.
GitHub action to create a micromamba environment, optionally index a local conda channel, and install a conda package.
When local-channel is set, the package is installed from that channel only (<local-channel>::<package-name>). If the local package can't be installed, for example because its dependencies are missing from the listed channels or conflict with python-version, the install step fails. Other dependencies still resolve from all listed channels.
Full list of available inputs in pkg-install/action.yml.
Inputs:
| Input | Description | Required | Default |
|---|---|---|---|
package-name |
Name of the conda package to install | Yes | - |
local-channel |
Path to a local conda channel containing the package | No | - |
python-version |
Python version to install into the test environment (for example 3.10) |
No | - |
extra-channels |
Additional conda channels to use during installation | No | - |
post-cleanup |
Micromamba cleanup mode passed to setup-micromamba |
No | shell-init |
Outputs:
| Output | Description |
|---|---|
conda-env |
Name of the created conda environment |
conda-install-dir |
Filesystem path of the created env |
Example:
jobs:
pkg-install:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
steps:
- name: Download conda package artifact
uses: actions/download-artifact@main
with:
name: artifact-conda-package
path: /tmp/local-channel/linux-64
- name: Install Conda Package
id: install
uses: neutrons/gh-actions/pkg-install@main
with:
local-channel: /tmp/local-channel
package-name: ${{ env.PKG_NAME }}
python-version: "3.11"
extra-channels: mantid neutrons pyoncatGitHub action to verify a conda package that is already installed in a conda environment. The action imports the package in Python and ensures that the version reported by conda and Python match.
Full list of available inputs in pkg-verify/action.yaml.
Inputs:
| Input | Description | Required | Default |
|---|---|---|---|
package-name |
Name of the conda package | Yes | - |
module-name |
Name of the Python module to import (if different from package name) | No | - |
conda-env-name |
Name of the conda environment where the package is already installed | Yes | - |
extra-commands |
Additional shell commands to run during verification (newline-separated) | No | - |
Example usage in a GitHub workflow:
jobs:
# First, build your conda package and upload it as an artifact:
build:
runs-on: ubuntu-latest
steps:
- name: Build conda package
run: |
# steps to build your .conda package
- name: Upload conda package as artifact
uses: actions/upload-artifact@main
with:
name: artifact-conda-package
path: ${{ env.PKG_NAME }}-*.conda
# Then install and verify the conda package:
pkg-verify:
needs: build
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
steps:
- name: Download conda package artifact
uses: actions/download-artifact@main
with:
name: artifact-conda-package
path: /tmp/local-channel/linux-64
- name: Install Conda Package
id: install
uses: neutrons/gh-actions/pkg-install@main
with:
local-channel: /tmp/local-channel
package-name: ${{ env.PKG_NAME }}
extra-channels: mantid neutrons pyoncat
- name: Verify Conda Package
uses: neutrons/gh-actions/pkg-verify@main
with:
package-name: ${{ env.PKG_NAME }}
conda-env-name: ${{ steps.install.outputs.conda-env }}GitHub action to remove old packages of a specific label from anaconda.org, keeping the N most recent versions.
Full list of available inputs in pkg-remove/action.yaml.
Inputs:
| Input | Description | Required | Default |
|---|---|---|---|
anaconda-token |
Anaconda.org API token | Yes | - |
organization |
Anaconda.org organization or user name | Yes | - |
package-name |
Name of the conda package to clean up | Yes | - |
label |
Label to target for cleanup (e.g., dev, nightly, rc) |
No | dev |
keep |
Number of most recent package versions to keep | No | 5 |
dry-run |
If true, only print what would be deleted without actually deleting |
No | false |
Outputs:
| Output | |
|---|---|
num-removed |
Number of files that would be deleted |
Example:
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Remove old dev packages
uses: neutrons/gh-actions/pkg-remove@main
with:
anaconda-token: ${{ secrets.ANACONDA_TOKEN }}
organization: neutrons
package-name: my-package
label: dev
keep: 5GitHub action to publish a pre-built conda package to Anaconda Cloud.
This action assumes that:
- The package has already been built and is available at the path given by
package-path - Either
anaconda-clientis available inPATH, orpixiis available so the action can run or installanaconda-client
If label is not provided, the action will attempt to determine it from github-ref:
- If the ref is tagged
refs/tags/v*rc*, the package will be published to therclabel - If the ref is tagged
refs/tags/v*, the package will be published to themainlabel - If the ref is tagged
refs/heads/next, the package will be published to thedevlabel - If the label cannot be determined from the ref, the action will fail
Full list of available inputs in publish/action.yaml.
Inputs:
| Input | Description | Required | Default |
|---|---|---|---|
anaconda-token |
Anaconda.org API token | Yes | - |
organization |
Anaconda.org organization or user name | Yes | - |
package-path |
Path to the conda package to publish | Yes | - |
github-ref |
GitHub ref (for example refs/tags/v1.0.0) used when inferring the label |
No | github.ref |
label |
Label to apply to the package (e.g., main, dev, nightly, rc) |
No | inferred from github-ref |
force |
If true, overwrite existing package with the same version |
No | false |
dry-run |
If true, print the upload command and skip publishing |
No | false |
Example:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main`
- uses: prefix-dev/setup-pixi@main
- name: Build package
run: |
# steps to build your .conda package, for example:
pixi build
- name: Publish package to Anaconda Cloud
uses: neutrons/gh-actions/publish@main
with:
anaconda-token: ${{ secrets.ANACONDA_TOKEN }}
organization: neutrons
package-path: my-package-*.condaGitHub action to map GitHub refs to standard environment names for use in CI workflows.
Full list of available inputs in branch-mapper/action.yaml.
Inputs:
| Input | Description | Required | Default |
|---|---|---|---|
prefix |
Prefix to add to the mapped branch name (e.g. my-pkg) |
Yes | - |
suffix-release |
Suffix for releases | No | None |
suffix-release-candidate |
Suffix for release candidates | No | -qa |
suffix-default |
Suffix for all other versions | No | -dev |
reference |
GitHub ref to map (e.g. github.ref) - used for testing |
No | github.ref |
Outputs:
| Output | Description |
|---|---|
name |
Mapped label (e.g. my-pkg, my-pkg-qa, my-pkg-dev) |
Example:
jobs:
deploy-software:
runs-on: ubuntu-latest
steps:
- name: Determine deploy environment
uses: neutrons/gh-actions/branch-mapper@main
id: deploy-name
with:
prefix: super-awesome-software
- name: Trigger deployment
uses: eic/trigger-gitlab-ci@v3
id: trigger
with:
project_id: 12345
token: ${{ secrets.TOKEN }}
variables: |
CONDA_ENV="${{ steps.deploy-name.outputs.name }}"
- name: Annotate commit
uses: peter-evans/commit-comment@v4
with:
body: |
GitLab pipeline for ${{ steps.deployname.outputs.name }} has been submitted for this commit: ${{ steps.trigger.outputs.web_url }}GitHub action to run an Anchore Grype vulnerability scan on a directory and upload the SARIF results to GitHub Security.
Full list of available inputs in grype/action.yml.
Inputs:
| Input | Description | Required | Default |
|---|---|---|---|
path |
Path to scan (e.g. a conda environment directory) | Yes | - |
fail-build |
Fail the build if vulnerabilities are found | No | false |
only-fixed |
Only report vulnerabilities that have a fix available | No | true |
Example:
jobs:
scan:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read
steps:
# only need grype configuration
- uses: actions/checkout@main
with:
sparse-checkout: |
.grype.yaml
sparse-checkout-cone-mode: false
- name: Install Conda Package
id: install
uses: neutrons/gh-actions/pkg-install@main
with:
package-name: ${{ env.PKG_NAME }}
- name: Scan with Grype
uses: neutrons/gh-actions/grype@main
with:
path: ${{ steps.install.outputs.conda-install-dir }}