on:
workflow_call:
inputs:
os:
required: true
type: string
secrets:
NPCAP_OEM_PASSWORD:
required: false
NPCAP_OEM_USERNAME:
required: false
env:
RUST_BACKTRACE: 1
CARGO_TERM_VERBOSE: true
CARGO_TERM_COLOR: always
PCAP_CI_TEST_TARGETS: ${{ contains(inputs.os, 'windows') && (github.event_name == 'pull_request') && '--lib' || '--all-targets' }}
PCAP_CI_GRCOV_CMD: >-
${{ contains(inputs.os, 'windows') && 'C:/grcov' || './grcov' }}
target/debug/profraw
--binary-path ./target/debug/
--output-types html
--source-dir .
--ignore-not-existing
--ignore "build.rs"
--ignore "tests/*"
--ignore "examples/*"
--excl-start "GRCOV_EXCL_START|mod tests \{"
--excl-stop "GRCOV_EXCL_STOP"
--output-path ./target/debug/coverage/
PCAP_CI_COV_CMD: >-
python3 .github/scripts/coverage.py
--coverage-file ./target/debug/coverage/coverage.json
PCAP_CI_COV_FAIL_UNDER_NO_FEATURES: ${{ contains(inputs.os, 'windows') && '80.00' || '100.00' }}
PCAP_CI_COV_FAIL_UNDER_ALL_FEATURES: ${{ contains(inputs.os, 'windows') && '75.00' || '96.00' }}
jobs:
coverage:
runs-on: ${{ inputs.os }}
env:
LLVM_PROFILE_FILE: 'target/debug/profraw/pcap-%p-%m.profraw'
RUSTFLAGS: '-C instrument-coverage'
steps:
- uses: actions/checkout@v4
- if: ${{ contains(inputs.os, 'ubuntu') }}
run: sudo apt-get install libpcap-dev
- if: ${{ contains(inputs.os, 'macos') }}
run: brew install libpcap
- if: ${{ contains(inputs.os, 'windows') }}
run: |
Invoke-WebRequest -Uri "https://npcap.com/dist/npcap-sdk-1.13.zip" -OutFile "C:/npcap-sdk.zip"
Expand-Archive -LiteralPath C:/npcap-sdk.zip -DestinationPath C:/npcap-sdk
echo "LIB=C:/npcap-sdk/Lib/x64" >> $env:GITHUB_ENV
- if: ${{ contains(inputs.os, 'windows') && (github.event_name != 'pull_request') }}
run: |
$SecPassword = ConvertTo-SecureString "${{ secrets.NPCAP_OEM_PASSWORD }}" -AsPlainText -Force
$CredObject = New-Object System.Management.Automation.PSCredential ("${{ secrets.NPCAP_OEM_USERNAME }}", $SecPassword)
Invoke-WebRequest -Uri "https://npcap.com/oem/dist/npcap-1.71-oem.exe" -OutFile C:/npcap-oem.exe -Credential $CredObject
C:/npcap-oem.exe /S
- run: |
rustup update --no-self-update stable
rustup default stable
rustup component add llvm-tools-preview
- if: ${{ contains(inputs.os, 'ubuntu') }}
run: >-
wget https://github.com/mozilla/grcov/releases/latest/download/grcov-x86_64-unknown-linux-gnu.tar.bz2 -qO- |
tar -xj -C ./
- if: ${{ contains(inputs.os, 'macos') }}
run: >-
wget https://github.com/mozilla/grcov/releases/latest/download/grcov-x86_64-apple-darwin.tar.bz2 -qO- |
tar -xj -C ./
- if: ${{ contains(inputs.os, 'windows') }}
run: |
Invoke-WebRequest -Uri "https://github.com/mozilla/grcov/releases/latest/download/grcov-x86_64-pc-windows-msvc.zip" -OutFile C:/grcov.zip
Expand-Archive -LiteralPath C:/grcov.zip -DestinationPath C:/
- run: cargo test ${{ env.PCAP_CI_TEST_TARGETS }} --no-fail-fast
- run: ${{ env.PCAP_CI_GRCOV_CMD }}
- run: ${{ env.PCAP_CI_COV_CMD }} --fail-under ${{ env.PCAP_CI_COV_FAIL_UNDER_NO_FEATURES }}
- if: ${{ contains(inputs.os, 'windows') }}
run: |
Remove-Item -Recurse -Force ./target/debug/coverage
Remove-Item -Recurse -Force ./target/debug/profraw
- if: ${{ ! contains(inputs.os, 'windows') }}
run: rm -rf ./target/debug/{coverage,profraw}
- run: cargo clean -p pcap
- run: cargo test ${{ env.PCAP_CI_TEST_TARGETS }} --all-features --no-fail-fast
- run: ${{ env.PCAP_CI_GRCOV_CMD }}
- run: ${{ env.PCAP_CI_COV_CMD }} --fail-under ${{ env.PCAP_CI_COV_FAIL_UNDER_ALL_FEATURES }}
- if: ${{ (github.event_name == 'push') && (github.ref == 'refs/heads/main') && contains(inputs.os, 'ubuntu') }}
uses: actions/checkout@v4
with:
clean: false
ref: coverage
- if: ${{ (github.event_name == 'push') && (github.ref == 'refs/heads/main') && contains(inputs.os, 'ubuntu') }}
run: |
rm -rf *.html badges src coverage.json
cp -r ./target/debug/coverage/* ./
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -A
git commit -m "Code coverage for "$(git rev-parse --short origin/main)
git push