agama/.github/workflows/ci-rust.yml
Ladislav Slezák 94870bc0f0
[SLE-16.0] Cache installed Ruby gems in CI (#3528)
## Problems

- Old versions of GitHub Actions (they use old unsupported NodeJS v20,
GitHub prints a ["Node.js 20 actions are deprecated"
](https://github.com/agama-project/agama/actions/runs/26086960005)
warning)
- Installing the needed Ruby gems takes quite long time (about [one and
half
minute](https://github.com/agama-project/agama/actions/runs/26175301761/job/77003739150#step:9:7))

## Solution

- Update the GitHub Action versions
- Cache the installed Ruby gems, restoring the cache and running Bundler
now takes [just about 15
seconds](https://github.com/agama-project/agama/actions/runs/26182626931/job/77029525706#step:8:17).
So the test run is it at least more than one minute faster!

## Testing

- Tested with the updated GitHub Actions
2026-05-21 09:48:50 +02:00

246 lines
6.8 KiB
YAML

name: CI - Rust
permissions:
contents: read
on:
push:
paths:
# NOTE: GitHub Actions do not allow using YAML references, the same path
# list is used below for the pull request event. Keep both lists in sync!!
# this file as well
- .github/workflows/ci-rust.yml
# any change in the rust subfolder
- rust/**
# except Markdown documentation
- "!rust/**.md"
# except the packaging
- "!rust/package/**"
# except the DBus configuration
- "!rust/share/**"
pull_request:
paths:
# NOTE: GitHub Actions do not allow using YAML references, the same path
# list is used above for the push event. Keep both lists in sync!!
# this file as well
- .github/workflows/ci-rust.yml
# any change in the rust subfolder
- rust/**
# except Markdown documentation
- "!rust/**.md"
# except the packaging
- "!rust/package/**"
# except the DBus configuration
- "!rust/share/**"
# allow running manually
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
# this makes the build slightly faster and the saved cache smaller
CARGO_INCREMENTAL: 0
jobs:
fmt:
# the default timeout is 6 hours, that's too much if the job gets stuck
timeout-minutes: 10
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./rust
steps:
- name: Git Checkout
uses: actions/checkout@v6
- name: Rust toolchain
run: |
rustup show
cargo --version
- name: Run rustfmt
run: cargo fmt --all -- --check
clippy:
# the default timeout is 6 hours, that's too much if the job gets stuck
timeout-minutes: 20
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./rust
steps:
- name: Git Checkout
uses: actions/checkout@v6
- name: Rust toolchain
run: |
rustup show
cargo --version
- name: Install packages
run: |
sudo apt-get update
sudo apt-get -y install libclang-18-dev libpam0g-dev
- name: Installed packages
run: apt list --installed
- name: Rust cache
uses: actions/cache@v5
with:
path: |
~/.cargo
rust/target
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
- name: Run clippy linter
run: cargo clippy
tests:
# the default timeout is 6 hours, that's too much if the job gets stuck
timeout-minutes: 30
runs-on: ubuntu-latest
env:
COVERAGE: 1
defaults:
run:
working-directory: ./rust
steps:
- name: Git Checkout
uses: actions/checkout@v6
- name: Rust toolchain
run: |
rustup show
cargo --version
- name: Install packages
run: |
sudo apt-get update
sudo apt-get -y install libclang-18-dev libpam0g-dev python3-langtable jsonnet
- name: Prepare for tests
run: |
# the langtable data location is different in SUSE/openSUSE, create a symlink
sudo mkdir -p /usr/share/langtable
sudo ln -s /usr/lib/python3/dist-packages/langtable/data /usr/share/langtable/data
# create the /etc/agama.d/locales file with list of locales
sudo mkdir /etc/agama.d
sudo bash -c 'ls -1 -d /usr/share/i18n/locales/* | sed -e "s#/usr/share/i18n/locales/##" >/etc/agama.d/locales'
- name: Installed packages
run: apt list --installed
- name: Rust cache
id: cache-tests
uses: actions/cache@v5
with:
path: |
~/.cargo
rust/target-coverage
key: ${{ runner.os }}-cargo-tests-${{ hashFiles('**/Cargo.lock') }}
- name: Install Tarpaulin (for code coverage)
# skip the step completely if the cache has been restored
# this avoids refreshing the crates index and saves few seconds
if: steps.cache-tests.outputs.cache-hit != 'true'
run: cargo install cargo-tarpaulin
- name: Run the tests
# Compile into the ./target-coverage directory because tarpaulin uses special compilation
# flags, to avoid reusing the previous builds it always starts from scratch.
# The --skip-clean skips the cleanup and allows using the cached results.
# See https://github.com/xd009642/tarpaulin/discussions/772
run: cargo tarpaulin --workspace --all-targets --doc --out xml --target-dir target-coverage --skip-clean -- --nocapture
env:
# use the "stable" tool chain (installed by default) instead of the "nightly" default in tarpaulin
RUSTC_BOOTSTRAP: 1
RUSTUP_TOOLCHAIN: stable
RUST_BACKTRACE: 1
RUSTFLAGS: --cfg ci
# send the code coverage for the Rust part to the coveralls.io
- name: Send coverage data to Coveralls
timeout-minutes: 10
# ignore errors in this step
continue-on-error: true
uses: coverallsapp/github-action@v2
with:
flag-name: rust
base-path: ./rust
format: cobertura
# Close the parallel build and inherit the Web parts (it needs a separate step, the "carryforward" flag can be used
# only with the "parallel-finished: true" option)
- name: Close the Coveralls build
timeout-minutes: 10
# ignore errors in this step
continue-on-error: true
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
carryforward: "rust,service,web"
openapi:
# the default timeout is 6 hours, that's too much if the job gets stuck
timeout-minutes: 30
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./rust
steps:
- name: Git Checkout
uses: actions/checkout@v6
- name: Rust toolchain
run: |
rustup show
cargo --version
- name: Configure system
# disable updating initramfs (the system is not booted again)
# disable updating man db (to save some time)
run: |
sudo sed -i "s/yes/no/g" /etc/initramfs-tools/update-initramfs.conf
sudo rm -f /var/lib/man-db/auto-update
- name: Install packages
run: |
sudo apt-get update
sudo apt-get -y install libclang-18-dev libpam0g-dev
# uninstall the python3-jsonschema package, openapi-spec-validator wants
# to install a newer version which would conflict with that
sudo apt-get purge python3-jsonschema python3-typing-extensions
sudo pip install openapi-spec-validator
- name: Installed packages
run: apt list --installed
- name: Rust cache
uses: actions/cache@v5
with:
path: |
~/.cargo
rust/target
key: ${{ runner.os }}-cargo-openapi-${{ hashFiles('**/Cargo.lock') }}
- name: Generate the OpenAPI specification
run: cargo xtask openapi
- name: Validate the OpenAPI specification
run: openapi-spec-validator out/openapi/*