Skip to content

Commit

Permalink
Code coverage preparations (#4387)
Browse files Browse the repository at this point in the history
Added manual jobs for code coverage (triggered via `codecov-start` job):
 - **codecov-start** - initialize Codecov report for commit/pr
- **test-linux-stable-codecov** - perform `nextest run` and upload
coverage data parts
- **codecov-finish** - finalize uploading of data parts and generate
Codecov report

Coverage requires code to be built with `-C instrument-coverage` which
causes build errors (e .g. ```error[E0275]: overflow evaluating the
requirement `<mock::Test as pallet::Config>::KeyOwnerProof == _\` ```,
seems like related to
[2641](#2641)) and
unstable tests behavior
([example](https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6004731)).
This is where we'll nee the developers assistance

closing [[polkadot-sdk] Add code coverage
#902](paritytech/ci_cd#902)
  • Loading branch information
AndWeHaveAPlan authored May 7, 2024
1 parent 930b046 commit 1c8595a
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
coverage:
precision: 2
round: down
range: "1...100"
status:
project:
default:
target: 1.0
threshold: 2.0
107 changes: 107 additions & 0 deletions .gitlab/pipeline/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,113 @@
- job: job-starter
artifacts: false

#
#
#
.codecov-check:
script:
- >
if command -v codecovcli -h >/dev/null 2>&1; then
codecovcli --version;
else
echo "downloading codecovcli";
curl -s -o codecovcli https://cli.codecov.io/latest/linux/codecov;
chmod +x codecovcli;
mv codecovcli /usr/local/bin/codecovcli;
fi
#
- codecovcli --version

#
#
#
codecov-start:
stage: test
when: manual
allow_failure: false
extends:
- .kubernetes-env
- .common-refs
- .pipeline-stopper-artifacts
- .run-immediately
script:
- !reference [.codecov-check, script]
- >
if [ "$CI_COMMIT_REF_NAME" != "master" ]; then
codecovcli -v create-commit -t ${CODECOV_TOKEN} -r paritytech/polkadot-sdk --commit-sha ${CI_COMMIT_SHA} --fail-on-error --pr ${CI_COMMIT_REF_NAME} --git-service github;
codecovcli -v create-report -t ${CODECOV_TOKEN} -r paritytech/polkadot-sdk --commit-sha ${CI_COMMIT_SHA} --fail-on-error --pr ${CI_COMMIT_REF_NAME} --git-service github;
else
codecovcli -v create-commit -t ${CODECOV_TOKEN} -r paritytech/polkadot-sdk --commit-sha ${CI_COMMIT_SHA} --fail-on-error --git-service github;
codecovcli -v create-report -t ${CODECOV_TOKEN} -r paritytech/polkadot-sdk --commit-sha ${CI_COMMIT_SHA} --fail-on-error --git-service github;
fi
#
#
#
codecov-finish:
stage: test
extends:
- .kubernetes-env
- .common-refs
- .pipeline-stopper-artifacts
needs:
- test-linux-stable-codecov
script:
- !reference [.codecov-check, script]
- codecovcli -v create-report-results -t ${CODECOV_TOKEN} -r paritytech/polkadot-sdk --commit-sha ${CI_COMMIT_SHA} --git-service github
- codecovcli -v get-report-results -t ${CODECOV_TOKEN} -r paritytech/polkadot-sdk --commit-sha ${CI_COMMIT_SHA} --git-service github
- codecovcli -v send-notifications -t ${CODECOV_TOKEN} -r paritytech/polkadot-sdk --commit-sha ${CI_COMMIT_SHA} --git-service github

#
#
#
test-linux-stable-codecov:
stage: test
needs:
- codecov-start
extends:
- .docker-env
- .common-refs
- .pipeline-stopper-artifacts
variables:
CI_IMAGE: europe-docker.pkg.dev/parity-build/ci-images/ci-unified:bullseye-1.77.0
RUST_TOOLCHAIN: stable
RUSTFLAGS: "-Cdebug-assertions=y -Cinstrument-coverage"
LLVM_PROFILE_FILE: "target/coverage/cargo-test-${CI_NODE_INDEX}-%p-%m.profraw"
CARGO_INCREMENTAL: 0
FORKLIFT_BYPASS: "true"
parallel: 2
script:
# tools
- !reference [.codecov-check, script]
- rustup component add llvm-tools-preview
- mkdir -p target/coverage/result/
# Place real test call here
- >
time cargo nextest run -p polkadot \
--locked \
--release \
--no-fail-fast \
--partition count:${CI_NODE_INDEX}/${CI_NODE_TOTAL}
# generate and upload reports
- >
grcov \
target/coverage/ \
--binary-path ./target/release/ \
-s . \
-t lcov \
--branch \
-o target/coverage/result/report-${CI_NODE_INDEX}.lcov
- ls -l target/coverage/result/
- >
if [ "$CI_COMMIT_REF_NAME" != "master" ]; then
codecovcli -v do-upload -f target/coverage/result/report-${CI_NODE_INDEX}.lcov --disable-search -t ${CODECOV_TOKEN} -r paritytech/polkadot-sdk --commit-sha ${CI_COMMIT_SHA} --fail-on-error --pr ${CI_COMMIT_REF_NAME} --git-service github;
else
codecovcli -v do-upload -f target/coverage/result/report-${CI_NODE_INDEX}.lcov --disable-search -t ${CODECOV_TOKEN} -r paritytech/polkadot-sdk --commit-sha ${CI_COMMIT_SHA} --fail-on-error --git-service github;
fi
#

test-linux-stable:
stage: test
extends:
Expand Down

0 comments on commit 1c8595a

Please sign in to comment.