Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate and publish code coverage reports in the CI #1947

Merged
merged 7 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ concurrency:
cancel-in-progress: true

env:
GIT_BRANCH: ${{ github.head_ref || github.ref_name }}
CARGO_TERM_COLOR: always
RUST_VERSION: 1.75.0
NIGHTLY_RUST_VERSION: nightly-2023-10-29
RUST_VERSION_FMT: nightly-2023-10-29
RUST_VERSION_COV: nightly-2024-06-05
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use a different version of rust nightly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to touch formatting in this PR. The branch coverage needs.a more recent nightly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. That makes sense. Do we have any issues for unifying them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a separate PR, maybe. I don't want to reformat the whole codebase here.

RUSTFLAGS: -D warnings
REGISTRY: ghcr.io
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 2
Expand All @@ -39,11 +41,11 @@ jobs:
- name: Install latest nightly
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.NIGHTLY_RUST_VERSION }}
toolchain: ${{ env.RUST_VERSION_FMT }}
components: rustfmt

- name: Rustfmt check
run: cargo +${{ env.NIGHTLY_RUST_VERSION }} fmt --all -- --check
run: cargo +${{ env.RUST_VERSION_FMT }} fmt --all -- --check

lint-toml-files:
runs-on: buildjet-4vcpu-ubuntu-2204
Expand Down Expand Up @@ -193,6 +195,48 @@ jobs:
check-repo: false
ignore-unpublished-changes: true

publish-codecov:
name: Publish code coverage report on GitHub pages branch
runs-on: buildjet-4vcpu-ubuntu-2204
needs:
- cargo-verifications
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the vm pr we have needs: -cargo. What's the difference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This workflow doesn't have cargo job. The closes equivalent is cargo-verifications.

permissions: # Write access to push changes to pages
contents: write
steps:
- uses: actions/checkout@v3
- name: Install latest Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION_COV }}
targets: wasm32-unknown-unknown

- name: Install cargo-llvm-codecov
uses: taiki-e/install-action@cargo-llvm-cov

- name: Code coverage report
run: cargo +${{ env.RUST_VERSION_COV }} llvm-cov --all-features --html --branch

- name: Checkout the repo again for pushing pages revision
uses: actions/checkout@v3
with:
ref: 'codecov-pages'
path: 'pages-branch'

- name: Push codecov report to pages branch
working-directory: ./pages-branch
run: |
export BRANCH_B64=$(echo -n "${{ env.GIT_BRANCH }}" | basenc --base64url)
git config user.email "2204863+Dentosal@users.noreply.github.com"
git config user.name "Dentosal"
cp -r ../target/llvm-cov/html "$BRANCH_B64"
python3 ../.github/workflows/scripts/generate_pages_index.py > index.html
git add .
git commit -m "Update codecov for ${{ env.GIT_BRANCH }}"
git push
export PAGES_URL="https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/$BRANCH_B64/index.html"
echo "$PAGES_URL"
echo "Codecov report $PAGES_URL" >> $GITHUB_STEP_SUMMARY

verifications-complete:
needs:
- cargo-verifications
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/scripts/generate_pages_index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!python3
# Generate index.html for code coverage pages

from glob import iglob
from base64 import urlsafe_b64encode, urlsafe_b64decode

master_path = urlsafe_b64encode(b"master").decode("utf-8")

print("<html><head><title>Code Coverage</title>")
print("<style>body { font-size: 1.2em }</style>")
print(f"</head><body><h1>Code coverage</h1>")
print(f"<h2>Per branch (<a href=\"{master_path}/index.html\">master</a>)</h2><ul>")
for path in sorted(list(iglob("*/index.html", recursive=True))):
name = urlsafe_b64decode(path.split("/")[0].encode()).decode()
style = "font-weight: bold" if name == "master" else ""
print(f'<li style="{style}"><a href="{path}">{name}</a></li>')
print("</ul></body></html>")
5 changes: 4 additions & 1 deletion tests/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use fuel_core_types::{
fuel_crypto::SecretKey,
fuel_tx::Input,
};
use itertools::Itertools;
use rand::{
rngs::StdRng,
SeedableRng,
Expand Down Expand Up @@ -134,6 +133,7 @@ async fn test_partitions_larger_groups(
num_validators: usize,
num_partitions: usize,
) {
use itertools::Itertools;
use std::collections::VecDeque;

// Create a random seed based on the test parameters.
Expand Down Expand Up @@ -218,7 +218,10 @@ async fn test_partitions_larger_groups(
}

#[tokio::test(flavor = "multi_thread")]
#[cfg(not(coverage))] // This test is too slow for coverage
async fn test_multiple_producers_different_keys() {
use itertools::Itertools;

// Create a random seed based on the test parameters.
let mut hasher = DefaultHasher::new();
let num_txs = 10;
Expand Down
10 changes: 5 additions & 5 deletions tests/tests/tx_gossip.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unexpected_cfgs)] // for cfg(coverage)

use fuel_core::p2p_test_helpers::{
make_nodes,
BootstrapSetup,
Expand All @@ -16,10 +18,7 @@ use fuel_core_types::{
*,
},
fuel_vm::*,
services::{
block_importer::SharedImportResult,
executor::TransactionExecutionResult,
},
services::block_importer::SharedImportResult,
};
use futures::StreamExt;
use rand::{
Expand Down Expand Up @@ -206,6 +205,7 @@ async fn test_tx_gossiping_invalid_txs(
}

#[tokio::test(flavor = "multi_thread")]
#[cfg(not(coverage))]
async fn test_tx_gossiping_reserved_nodes_invalid_txs() {
// Test verifies that gossiping of invalid transactions from reserved
// nodes doesn't decrease its reputation.
Expand All @@ -218,7 +218,7 @@ async fn test_tx_gossiping_reserved_nodes_invalid_txs() {
assert_eq!(result.tx_status.len(), 2);
assert!(matches!(
result.tx_status[0].result,
TransactionExecutionResult::Success { .. }
fuel_core_types::services::executor::TransactionExecutionResult::Success { .. }
));
}

Expand Down
Loading