From ccb6d3ffdd4c1eb0a50797a41bb595aa3fb8f66d Mon Sep 17 00:00:00 2001 From: Guillermo Perez Date: Tue, 2 Apr 2024 21:08:15 +0200 Subject: [PATCH] add code coverage to pipeline (#1745) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add code coverage to pipeline * exclude migrations * add codecov badge --------- Co-authored-by: William Freudenberger Co-authored-by: Luis Enrique Muñoz Martín --- .github/actions/prep-ubuntu/action.yml | 2 +- .github/workflows/codecov.yml | 51 +++++++++++++++++++ .../xperimental-codecov.yml.commented | 44 ---------------- README.md | 1 + 4 files changed, 53 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/codecov.yml delete mode 100644 .github/workflows/xperimental-codecov.yml.commented diff --git a/.github/actions/prep-ubuntu/action.yml b/.github/actions/prep-ubuntu/action.yml index 45f3065c0f..16efb5e82e 100644 --- a/.github/actions/prep-ubuntu/action.yml +++ b/.github/actions/prep-ubuntu/action.yml @@ -31,7 +31,7 @@ runs: - name: Disable cache on forks and dependabot if: github.event_name == 'pull_request' - shell: sh + shell: bash run: | if [ "${{ github.event.pull_request.head.repo.fork }}" == "true" ] || \ [ "${{ github.actor }}" == "dependabot[bot]" ] || \ diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 0000000000..95438ad86f --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,51 @@ +on: + push: + branches: [main] + pull_request: +name: Code coverage +concurrency: + group: 'codecov-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true +permissions: + id-token: write + contents: read +jobs: + codecov: + runs-on: ubuntu-latest-8-cores + if: github.event.pull_request.draft == false || github.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@master + + - name: Prep build + uses: ./.github/actions/prep-ubuntu + with: + cache: enabled + # Cache needs Google credentials: + GWIP: ${{ secrets.GWIP_SCCACHE }} + GSA: ${{ secrets.GSA_SCCACHE }} + + - name: Install Tarpaulin + run: cargo install --locked cargo-tarpaulin + + - name: generate codecov reports + env: + RUST_BACKTRACE: 1 + run: | + cargo tarpaulin --timeout 300 -e runtime-integration-tests --features fast-runtime \ + --exclude-files runtime/*/src/migrations.rs --exclude-files runtime/common/src/migrations \ + --exclude-files pallets/rewards/src/migrations/new_instance.rs --exclude-files pallets/block-rewards/src/migrations.rs \ + --workspace --exclude-files **/mock.rs **/weights.rs **/weights/* --out xml + + # UPLOAD REPORTS (requires cargo 1.70.0) + - name: Upload to codecov.io + if: ${{ always() }} + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + with: + # token: ${{ secrets.CODECOV_TOKEN }} + # files: ./coverage1.xml,./coverage2.xml # optional + # flags: unittests # optional + # name: codecov-umbrella # optional + fail_ci_if_error: true # optional (default = false) + verbose: true # optional (default = false) diff --git a/.github/workflows/xperimental-codecov.yml.commented b/.github/workflows/xperimental-codecov.yml.commented deleted file mode 100644 index 6600aff7c0..0000000000 --- a/.github/workflows/xperimental-codecov.yml.commented +++ /dev/null @@ -1,44 +0,0 @@ -## THIS IS A WORK IN PROGRESS -on: - # push: - # branches: [main, 'release-v**'] - pull_request: -name: Sanity checks -concurrency: - group: 'tests-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' - cancel-in-progress: true -permissions: - id-token: write - contents: read -jobs: - codecov: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - # Tarpaulin requires cargo 1.70.0: - - name: generate codecov reports - run: | - if ${{ contains(matrix.target, 'test' ) }}; then - echo "---- GENERATE CODE COVERAGE ----" - echo "# Install Tarpaulin" - cargo install --locked cargo-tarpaulin - # make Cargo.toml - echo "Generate code coverage for ${{ matrix.target }}" - cargo +nightly tarpaulin --verbose --no-fail-fast --workspace --timeout 300 --out Xml - fi - - name: Runing cargo ${{ matrix.target }} - run: ./ci/run-check.sh - env: - TARGET: ${{ matrix.target }} - RUSTC_WRAPPER: "sccache" - - # UPLOAD REPORTS (requires cargo 1.70.0) - - name: Upload codecov report - uses: codecov/codecov-action@v3 - with: - # token: ${{ secrets.CODECOV_TOKEN }} - # files: ./coverage1.xml,./coverage2.xml # optional - # flags: unittests # optional - # name: codecov-umbrella # optional - # fail_ci_if_error: true # optional (default = false) - verbose: true # optional (default = false) diff --git a/README.md b/README.md index 01ad8309c3..66258e0772 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@
[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/centrifuge/centrifuge-chain/build-wasm.yml?label=Actions&logo=github)](https://github.com/centrifuge/centrifuge-chain/actions) +[![codecov](https://codecov.io/gh/centrifuge/centrifuge-chain/graph/badge.svg?token=RXlH3AJMRB)](https://codecov.io/gh/centrifuge/centrifuge-chain) [![GitHub Release](https://img.shields.io/github/v/release/centrifuge/centrifuge-chain)](https://github.com/centrifuge/centrifuge-chain/releases) [![Substrate version](https://img.shields.io/badge/Substrate-2.0.0-brightgreen?logo=Parity%20Substrate)](https://substrate.io/) [![License](https://img.shields.io/github/license/centrifuge/centrifuge-chain?color=green)](https://github.com/centrifuge/centrifuge-chain/blob/main/LICENSE)