|
| 1 | +--- |
| 2 | +name: Code Coverage |
| 3 | +"on": |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - trunk |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - trunk |
| 10 | +jobs: |
| 11 | + generate: |
| 12 | + name: Generate |
| 13 | + permissions: |
| 14 | + id-token: write |
| 15 | + contents: read |
| 16 | + runs-on: ubuntu-latest |
| 17 | + env: |
| 18 | + RUST_BACKTRACE: 1 |
| 19 | + CARGO_NET_GIT_FETCH_WITH_CLI: true |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v3 |
| 23 | + |
| 24 | + - name: Install Rust toolchain |
| 25 | + uses: actions-rs/toolchain@v1 |
| 26 | + with: |
| 27 | + toolchain: nightly |
| 28 | + profile: minimal |
| 29 | + override: true |
| 30 | + components: llvm-tools-preview |
| 31 | + |
| 32 | + - name: Setup grcov |
| 33 | + run: | |
| 34 | + release_url="$(curl \ |
| 35 | + -H "Accept: application/vnd.github.v3+json" \ |
| 36 | + https://api.github.com/repos/mozilla/grcov/releases | \ |
| 37 | + jq -r '.[0].assets | map(select(.browser_download_url | test(".*x86_64-unknown-linux-musl.tar.bz2$"))) | .[0].browser_download_url')" |
| 38 | +
|
| 39 | + curl -sL "$release_url" | sudo tar xvj -C /usr/local/bin/ |
| 40 | +
|
| 41 | + - name: Generate coverage |
| 42 | + env: |
| 43 | + LLVM_PROFILE_FILE: "posix-space-%m.profraw" |
| 44 | + RUSTFLAGS: "-C instrument-coverage" |
| 45 | + # Unstable feature: https://github.com/rust-lang/rust/issues/56925 |
| 46 | + RUSTDOCFLAGS: "-C instrument-coverage -Z unstable-options --persist-doctests target/debug/doctests" |
| 47 | + run: | |
| 48 | + cargo +nightly test --lib |
| 49 | + cargo +nightly test --doc |
| 50 | +
|
| 51 | + - name: Generate HTML report |
| 52 | + run: grcov posix-space*.profraw --source-dir . --binary-path target/debug -t html --filter covered -o target/coverage |
| 53 | + |
| 54 | + - name: Generate detailed JSON report |
| 55 | + run: grcov posix-space*.profraw --source-dir . --binary-path target/debug -t covdir --filter covered -o target/coverage/coverage.json |
| 56 | + |
| 57 | + - name: Configure AWS Credentials |
| 58 | + uses: aws-actions/configure-aws-credentials@master |
| 59 | + if: github.ref == 'refs/heads/trunk' |
| 60 | + with: |
| 61 | + aws-region: us-west-2 |
| 62 | + role-to-assume: arn:aws:iam::447522982029:role/gha-posix-space-s3-backup-20220820215201568100000009 |
| 63 | + role-session-name: GitHubActionsRustCodeCoverage@posix-space |
| 64 | + |
| 65 | + - name: Show AWS caller identity |
| 66 | + if: github.ref == 'refs/heads/trunk' |
| 67 | + run: aws sts get-caller-identity |
| 68 | + |
| 69 | + - name: Upload archives to S3 |
| 70 | + if: github.ref == 'refs/heads/trunk' |
| 71 | + run: | |
| 72 | + aws s3 sync target/coverage/ s3://artichoke-forge-code-coverage-us-west-2/posix-space/ --delete --sse AES256 --exclude '*' --include '*.svg' --content-type 'image/svg+xml' |
| 73 | + aws s3 sync target/coverage/ s3://artichoke-forge-code-coverage-us-west-2/posix-space/ --delete --sse AES256 --exclude '*' --include '*.html' --content-type 'text/html' |
| 74 | + aws s3 sync target/coverage/ s3://artichoke-forge-code-coverage-us-west-2/posix-space/ --delete --sse AES256 --exclude '*' --include '*.json' --content-type 'application/json' |
| 75 | + aws s3 sync target/coverage/ s3://artichoke-forge-code-coverage-us-west-2/posix-space/ --delete --sse AES256 --include '*' --exclude '*.svg' --exclude '*.html' --exclude '*.json' |
| 76 | +
|
| 77 | + - name: Check missed lines |
| 78 | + run: | |
| 79 | + curl -s https://codecov.artichokeruby.org/posix-space/coverage.json | python -c '\ |
| 80 | + import sys, json; \ |
| 81 | + \ |
| 82 | + trunk_coverage = json.loads(sys.stdin.read()); \ |
| 83 | + print("On trunk: "); \ |
| 84 | + print("coveragePercent =", trunk_coverage["coveragePercent"]); \ |
| 85 | + print("linesCovered =", trunk_coverage["linesCovered"]); \ |
| 86 | + print("linesMissed =", trunk_coverage["linesMissed"]); \ |
| 87 | + print("linesTotal =", trunk_coverage["linesTotal"]); \ |
| 88 | + print(""); \ |
| 89 | + \ |
| 90 | + branch_coverage = json.load(open("target/coverage/coverage.json")) |
| 91 | + print("On PR branch: "); \ |
| 92 | + print("coveragePercent =", branch_coverage["coveragePercent"]); \ |
| 93 | + print("linesCovered =", branch_coverage["linesCovered"]); \ |
| 94 | + print("linesMissed =", branch_coverage["linesMissed"]); \ |
| 95 | + print("linesTotal =", branch_coverage["linesTotal"]); \ |
| 96 | + print(""); \ |
| 97 | + \ |
| 98 | + is_ok = branch_coverage["linesMissed"] <= trunk_coverage["linesMissed"]; \ |
| 99 | + exit(0) if is_ok else exit(1) \ |
| 100 | + ' |
0 commit comments