refactor: Switch to let-chains where possible #1931
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: test-suite | |
on: | |
push: | |
branches: | |
- stable | |
- 'pr/*' | |
pull_request: | |
types: [opened, synchronize, reopened, ready_for_review] | |
merge_group: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
# Deny warnings in CI | |
# Disable debug info (see https://github.com/sigp/lighthouse/issues/4005) | |
RUSTFLAGS: "-D warnings -C debuginfo=0" | |
# Prevent Github API rate limiting. | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Enable self-hosted runners for the Anchor repo only. | |
SELF_HOSTED_RUNNERS: false # ${{ github.repository == 'sigp/anchor' }} | |
# Self-hosted runners need to reference a different host for `./watch` tests. | |
WATCH_HOST: ${{ github.repository == 'sigp/anchor' && 'host.docker.internal' || 'localhost' }} | |
# Disable incremental compilation | |
CARGO_INCREMENTAL: 0 | |
# Enable portable to prevent issues with caching `blst` for the wrong CPU type | |
# TEST_FEATURES: portable | |
jobs: | |
check-labels: | |
runs-on: ubuntu-22.04 | |
name: Check for 'skip-ci' label | |
outputs: | |
skip_ci: ${{ steps.set-output.outputs.SKIP_CI }} | |
steps: | |
- name: check for skip-ci label | |
id: set-output | |
env: | |
LABELS: ${{ toJson(github.event.pull_request.labels) }} | |
run: | | |
SKIP_CI="false" | |
if [ -z "${LABELS}" ] || [ "${LABELS}" = "null" ]; then | |
LABELS="none"; | |
else | |
LABELS=$(echo ${LABELS} | jq -r '.[].name') | |
fi | |
for label in ${LABELS}; do | |
if [ "$label" = "skip-ci" ]; then | |
SKIP_CI="true" | |
break | |
fi | |
done | |
echo "skip_ci=$SKIP_CI" >> $GITHUB_OUTPUT | |
target-branch-check: | |
name: target-branch-check | |
runs-on: ubuntu-22.04 | |
if: github.event_name == 'pull_request' || github.event_name == 'merge_group' | |
steps: | |
- name: Check that the pull request is not targeting the stable branch | |
run: | | |
if [[ "${{ github.base_ref }}" == "stable" && "${{ github.head_ref }}" != "unstable" ]]; then | |
echo "Pull requests to the stable branch can only come from the unstable branch." | |
exit 1 | |
fi | |
release-tests-ubuntu: | |
name: release-tests-ubuntu | |
needs: [check-labels] | |
if: needs.check-labels.outputs.skip_ci != 'true' | |
# Use self-hosted runners only on the sigp repo. | |
runs-on: ubuntu-22.04 #${{ github.repository == 'sigp/anchor' && fromJson('["self-hosted", "linux", "CI", "large"]') || 'ubuntu-22.04' }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: 'recursive' | |
- name: Get latest version of stable Rust | |
if: env.SELF_HOSTED_RUNNERS == 'false' | |
uses: moonrepo/setup-rust@v1 | |
with: | |
cache: false # Don't change this and the others to true, see https://github.com/sigp/anchor/pull/240 | |
cache-target: release | |
bins: cargo-nextest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Run tests in release | |
run: make nextest-release | |
- name: Show cache stats | |
if: env.SELF_HOSTED_RUNNERS == 'true' | |
run: sccache --show-stats | |
debug-tests-ubuntu: | |
name: debug-tests-ubuntu | |
needs: [check-labels] | |
if: needs.check-labels.outputs.skip_ci != 'true' | |
# Use self-hosted runners only on the sigp repo. | |
runs-on: ubuntu-22.04 #${{ github.repository == 'sigp/anchor' && fromJson('["self-hosted", "linux", "CI", "large"]') || 'ubuntu-22.04' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: 'recursive' | |
- name: Get latest version of stable Rust | |
if: env.SELF_HOSTED_RUNNERS == 'false' | |
uses: moonrepo/setup-rust@v1 | |
with: | |
cache: false | |
channel: stable | |
bins: cargo-nextest | |
- name: Run tests in debug | |
run: make nextest-debug | |
- name: Show cache stats | |
if: env.SELF_HOSTED_RUNNERS == 'true' | |
run: sccache --show-stats | |
check-fmt: | |
name: check-fmt | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get latest version of nightly Rust | |
uses: moonrepo/setup-rust@v1 | |
with: | |
channel: nightly | |
components: rustfmt | |
- name: Check formatting with cargo fmt | |
run: make cargo-fmt-check | |
check-code: | |
name: check-code | |
runs-on: ubuntu-22.04 | |
env: | |
CARGO_INCREMENTAL: 1 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get latest version of stable Rust | |
uses: moonrepo/setup-rust@v1 | |
with: | |
channel: stable | |
cache-target: release | |
components: rustfmt,clippy | |
bins: cargo-audit | |
- name: Lint code for quality and style with Clippy | |
run: make lint | |
- name: Certify Cargo.lock freshness | |
run: git diff --exit-code Cargo.lock | |
- name: Run cargo audit | |
run: make audit-CI | |
- name: Run cargo vendor to make sure dependencies can be vendored for packaging, reproducibility and archival purpose | |
run: CARGO_HOME=$(readlink -f $HOME) make vendor | |
- name: Markdown-linter | |
run: make mdlint | |
check-msrv: | |
name: check-msrv | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust at Minimum Supported Rust Version (MSRV) | |
run: | | |
metadata=$(cargo metadata --no-deps --format-version 1) | |
msrv=$(echo $metadata | jq -r '.packages | map(select(.name == "anchor")) | .[0].rust_version') | |
rustup override set $msrv | |
- name: Run cargo check | |
run: cargo check --workspace | |
cargo-udeps: | |
name: cargo-udeps | |
needs: [check-labels] | |
if: needs.check-labels.outputs.skip_ci != 'true' | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get latest version of nightly Rust | |
uses: moonrepo/setup-rust@v1 | |
with: | |
channel: nightly | |
bins: cargo-udeps | |
cache: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Cargo config dir | |
run: mkdir -p .cargo | |
- name: Install custom Cargo config | |
run: cp -f .github/custom/config.toml .cargo/config.toml | |
- name: Run cargo udeps to identify unused crates in the dependency graph | |
run: make udeps | |
env: | |
# Allow warnings on Nightly | |
RUSTFLAGS: "" | |
spell-check: | |
name: spellcheck | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
# Uses the canonical version so that the version is up to date: | |
# https://github.com/rojopolis/spellcheck-github-actions?tab=readme-ov-file#using-a-canonical-version | |
- uses: rojopolis/[email protected] | |
with: | |
config_path: .github/spellcheck.yml | |
output_file: spellcheck-output.txt | |
# cli-check: | |
# name: cli-check | |
# needs: [check-labels] | |
# if: needs.check-labels.outputs.skip_ci != 'true' | |
# runs-on: ubuntu-22.04 | |
# steps: | |
# - uses: actions/checkout@v4 | |
# - name: Get latest version of stable Rust | |
# uses: moonrepo/setup-rust@v1 | |
# with: | |
# channel: stable | |
# cache-target: release | |
# - name: Run Makefile to trigger the bash script | |
# run: make cli | |
cargo-sort: | |
name: cargo-sort | |
needs: [check-labels] | |
if: needs.check-labels.outputs.skip_ci != 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get latest version of stable Rust | |
uses: moonrepo/setup-rust@v1 | |
with: | |
channel: stable | |
cache-target: release | |
bins: [email protected] | |
- name: Run cargo sort to check if Cargo.toml files are sorted | |
run: make sort | |
lockbud: | |
name: lockbud | |
runs-on: ubuntu-latest | |
container: | |
image: sigmaprime/lockbud:latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: apt update && apt install -y cmake libclang-dev | |
- name: Check for deadlocks | |
run: .github/scripts/check_lockbud.sh | |
# This job succeeds ONLY IF all others succeed. It is used by the merge queue to determine whether | |
# a PR is safe to merge. New jobs should be added here. | |
test-suite-success: | |
name: test-suite-success | |
if: needs.check-labels.outputs.skip_ci != 'true' | |
runs-on: ubuntu-latest | |
needs: [ | |
'check-labels', | |
'target-branch-check', | |
'release-tests-ubuntu', | |
'debug-tests-ubuntu', | |
'check-fmt', | |
'check-code', | |
'check-msrv', | |
'cargo-udeps', | |
'spell-check', | |
'cargo-sort', | |
'lockbud', | |
] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check that success job is dependent on all others | |
run: ./.github/scripts/check_success_job.sh ./.github/workflows/test-suite.yml test-suite-success |