diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3881c99e1..8cac5c1a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,7 @@ on: env: CARGO_TERM_COLOR: always + RUST_VERSION_COV: nightly-2024-06-05 REGISTRY: ghcr.io jobs: @@ -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' diff --git a/.github/workflows/scripts/generate_pages_index.py b/.github/workflows/scripts/generate_pages_index.py new file mode 100644 index 000000000..f2b2c91a1 --- /dev/null +++ b/.github/workflows/scripts/generate_pages_index.py @@ -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("Code Coverage") +print("") +print(f"

Code coverage

") +print(f"

Per branch (master)

")