Skip to content

Build + Test Code Coverage #155

Build + Test Code Coverage

Build + Test Code Coverage #155

Workflow file for this run

name: Build + Test Code Coverage
on:
schedule:
- cron: '0 12 * * 0' # run on Sundays at 12
workflow_dispatch:
jobs:
Run:
strategy:
fail-fast: false
matrix:
test:
- CodeCov1
- CodeCov2
- CodeCov3
include:
- test: CodeCov1
args: first_piece
- test: CodeCov2
args: second_piece
- test: CodeCov3
args: third_piece
runs-on: ubuntu-22.04
steps:
- name: manually remove gcloud
shell: bash
run: |
gcloud_sdk_root=$(gcloud info --format='value(installation.sdk_root)')
gcloud_global_config=$(gcloud info --format='value(config.paths.global_config_dir)')
echo "will remove directory : $gcloud_sdk_root"
echo "will remove directory : $gcloud_global_config"
sudo rm -fr $gcloud_sdk_root
sudo rm -fr $gcloud_global_config
- name: same as 'large-packages' but without 'google-cloud-sdk'
shell: bash
run: |
sudo apt-get remove -y 'php.*'
sudo apt-get remove -y '^mongodb-.*'
sudo apt-get remove -y '^mysql-.*'
sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri
sudo apt-get autoremove -y
sudo apt-get clean
- name: Free Disk Space
uses: jlumbroso/free-disk-space@main
with:
tool-cache: true
large-packages: false
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- uses: taiki-e/install-action@cargo-llvm-cov
- uses: taiki-e/install-action@nextest
- uses: Swatinem/rust-cache@v2
- name: Remove possible stale artifacts
run: cargo llvm-cov clean --workspace
- name: Disk Space
run: df -h /
- name: Run test with coverage instrumentation
shell: bash
env:
MIN_TPS: 3
run: |
set +o pipefail
# fetch all package names
pkg_names=($(cargo build -p 2>&1 | grep ' ' | cut -c 5-))
# find splitting package indexes
num_pkgs=${#pkg_names[@]}
pkgs_split=$(expr $num_pkgs / 3)
last_splitting_point=$(($pkgs_split * 2))
# sets the packages to run for both code cov runs
first_piece=${pkg_names[@]:0:$pkgs_split}
second_piece=${pkg_names[@]:$pkgs_split:$pkgs_split}
third_piece=${pkg_names[@]:$last_splitting_point:$num_pkgs}
first_piece=$(echo $first_piece | xargs printf -- '-p %s\n')
second_piece=$(echo $second_piece | xargs printf -- '-p %s\n')
third_piece=$(echo $third_piece | xargs printf -- '-p %s\n')
echo $first_piece
echo $second_piece
echo $third_piece
set -o pipefail
echo $${{matrix.args}} | xargs cargo llvm-cov nextest --features=nimiq-zkp-component/test-prover
# Fixme: --doctest is not supported in stable. See:
# https://github.com/taiki-e/cargo-llvm-cov/tree/7448e48b438797efb446a98ebd8ff22d3fae5ebe#known-limitations
# run: cargo llvm-cov --features=nimiq-zkp-component/test-prover --doctests
- name: Disk Space
run: df -h /
- name: Generate coverage report
run: cargo llvm-cov report --lcov --output-path coverage.lcov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: coverage.lcov
fail_ci_if_error: true
flags: unittests
name: Nimiq code coverage
verbose: true