Add cargo-llvm-cov test coverage reports (#766) #1003
This file contains 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: CI | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
permissions: | |
contents: read | |
env: | |
CARGO_TERM_COLOR: always | |
jobs: | |
lint: | |
name: Rust Code Linting | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Update Rust toolchain | |
run: rustup update | |
- name: Rust Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Clippy | |
run: cargo clippy --all-targets --locked -- --deny warnings | |
- name: rustfmt | |
run: cargo fmt -- --check | |
unit-test: | |
name: Unit Tests | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Update Rust toolchain | |
run: rustup update | |
- name: Rust Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Run unit tests | |
run: cargo test --locked | |
# Currently a separate job since the #coverage(off) attribute requires nightly Rust. As soon as we can use llvm-cov | |
# without Rust nightly, we should merge this job with the regular unit tests. | |
unit-test-coverage: | |
name: Generate test coverage report | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Install nightly Rust toolchain | |
run: rustup install nightly | |
- name: Rust Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Install cargo-llvm-cov | |
uses: taiki-e/install-action@cargo-llvm-cov | |
- name: Run unit tests and generate coverage report | |
run: cargo +nightly llvm-cov --locked --html | |
- name: Upload HTML coverage report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: "llvm-cov-html-${{github.event.repository.name}}-${{github.sha}}" | |
path: "target/llvm-cov/html" | |
if-no-files-found: "error" | |
integration-test: | |
name: Integration Tests (${{ matrix.buildpack-directory }}, ${{matrix.builder}}, ${{matrix.arch}}) | |
runs-on: ${{ matrix.arch == 'arm64' && 'pub-hk-ubuntu-24.04-arm-large' || 'pub-hk-ubuntu-24.04-large' }} | |
strategy: | |
fail-fast: false | |
matrix: | |
builder: [ "builder:24", "builder:22", "builder:20" ] | |
arch: [ "amd64", "arm64" ] | |
buildpack-directory: [ "buildpacks/gradle", "buildpacks/jvm", "buildpacks/jvm-function-invoker", "buildpacks/maven", "buildpacks/sbt" ] | |
exclude: | |
- builder: "builder:22" | |
arch: "arm64" | |
- builder: "builder:20" | |
arch: "arm64" | |
- buildpack-directory: "buildpacks/jvm-function-invoker" | |
builder: "builder:20" | |
- buildpack-directory: "buildpacks/jvm-function-invoker" | |
builder: "builder:24" | |
env: | |
INTEGRATION_TEST_BUILDER: heroku/${{ matrix.builder }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Install musl-tools | |
run: sudo apt-get install -y --no-install-recommends musl-tools | |
- name: Update Rust toolchain | |
run: rustup update | |
- name: Install Rust linux-musl target | |
run: rustup target add ${{ matrix.arch == 'arm64' && 'aarch64-unknown-linux-musl' || 'x86_64-unknown-linux-musl' }} | |
- name: Rust Cache | |
uses: Swatinem/rust-cache@v2 | |
- name: Install Pack CLI | |
uses: buildpacks/github-actions/[email protected] | |
# The images are pulled up front to prevent duplicate pulls due to the tests being run concurrently. | |
- name: Pull builder image | |
run: docker pull ${{ env.INTEGRATION_TEST_BUILDER }} | |
- name: Pull run image | |
# Using `docker inspect` rather than `pack builder inspect` since the latter makes | |
# additional requests to Docker Hub even when the image is available locally. | |
run: | | |
RUN_IMAGE=$( | |
docker inspect --format='{{index .Config.Labels "io.buildpacks.builder.metadata"}}' '${{ env.INTEGRATION_TEST_BUILDER }}' \ | |
| jq --exit-status --raw-output '.stack.runImage.image' | |
) | |
docker pull "${RUN_IMAGE}" | |
- name: Run integration tests | |
working-directory: ${{ matrix.buildpack-directory }} | |
# Runs only tests annotated with the `ignore` attribute (which in this repo, are the integration tests). | |
run: cargo test --locked -- --ignored --test-threads 16 |