Reusable GitHub Actions workflows for Ystorian repositories.
This is a public repository licensed under the GNU Affero General Public License v3.0.
CI:
- Detect changes Detect relevant file changes to skip unneeded jobs
- Check Check actions and source code
- Test Rust Test and lint Rust code on one or more runners
- Cargo cache cleanup Delete superseded Cargo caches
- Status check Set the required status check branch protection
Deployment:
- Detect changes Detect relevant file changes to skip unneeded jobs
- Build image Build and push a Docker image
- Dispatch to Ynfra Send a dispatch event
Release:
- Release Rust Build, sign, and publish the binaries of a Rust package
- Publish crate Publish a Rust package to crates.io
The detect_changes.yaml workflow detects relevant file changes with
dorny/paths-filter.
It reads the .github/filters.yaml file of the calling repository.
- On push: the
runoutput is the result of thefilterinput. - On other events: the
runoutput is alwaystrue.
jobs:
changes:
name: Workflows
uses: ystorian/workflows/.github/workflows/detect_changes.yaml@main
permissions:
contents: read
with:
filter: ci # Optional, default is `ci`.
test:
needs: changes
if: needs.changes.outputs.run == 'true'The status_check.yaml workflow gives one required status check for a workflow.
It fails when a job in needs failed or was canceled.
Skipped jobs pass.
jobs:
status:
name: Workflows
needs: [changes, check, test]
if: always()
uses: ystorian/workflows/.github/workflows/status_check.yaml@main
with:
needs: ${{ toJSON(needs) }}In branch protection, require only Workflows / Status check.
The check.yaml workflow checks a repository on Linux arm64. It checks Just recipes, typos, and
actions. More recipes can be added to check for other lints.
The caller must have these Just recipes:
check_justcheck_typoscheck_actionsaudit_actions
On failure, it cancels the whole workflow run.
jobs:
check:
name: Workflows
needs: changes
if: needs.changes.outputs.run == 'true'
uses: ystorian/workflows/.github/workflows/check.yaml@main
permissions:
actions: write # Required to cancel the `test` jobs on failure.
contents: read
with:
tools: cargo-deny,flynt # Comma separated optional tools to install.
recipes: check_deny flynt # Space separated optional Just recipes to run.
timeout: 1 # Optional, default is `1`.The recipes input does not install tools. Add the tools of the recipes to tools.
For example, check_deny needs tools: cargo-deny.
The recipes input skips check_rust with a warning. This recipe runs cargo fmt, and the
Rust version of the runner can be too old. The test_rust.yaml workflow runs check_rust.
The test_rust.yaml workflow tests a Rust repository with the ci Cargo profile.
It runs:
just check_ruston the first runner (Linux by default)just test cion each runnerjust clippy cion the OS inclippy_os
The formatting is checked here to use the same Rust version as the tests.
Clippy fails on warnings with the ci profile.
It caches the Cargo crates and the target folder. See Cargo cache cleanup.
The caller must have the Just recipes:
check_rustfetchtestclippyprune_target
The caller's workflow env is not passed to a reusable workflow. Use the env input.
The services start only on Linux runners. With postgres: true, DATABASE_URL is set to
postgres://postgres:secret@localhost:1338/postgres.
jobs:
test:
name: Workflows
needs: changes
if: needs.changes.outputs.run == 'true'
uses: ystorian/workflows/.github/workflows/test_rust.yaml@main
permissions:
contents: read
with:
runners: '["ubuntu-26.04-arm", "windows-11-arm", "macos-26"]' # Optional, default is Linux.
rust_version: 1.99.1 # Optional, default is the runner's version.
clippy_os: '["Linux", "macOS"]' # Optional, default is Linux.
clippy_strict: true # Optional, run Clippy with `--strict`.
apt_packages: libfontconfig1-dev # Optional, space separated, Linux only.
env: | # Optional, one `KEY=VALUE` per line.
SLINT_NO_QT=1
postgres: true # Optional, Postgres on port 1338.
mail: true # Optional, Mailpit on ports 1025 and 8025.
recipes: test_app # Optional, space separated Just recipes to run.
timeout: 10 # Optional, default is `10`.Use cargo_cache_cleanup.yaml after this job to delete the superseded caches.
The cargo_cache_cleanup.yaml workflow deletes the superseded Cargo caches of the current ref.
It keeps the newest cache for each group of key fields.
The cache keys must look like cargo-<os>-<arch>-<rustc>-<lock>[-<run_id>].
The default group is the first 4 fields: cargo-<os>-<arch>-<rustc>.
jobs:
cargo-cache-cleanup:
name: Workflows
needs: test
if: github.ref == 'refs/heads/main'
uses: ystorian/workflows/.github/workflows/cargo_cache_cleanup.yaml@main
permissions:
actions: write # Required to list and delete the cache entries.
with:
fields: 4 # Optional, default is `4`.The build_image.yaml workflow builds a Docker image and pushes it to ghcr.io/<owner>/<image>.
It gives the commit ID to the build with the COMMIT_ID build argument.
It tags the image with the branch name and with sha-<commit>.
It keeps the build cache in the buildcache tag.
jobs:
build:
name: Workflows
needs: changes
if: needs.changes.outputs.run == 'true'
uses: ystorian/workflows/.github/workflows/build_image.yaml@main
permissions:
contents: read
packages: write # Required to push to ghcr.io.
with:
image: app
dockerfile: app.Dockerfile # Optional, default is `<image>.Dockerfile`.
timeout: 5 # Optional, default is `5`.The dispatch_to_ynfra.yaml workflow sends a repository_dispatch event to <owner>/ynfra.
It sends the commit SHA in client_payload.sha, to deploy the sha-<commit> image tag.
The YNFRA_DISPATCH_TOKEN secret is in the environment of the caller repository.
The caller must pass it by name, otherwise it is empty.
jobs:
dispatch:
name: Workflows
needs: build
uses: ystorian/workflows/.github/workflows/dispatch_to_ynfra.yaml@main
permissions:
contents: read
with:
event: restart-app
environment: production # Optional, default is `production`.
secrets:
YNFRA_DISPATCH_TOKEN: ${{ secrets.YNFRA_DISPATCH_TOKEN }}The release_rust.yaml workflow releases the binaries of a Rust package on a v* tag push.
It runs:
draft: checks the tag against theCargo.tomlversion, and creates a draft release.build: builds one archive per target (.tar.gz, or.zipon Windows).sign: signs the archives and aSHA256SUMSfile with minisign, and attaches them to the draft.publish: publishes the draft only when all the other jobs passed.
A workflow_dispatch run only builds the archives. It does not sign or publish.
The Cargo.toml file must have a minisign pubkey, for example in
[package.metadata.binstall.signing]. The signatures are checked against this key.
The MINISIGN_SECRET_KEY and MINISIGN_PASSWORD secrets are in the environment of the caller
repository. The caller passes them by name.
The default targets are Linux (musl), macOS, and Windows, on x64 and arm64.
on:
push:
tags:
- v*
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
release:
name: Workflows
uses: ystorian/workflows/.github/workflows/release_rust.yaml@main
permissions:
contents: write # Required to create and publish the release.
with:
targets: '[{"os": "ubuntu-26.04-arm", "name": "Linux arm64", "target": "aarch64-unknown-linux-musl"}]' # Optional.
features: cli # Optional, comma separated Cargo features.
environment: release # Optional, default is `release`.
timeout: 10 # Optional, build timeout, default is `10`.
secrets:
MINISIGN_SECRET_KEY: ${{ secrets.MINISIGN_SECRET_KEY }}
MINISIGN_PASSWORD: ${{ secrets.MINISIGN_PASSWORD }}The publish_crate.yaml workflow publishes a Rust package to crates.io with
Trusted Publishing.
On crates.io, set the Trusted Publishing workflow to the caller file, for example release.yaml.
crates.io checks the caller workflow, not this file.
Add if: github.event_name == 'push', to skip a workflow_dispatch run.
jobs:
crate:
name: Workflows
needs: release
if: github.event_name == 'push'
uses: ystorian/workflows/.github/workflows/publish_crate.yaml@main
permissions:
contents: read
id-token: write # Required for crates.io Trusted Publishing.
with:
environment: release # Optional, default is `release`.
timeout: 5 # Optional, default is `5`.Pin the workflows to a commit SHA. Update them with just update_actions.