Skip to content

Commit

Permalink
Github actions coverage (#5148)
Browse files Browse the repository at this point in the history
Jobs for coverage collections and upload to codecov for github PR's
Uses same test suit as test-linux-stable, splits tests into 5 parallel
jobs, uploads to codecov, generates report comment and status checks
(can be made required)
| | |
| --- | --- |
| <img width="640" alt="image"
src="https://github.com/user-attachments/assets/3790f255-27d1-46b9-8d25-2e40b3dcd844">
| <img width="764" alt="image"
src="https://github.com/user-attachments/assets/9e0c8cc7-3278-4b4e-9e28-d76cd57b9163">
|

Codecov behavior (required coverage, thresholds, comment info etc.) is
highly customizable via `.github/codecov.yaml`
([reference](https://docs.codecov.com/docs/codecovyml-reference))

Unfortunately, some tests are excluded because with `-C
instrument-coverage` they run very slowly, flaky, or fail (see [nextest
filter
expression](https://github.com/paritytech/polkadot-sdk/pull/5148/files#diff-b19504a9520a2498d03020108344d8e6d93d254d812bfa26247faaa7f55263d6R80)
of test-linux-stable-coverage). So for now, this workflow is optional,
and will only run for pr's with the `GHA-coverage` label
  • Loading branch information
AndWeHaveAPlan authored Sep 5, 2024
1 parent 49a6813 commit b9b34fb
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 11 deletions.
8 changes: 7 additions & 1 deletion .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ coverage:
project:
default:
target: 1.0
threshold: 2.0
threshold: 2.0

comment:
behavior: new

fixes:
- "/__w/polkadot-sdk/polkadot-sdk/::"
143 changes: 143 additions & 0 deletions .github/workflows/tests-linux-stable-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# GHA for test-linux-stable-int, test-linux-stable, test-linux-stable-oldkernel
name: tests linux stable coverage

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled]
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:

set-image:
# GitHub Actions allows using 'env' in a container context.
# However, env variables don't work for forks: https://github.com/orgs/community/discussions/44322
# This workaround sets the container image for each job using 'set-image' job output.
if: contains(github.event.label.name, 'GHA-coverage') || contains(github.event.pull_request.labels.*.name, 'GHA-coverage')
runs-on: ubuntu-latest
outputs:
IMAGE: ${{ steps.set_image.outputs.IMAGE }}
RUNNER: ${{ steps.set_runner.outputs.RUNNER }}
steps:
- name: Checkout
uses: actions/checkout@v4
- id: set_image
run: cat .github/env >> $GITHUB_OUTPUT
- id: set_runner
run: |
# Run merge queues on persistent runners
if [[ $GITHUB_REF_NAME == *"gh-readonly-queue"* ]]; then
echo "RUNNER=arc-runners-polkadot-sdk-beefy-persistent" >> $GITHUB_OUTPUT
else
echo "RUNNER=arc-runners-polkadot-sdk-beefy" >> $GITHUB_OUTPUT
fi
#
#
#
test-linux-stable-coverage:
needs: [set-image]
runs-on: ${{ needs.set-image.outputs.RUNNER }}
timeout-minutes: 120
container:
image: ${{ needs.set-image.outputs.IMAGE }}
env:
RUST_TOOLCHAIN: stable
# Enable debug assertions since we are running optimized builds for testing
# but still want to have debug assertions.
#
# -Cinstrument-coverage slows everything down but it is necessary for code coverage
# https://doc.rust-lang.org/rustc/instrument-coverage.html
RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings -Cinstrument-coverage"
LLVM_PROFILE_FILE: "/__w/polkadot-sdk/polkadot-sdk/target/coverage/cargo-test-${{ matrix.ci_node_index }}-%p-%m.profraw"
strategy:
fail-fast: false
matrix:
ci_node_index: [1, 2, 3, 4, 5]
ci_node_total: [5]
steps:
- name: Checkout
uses: actions/checkout@v4

- run: rustup component add llvm-tools-preview
- run: cargo install cargo-llvm-cov

- run: mkdir -p target/coverage

# Some tests are excluded because they run very slowly or fail with -Cinstrument-coverage
- name: run tests
run: >
time cargo llvm-cov nextest
--no-report --release
--workspace
--locked --no-fail-fast
--features try-runtime,ci-only-tests,experimental,riscv
--filter-expr "
!test(/.*benchmark.*/)
- test(/recovers_from_only_chunks_if_pov_large::case_1/)
- test(/participation_requests_reprioritized_for_newly_included/)
- test(/availability_is_recovered_from_chunks_if_no_group_provided::case_1/)
- test(/rejects_missing_inherent_digest/)
- test(/availability_is_recovered_from_chunks_even_if_backing_group_supplied_if_chunks_only::case_1/)
- test(/availability_is_recovered_from_chunks_if_no_group_provided::case_2/)
- test(/all_security_features_work/)
- test(/nonexistent_cache_dir/)
- test(/recovers_from_only_chunks_if_pov_large::case_3/)
- test(/recovers_from_only_chunks_if_pov_large::case_2/)
- test(/authoring_blocks/)
- test(/rejects_missing_seals/)
- test(/generate_chain_spec/)
- test(/get_preset/)
- test(/list_presets/)
- test(/tests::receive_rate_limit_is_enforced/)
- test(/polkadot-availability-recovery/)
"
--partition count:${{ matrix.ci_node_index }}/${{ matrix.ci_node_total }}
- name: generate report
run: cargo llvm-cov report --release --codecov --output-path coverage-${{ matrix.ci_node_index }}.lcov
- name: upload report
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ matrix.ci_node_index }}.lcov
path: coverage-${{ matrix.ci_node_index }}.lcov

#
#
# Upload to codecov
upload-reports:
needs: [test-linux-stable-coverage]
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: reports
pattern: coverage-report-*
merge-multiple: true
- run: ls -al reports/
- name: Upload to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
directory: reports
root_dir: /__w/polkadot-sdk/polkadot-sdk/

#
#
#
remove-label:
runs-on: ubuntu-latest
needs: [upload-reports]
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v2
- uses: actions-ecosystem/action-remove-labels@v1
with:
labels: GHA-coverage
7 changes: 3 additions & 4 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,7 @@ impl pallet_babe::Config for Runtime {
type WeightInfo = ();
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominators;
type KeyOwnerProof =
<Historical as KeyOwnerProofSystem<(KeyTypeId, pallet_babe::AuthorityId)>>::Proof;
type KeyOwnerProof = sp_session::MembershipProof;
type EquivocationReportSystem =
pallet_babe::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
}
Expand Down Expand Up @@ -1534,7 +1533,7 @@ impl pallet_grandpa::Config for Runtime {
type MaxAuthorities = MaxAuthorities;
type MaxNominators = MaxNominators;
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;
type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, GrandpaId)>>::Proof;
type KeyOwnerProof = sp_session::MembershipProof;
type EquivocationReportSystem =
pallet_grandpa::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
}
Expand Down Expand Up @@ -2614,7 +2613,7 @@ impl pallet_beefy::Config for Runtime {
type OnNewValidatorSet = MmrLeaf;
type AncestryHelper = MmrLeaf;
type WeightInfo = ();
type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, BeefyId)>>::Proof;
type KeyOwnerProof = sp_session::MembershipProof;
type EquivocationReportSystem =
pallet_beefy::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
}
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use frame_election_provider_support::{
};
use frame_support::{
derive_impl, parameter_types,
traits::{ConstU128, ConstU32, ConstU64, KeyOwnerProofSystem, OnInitialize},
traits::{ConstU128, ConstU32, ConstU64, OnInitialize},
};
use pallet_session::historical as pallet_session_historical;
use sp_consensus_babe::{AuthorityId, AuthorityPair, Randomness, Slot, VrfSignature};
use sp_core::{
crypto::{KeyTypeId, Pair, VrfSecret},
crypto::{Pair, VrfSecret},
U256,
};
use sp_io;
Expand Down Expand Up @@ -182,7 +182,7 @@ impl Config for Test {
type WeightInfo = ();
type MaxAuthorities = ConstU32<10>;
type MaxNominators = ConstU32<100>;
type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, AuthorityId)>>::Proof;
type KeyOwnerProof = sp_session::MembershipProof;
type EquivocationReportSystem =
super::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
}
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ use frame_election_provider_support::{
};
use frame_support::{
derive_impl, parameter_types,
traits::{ConstU128, ConstU32, ConstU64, KeyOwnerProofSystem, OnFinalize, OnInitialize},
traits::{ConstU128, ConstU32, ConstU64, OnFinalize, OnInitialize},
};
use pallet_session::historical as pallet_session_historical;
use sp_consensus_grandpa::{RoundNumber, SetId, GRANDPA_ENGINE_ID};
use sp_core::{crypto::KeyTypeId, H256};
use sp_core::H256;
use sp_keyring::Ed25519Keyring;
use sp_runtime::{
curve::PiecewiseLinear,
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Config for Test {
type MaxAuthorities = ConstU32<100>;
type MaxNominators = ConstU32<1000>;
type MaxSetIdSessionEntries = MaxSetIdSessionEntries;
type KeyOwnerProof = <Historical as KeyOwnerProofSystem<(KeyTypeId, AuthorityId)>>::Proof;
type KeyOwnerProof = sp_session::MembershipProof;
type EquivocationReportSystem =
super::EquivocationReportSystem<Self, Offences, Historical, ReportLongevity>;
}
Expand Down

0 comments on commit b9b34fb

Please sign in to comment.