Fix benchmark data path (#367) #54
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
on: | |
push: | |
branches: | |
- main | |
- v*.x | |
workflow_dispatch: {} | |
name: Code coverage | |
jobs: | |
coverage: | |
name: Coverage | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
target: | |
- x86_64-unknown-linux-gnu | |
- armv7-unknown-linux-gnueabihf | |
- aarch64-unknown-linux-gnu | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: 'true' | |
- uses: dtolnay/rust-toolchain@nightly | |
id: toolchain | |
with: | |
targets: ${{ matrix.target }} | |
components: 'llvm-tools-preview' | |
- uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
key: ${{ runner.os }}-dot-cargo-${{ steps.toolchain.outputs.cacheKey }}-cross-19be83481fd3e50ea103d800d72e0f8eddb1c90c-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}-dot-cargo-${{ steps.toolchain.outputs.cacheKey }}-cross-19be83481fd3e50ea103d800d72e0f8eddb1c90c- | |
${{ runner.os }}-dot-cargo-${{ steps.toolchain.outputs.cacheKey }}-${{ hashFiles('**/Cargo.lock') }}- | |
${{ runner.os }}-dot-cargo-${{ steps.toolchain.outputs.cacheKey }}- | |
${{ runner.os }}-dot-cargo- | |
- uses: actions/cache@v4 | |
with: | |
path: | | |
./crates/jxl-oxide-tests/tests/cache/ | |
key: jxl-oxide-fixtures-0-${{ hashFiles('crates/jxl-oxide-tests/tests/*.rs') }} | |
restore-keys: | | |
jxl-oxide-fixtures-0- | |
- name: Install cross | |
uses: taiki-e/cache-cargo-install-action@v2 | |
with: | |
tool: cross | |
git: https://github.com/cross-rs/cross | |
rev: 7b79041c9278769eca57fae10c74741f5aa5c14b | |
- name: Set environment variables | |
run: | | |
target_uppercase="$(tr '[:lower:]-' '[:upper:]_' <<< '${{ matrix.target }}')" | |
echo "RUSTFLAGS=-C instrument-coverage -Z coverage-options=branch" >>"$GITHUB_ENV" | |
echo "CARGO_TARGET_${target_uppercase}_RUSTFLAGS=-C instrument-coverage -Z coverage-options=branch" >>"$GITHUB_ENV" | |
echo "RUSTC_SYSROOT=$(rustc --print sysroot)" >>"$GITHUB_ENV" | |
- name: Run tests | |
run: cross test --tests --no-fail-fast --target ${{ matrix.target }} | |
- name: Collect coverage data | |
run: | | |
llvm_profdata="$(find $RUSTC_SYSROOT -name llvm-profdata)" | |
llvm_cov="$(find $RUSTC_SYSROOT -name llvm-cov)" | |
profiles="$(find . -name '*.profraw')" | |
$llvm_profdata merge -sparse $profiles -o coverage.profdata | |
testbins=$( \ | |
cross test --no-run --message-format=json --target ${{ matrix.target }} \ | |
| jq -r "select(.profile.test == true) | .filenames[]" \ | |
| grep -v dSYM \ | |
) | |
covargs=$(for bin in $testbins; do echo "-object ${PWD}${bin}"; done) | |
$llvm_cov export -format=lcov -instr-profile=coverage.profdata $covargs \ | |
-ignore-filename-regex='/\.cargo/' \ | |
-ignore-filename-regex='/rustc/' \ | |
>coverage.lcov | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v4 | |
with: | |
files: ./coverage.lcov | |
flags: rust-${{ matrix.target }} | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
- uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: images | |
path: crates/jxl-oxide-tests/tests/.artifact/ |