Skip to content

Commit

Permalink
ci: enable coverage reports
Browse files Browse the repository at this point in the history
  • Loading branch information
kayagokalp committed Jun 25, 2024
1 parent acee544 commit ab99cc8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

env:
CARGO_TERM_COLOR: always
RUST_VERSION_COV: nightly-2024-06-05
REGISTRY: ghcr.io

jobs:
Expand All @@ -35,6 +36,45 @@ jobs:
sh_checker_comment: false
sh_checker_exclude: "src"

publish-codecov:
name: Publish code coverage report on GitHub pages branch
runs-on: ubuntu-latest
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 }}

- 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 "fuel-tooling@users.noreply.github.com"
git config user.name "tooling"
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
try-run-fuelup-init:
needs: cancel-previous-runs
if: github.event_name != 'release' || github.event.action != 'published'
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>")

0 comments on commit ab99cc8

Please sign in to comment.