|
| 1 | +on: |
| 2 | + pull_request: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + |
| 7 | +name: Test with Code Coverage |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + name: Test |
| 12 | + env: |
| 13 | + PROJECT_NAME_UNDERSCORE: rust_ci_github_actions_workflow |
| 14 | + CARGO_INCREMENTAL: 0 |
| 15 | + RUSTFLAGS: -Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort |
| 16 | + RUSTDOCFLAGS: -Cpanic=abort |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - uses: actions/checkout@v2 |
| 20 | + - uses: actions-rs/toolchain@v1 |
| 21 | + with: |
| 22 | + profile: minimal |
| 23 | + toolchain: nightly |
| 24 | + override: true |
| 25 | + - name: Cache dependencies |
| 26 | + uses: actions/cache@v2 |
| 27 | + env: |
| 28 | + cache-name: cache-dependencies |
| 29 | + with: |
| 30 | + path: | |
| 31 | + ~/.cargo/.crates.toml |
| 32 | + ~/.cargo/.crates2.json |
| 33 | + ~/.cargo/bin |
| 34 | + ~/.cargo/registry/index |
| 35 | + ~/.cargo/registry/cache |
| 36 | + target |
| 37 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Cargo.lock') }} |
| 38 | + - name: Generate test result and coverage report |
| 39 | + run: | |
| 40 | + cargo install cargo2junit grcov rust-covfix; |
| 41 | + cargo test --features coverage $CARGO_OPTIONS -- -Z unstable-options --format json | cargo2junit > results.xml; |
| 42 | + zip -0 ccov.zip `find . \( -name "$PROJECT_NAME_UNDERSCORE*.gc*" \) -print`; |
| 43 | + grcov ccov.zip -s . -t lcov --llvm --branch --ignore-not-existing --ignore "/*" --ignore "tests/*" -o lcov.info; |
| 44 | + rust-covfix -o lcov_correct.info lcov.info; |
| 45 | + - name: Upload test results |
| 46 | + uses: EnricoMi/publish-unit-test-result-action@v1 |
| 47 | + with: |
| 48 | + check_name: Test Results |
| 49 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 50 | + files: results.xml |
| 51 | + - name: Upload to CodeCov |
| 52 | + uses: codecov/codecov-action@v1 |
| 53 | + with: |
| 54 | + # required for private repositories: |
| 55 | + # token: ${{ secrets.CODECOV_TOKEN }} |
| 56 | + files: ./lcov_correct.info |
| 57 | + fail_ci_if_error: true |
0 commit comments