name: Tests and Checks
on:
push:
branches: [ main ]
pull_request:
branches: [ '**' ]
workflow_dispatch:
inputs:
force_build_libkrun:
description: 'Force build libkrun'
required: false
type: boolean
default: false
env:
LIBKRUNFW_FULL_VERSION: "4.10.0"
LIBKRUNFW_ABI_VERSION: "4"
LIBKRUN_VERSION: "1.14.0"
LIBKRUN_ABI_VERSION: "1"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-libkrun-cache-changes:
strategy:
matrix:
os: [macos-26, ubuntu-latest]
runs-on: ${{ matrix.os }}
outputs:
cache_hit: ${{ steps.check_cache.outputs.cache-hit }}
libkrun_hash: ${{ steps.hash_libkrun.outputs.hash }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Hash build_libkrun.sh
id: hash_libkrun
run: |
HASH=$(sha256sum scripts/build_libkrun.sh | awk '{ print $1 }')
echo "hash=$HASH" >> $GITHUB_OUTPUT
echo "Calculated hash: $HASH"
- name: Check if cache exists
id: check_cache
uses: actions/cache/restore@v4
with:
path: |
build/libkrunfw/libkrunfw*.so*
build/libkrun/target/release/libkrun*.so*
build/libkrunfw.so*
build/libkrun.so*
key: ${{ runner.os }}-libkrun-${{ steps.hash_libkrun.outputs.hash }}
build-libkrun:
needs: check-libkrun-cache-changes
if: |
github.event.inputs.force_build_libkrun == 'true' ||
needs.check-libkrun-cache-changes.outputs.cache_hit != 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Dependencies
run: |
sudo apt-get update -qqy
sudo apt-get install -y jq libelf-dev build-essential flex bison libssl-dev libncurses5-dev python3-pip
pip3 install --user pyelftools
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Build libkrun
run: |
./scripts/build_libkrun.sh --no-cleanup --force-build
- name: Cache libkrun
uses: actions/cache/save@v4
with:
path: |
build/libkrunfw/libkrunfw*.so*
build/libkrun/target/release/libkrun*.so*
build/libkrunfw.so*
build/libkrun.so*
key: ${{ runner.os }}-libkrun-${{ needs.check-libkrun-cache-changes.outputs.libkrun_hash }}
run-checks:
needs: [check-libkrun-cache-changes, build-libkrun]
if: always()
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Cache Project
uses: Swatinem/rust-cache@v2
- name: Restore libkrun cache
uses: actions/cache/restore@v4
with:
path: |
build/libkrunfw/libkrunfw*.so*
build/libkrun/target/release/libkrun*.so*
build/libkrunfw.so*
build/libkrun.so*
key: ${{ runner.os }}-libkrun-${{ needs.check-libkrun-cache-changes.outputs.libkrun_hash }}
- name: Install Rust Toolchain (stable)
uses: actions-rs/toolchain@v1
with:
override: true
components: clippy
toolchain: stable
- name: Install Rust Toolchain (nightly)
uses: actions-rs/toolchain@v1
with:
override: true
components: rustfmt
toolchain: nightly
- name: Check Format
uses: actions-rs/cargo@v1
with:
args: --all -- --check
command: fmt
toolchain: nightly # use nightly for fmt
- name: Run Linter
uses: actions-rs/cargo@v1
with:
args: --all --all-features -- -D warnings
command: clippy
toolchain: stable
- name: Check Advisories
uses: EmbarkStudios/cargo-deny-action@v2
with:
command: check advisories
continue-on-error: true
- name: Check Bans, Licenses, and Sources
uses: EmbarkStudios/cargo-deny-action@v2
with:
command: check bans licenses sources
- name: Check Release Build
run: |
export LIBRARY_PATH=${{ github.workspace }}/build:${{ github.workspace }}/build/libkrunfw:${{ github.workspace }}/build/libkrun/target/release
export LD_LIBRARY_PATH=${{ github.workspace }}/build:${{ github.workspace }}/build/libkrunfw:${{ github.workspace }}/build/libkrun/target/release
cargo check --all-features
cargo build --release
run-tests:
needs: [check-libkrun-cache-changes, build-libkrun]
if: always()
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Restore libkrun cache
uses: actions/cache/restore@v4
with:
path: |
build/libkrunfw/libkrunfw*.so*
build/libkrun/target/release/libkrun*.so*
build/libkrunfw.so*
build/libkrun.so*
key: ${{ runner.os }}-libkrun-${{ needs.check-libkrun-cache-changes.outputs.libkrun_hash }}
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
override: true
toolchain: stable
# RUSTDOCFLAGS sets rpath so rustdoc tests (which run in /tmp) can find shared libraries at runtime
- name: Run Tests
run: |
export LIBRARY_PATH=${{ github.workspace }}/build:${{ github.workspace }}/build/libkrunfw:${{ github.workspace }}/build/libkrun/target/release
export LD_LIBRARY_PATH=${{ github.workspace }}/build:${{ github.workspace }}/build/libkrunfw:${{ github.workspace }}/build/libkrun/target/release
export RUSTDOCFLAGS="-C link-args=-Wl,-rpath,${{ github.workspace }}/build,-rpath,${{ github.workspace }}/build/libkrunfw,-rpath,${{ github.workspace }}/build/libkrun/target/release"
cargo test --workspace -- --include-ignored