Skip to content

.github/workflows/coverage.yml #403

.github/workflows/coverage.yml

.github/workflows/coverage.yml #403

Workflow file for this run

on:
schedule:
- cron: 0 0 * * *
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
jobs:
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@nightly
with:
components: llvm-tools
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
- name: Install fuzzing utilities
run: |
cargo install cargo-fuzz
cargo install cargo-binutils
cargo install rustfilt
- name: Set up configuation
run: |
cp Cargo.toml Cargo.toml.bak
cat Cargo.toml.bak | grep -v "lto" > Cargo.toml
- name: Get date
id: get-date
run: |
echo "today=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
echo "yesterday=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
- name: Cache fuzzing data
uses: actions/cache@v4
with:
path: fuzzing-data
key: ${{ runner.os }}-fuzzing-data-${{ steps.get-date.outputs.today }}
restore-keys: |
${{ runner.os }}-fuzzing-data-${{ steps.get-date.outputs.today }}
${{ runner.os }}-fuzzing-data-${{ steps.get-date.outputs.yesterday }}
${{ runner.os }}-fuzzing-data-
${{ runner.os }}-
- name: Prepare fuzzing data
run: |
mkdir -p fuzzing-data/artifacts && cp -r fuzzing-data/artifacts fuzz
mkdir -p fuzzing-data/corpus && cp -r fuzzing-data/corpus fuzz
mkdir -p fuzzing-data/coverage && cp -r fuzzing-data/coverage fuzz
mkdir -p target
touch target/lcov.txt
- name: Fuzz target (stress)
id: fuzz-target-stress
run: |
cargo fuzz run stress &
PID=$!
sleep 60
k(){ if c=$(pgrep -P $1);then for p in $c;do k $p;done;fi;kill $1; }; k $PID
cargo fuzz coverage stress
cargo cov -- export -format=lcov \
-instr-profile=./fuzz/coverage/stress/coverage.profdata \
-object ./target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release/stress \
-sources ./src | rustfilt >> target/lcov.txt
env:
RUSTFLAGS: -Cdebuginfo=2
RUST_BACKTRACE: 1
continue-on-error: true
- name: Fuzz target (stress_local)
id: fuzz-target-stress_local
run: |
cargo fuzz run stress_local &
PID=$!
sleep 60
k(){ if c=$(pgrep -P $1);then for p in $c;do k $p;done;fi;kill $1; }; k $PID
cargo fuzz coverage stress_local
cargo cov -- export -format=lcov \
-instr-profile=./fuzz/coverage/stress_local/coverage.profdata \
-object ./target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release/stress_local \
-sources ./src | rustfilt >> target/lcov.txt
env:
RUSTFLAGS: -Cdebuginfo=2
RUST_BACKTRACE: 1
continue-on-error: true
- name: Fuzz target (custom)
id: fuzz-target-custom
run: |
cargo fuzz run custom &
PID=$!
sleep 60
k(){ if c=$(pgrep -P $1);then for p in $c;do k $p;done;fi;kill $1; }; k $PID
cargo fuzz coverage custom
cargo cov -- export -format=lcov \
-instr-profile=./fuzz/coverage/custom/coverage.profdata \
-object ./target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release/custom \
-sources ./src | rustfilt >> target/lcov.txt
env:
RUSTFLAGS: -Cdebuginfo=2
RUST_BACKTRACE: 1
continue-on-error: true
- name: Save fuzzing data
run: |
cp -rf fuzz/artifacts fuzzing-data
cp -rf fuzz/corpus fuzzing-data
cp -rf fuzz/coverage fuzzing-data
- name: Upload failure artifacts
uses: actions/upload-artifact@v4
with:
path: fuzzing-data
name: fuzzing-data
if: ${{ steps.fuzz-target-stress.outcome == 'failure' || steps.fuzz-target-stress_local.outcome == 'failure' || steps.fuzz-target-custom.outcome == 'failure'}}
- name: Upload coverage report
uses: codecov/codecov-action@v4
with:
file: ./target/lcov.txt
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
slug: js2xxx/ferroc
if: ${{ steps.fuzz-target-stress.outcome == 'success' && steps.fuzz-target-stress_local.outcome == 'success' && steps.fuzz-target-custom.outcome == 'success' }}