Skip to content

Invoke proper caching on CI #69

Invoke proper caching on CI

Invoke proper caching on CI #69

Workflow file for this run

# This is a workflow file to run, build, and test all crates used as part of `rust-exercises`.
# It is cached with Swatinem/rust-cache@v2 and setup so that no jobs depend on any other jobs,
# EXCEPT for the last `deploy` job, which marks all other jobs in the `needs:` field as a dependency to fire.
# The brunt of the work is defined in `build_fns.sh` where the actual build/testing logic is defined.
name: rust-exercises
env:
CARGO_TERM_COLOR: always # We want colors in our CI output
CARGO_INCREMENTAL: 0 # Don't waste time writing out incremental build files
CARGO_PROFILE_TEST_DEBUG: 0 # These are thrown away anyways, don't produce them
on:
push:
branches:
- main
tags:
- "**"
pull_request:
branches:
- main
# * All jobs defined here run independently of each other.
# * Jobs that have a `matrix` field will setup up a job per entry in said `matrix`.
# If you add *ANY* jobs, make sure to add them to the `needs:` field of the `deploy` job, since that
# ensures `deploy` will run last.
jobs:
test_and_build_mdbook:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Install mdbook, mdbook-mermaid
uses: taiki-e/install-action@v2
with:
tool: [email protected],[email protected]
# From Rust Cache Action:
# selecting a toolchain either by action or manual `rustup` calls should happen
# before the plugin, as the cache uses the current rustc version as its cache key
- run: rustup toolchain install stable --profile minimal
- name: Setup
run: |
cd exercise-book
# For the cache to be keyed properly, we need to `cd` into a directory that can invoke `cargo` commands.
# Thus above `cd exercise-book` *has* to happen before invoking the `Swatinem/rust-cache@v2` action.
- uses: Swatinem/rust-cache@v2
- name: Load cache
run: |
mdbook test
mdbook build
# Uploading an artifact is how we can share data between different jobs
- name: Upload mdbook artifacts
uses: actions/upload-artifact@v4
with:
name: mdbook-dir
path: book/
if-no-files-found: error
test_exercise_solutions_and_examples:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- run: |
rustup toolchain install stable --profile minimal
cd exercise-solutions
- uses: Swatinem/rust-cache@v2
with:
workspaces: exercise-solutions
- name: Test exercise-solutions and examples, with cache
run: |
cargo test --locked
cargo test --examples --locked
test_exercise_solutions_standalone_crates:
runs-on: ubuntu-24.04
strategy:
matrix:
crates: [exercise-solutions/connected-mailbox,
exercise-solutions/multi-threaded-mailbox]
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal
- name: Test exercise-solutions standalone crates
run: |
cd ${{matrix.crates}}
- uses: Swatinem/rust-cache@v2
with:
workspaces: ${{matrix.crates}}
- name: Load cache
run: |
cargo test --locked
build_qemu_core:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --component rust-src
- uses: Swatinem/rust-cache@v2
- name: Build qemu-code/uart-driver
run: |
cd qemu-code/uart-driver
- uses: Swatinem/rust-cache@v2
with:
workspaces: qemu-code/uart-driver
- name: Load cache
run: |
RUSTC_BOOTSTRAP=1 cargo build -Zbuild-std=core --locked
build_nrf52_usb_crates:
runs-on: ubuntu-24.04
strategy:
matrix:
crates: [nrf52-code/boards/dk,
nrf52-code/boards/dk-solution,
nrf52-code/boards/dongle,
nrf52-code/radio-app,
nrf52-code/usb-app,
nrf52-code/usb-app-solutions,
nrf52-code/consts]
steps:
- name: Install flip-link
uses: taiki-e/install-action@v2
with:
tool: [email protected]
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --target thumbv7em-none-eabihf
- uses: Swatinem/rust-cache@v2
with:
workspaces: ${{matrix.crates}}
- name: build-only nrf52 crates
run: |
cd ${{matrix.crates}}
- uses: Swatinem/rust-cache@v2
- name: Load cache
run: |
cargo build --target=thumbv7em-none-eabihf --locked --release
# This job is different from the one above because we cannot make individual steps conditional,
# but we can define a different `matrix` of files that we have to upload
build_nrf52_usb_crates_and_upload_fw:
runs-on: ubuntu-24.04
strategy:
matrix:
crates: [puzzle-fw, loopback-fw]
steps:
- name: Install flip-link
uses: taiki-e/install-action@v2
with:
tool: [email protected]
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --target thumbv7em-none-eabihf
- name: build-only nrf52 crates
run: |
cd nrf52-code/${{matrix.crates}}
- uses: Swatinem/rust-cache@v2
with:
workspaces: nrf52-code/${{matrix.crates}}
- name: Load cache
run: |
cargo build --target=thumbv7em-none-eabihf --locked --release
# We also upload the built binaries in the puzzle-fw and loopback-fw cases
- name: Upload ${{matrix.crates}} artifacts
uses: actions/upload-artifact@v4
with:
name: ${{matrix.crates}}
path: ${{matrix.crates}}/target/thumbv7em-none-eabihf/release/
if-no-files-found: error
build_and_test_nrf52_crates:
runs-on: ubuntu-24.04
strategy:
matrix:
crates: [nrf52-code/usb-lib-solutions/complete,
nrf52-code/usb-lib-solutions/get-descriptor-config,
nrf52-code/usb-lib-solutions/get-device,
nrf52-code/usb-lib-solutions/set-config]
steps:
- name: Install flip-link
uses: taiki-e/install-action@v2
with:
tool: [email protected]
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --target thumbv7em-none-eabihf
- name: build-and-test nrf52 crates
run: |
cd ${{matrix.crates}}
- uses: Swatinem/rust-cache@v2
with:
workspaces: ${{matrix.crates}}
- name: Load cache
run: |
cargo build --target=thumbv7em-none-eabihf --locked --release
cargo test --locked
check_templates:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal
- uses: Swatinem/rust-cache@v2
- name: Check exercise-templates
run: |
cd exercise-templates
- uses: Swatinem/rust-cache@v2
with:
workspaces: exercise-templates
- name: Load cache
run: |
cargo check --locked
check_fmt:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- run: rustup toolchain install stable --profile minimal --component rustfmt
- uses: Swatinem/rust-cache@v2
- name: Check fmt
run: |
. build_fns.sh
check_fmt
# This is the last job, and waits (`needs:`) on all the other jobs before firing.
# It the necessary resulting builds as artifacts, zips them, and uploads with a tag if necessary.
deploy:
runs-on: ubuntu-24.04
needs: [test_and_build_mdbook,
test_exercise_solutions_and_examples,
test_exercise_solutions_standalone_crates,
build_qemu_core,
build_nrf52_usb_crates,
build_nrf52_usb_crates_and_upload_fw,
build_and_test_nrf52_crates,
check_templates,
check_fmt]
steps:
- uses: actions/checkout@v4
# Download the produced artifacts
- name: Download mdbook-dir artifact
uses: actions/download-artifact@v4
with:
# Move the mdbook `book` dir to where we expect it to be
name: mdbook-dir
path: ./exercise-book/book
- name: Download puzzle-fw artifact
uses: actions/download-artifact@v4
with:
name: puzzle-fw
path: ./nrf52-code/puzzle-fw/target/thumbv7em-none-eabihf/release/
- name: Download loopback-fw artifact
uses: actions/download-artifact@v4
with:
name: loopback-fw
path: ./nrf52-code/loopback-fw/target/thumbv7em-none-eabihf/release/
- name: Find slug name
run: |
slug=$(./describe.sh "${GITHUB_REF}")
echo "Building with slug '${slug}'"
echo "slug=${slug}" >> "${GITHUB_ENV}"
- name: Build and test
env: # Or as an environment variable
HIDDEN_MESSAGE: ${{ secrets.HIDDEN_MESSAGE }}
run: |
. build_fns.sh
zip_output "./rust-exercises-${{ env.slug }}"
- name: Upload Artifacts
uses: actions/upload-artifact@v4
if: ${{success()}}
with:
name: Artifacts
if-no-files-found: error
path: |
./rust-exercises-*
- name: Create and Upload Release
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags/')
id: create_release
uses: ncipollo/release-action@v1
with:
artifacts: "./rust-exercises-${{ env.slug }}.zip,./rust-exercises-${{ env.slug }}/nrf52-code/boards/dongle-fw/*-fw"
allowUpdates: true
updateOnlyUnreleased: true