ci: Added code coverage tool #146
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rust | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
env: | |
CARGO_TERM_COLOR: always | |
SQLX_OFFLINE: "true" | |
jobs: | |
unit-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
save-if: ${{ github.ref == 'refs/head/main' }} | |
shared-key: "main" | |
- name: Install cargo-llvm-cov | |
uses: taiki-e/install-action@cargo-llvm-cov | |
- name: Run unit tests | |
run: cargo llvm-cov test --verbose --lib --cobertura --output-path unit-tests.cobertura.xml | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: unit-tests.cobertura.xml | |
path: unit-tests.cobertura.xml | |
integration-tests: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
save-if: ${{ github.ref == 'refs/head/main' }} | |
shared-key: "main" | |
- name: Install cargo-llvm-cov | |
uses: taiki-e/install-action@cargo-llvm-cov | |
- name: Start containers | |
run: docker compose up -d | |
- name: Install self signed certificate | |
run: | | |
until [ -f ./resources/test/certs/cert.pem ]; do sleep 1; done | |
sudo cp ./resources/test/certs/cert.pem /usr/local/share/ca-certificates/localhost.crt && sudo update-ca-certificates | |
timeout-minutes: 1 | |
- name: Run integration tests | |
run: cargo llvm-cov test --verbose --test '*' --cobertura --output-path integration-tests.cobertura.xml | |
env: | |
AWS_ACCESS_KEY_ID: minioadmin | |
AWS_SECRET_ACCESS_KEY: minioadmin | |
AWS_REGION: us-east-1 | |
RUSTFLAGS: "-C instrument-coverage" | |
- name: Stop containers | |
if: always() | |
run: docker compose down | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: integration-tests.cobertura.xml | |
path: integration-tests.cobertura.xml | |
coverage: | |
runs-on: ubuntu-latest | |
needs: [unit-tests, integration-tests] | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/download-artifact@master | |
with: | |
name: unit-tests.cobertura.xml | |
path: coverage | |
- uses: actions/download-artifact@master | |
with: | |
name: integration-tests.cobertura.xml | |
path: coverage | |
- name: Code Coverage Report | |
uses: irongut/CodeCoverageSummary@v1.3.0 | |
with: | |
filename: coverage/*.cobertura.xml | |
badge: true | |
fail_below_min: false | |
format: markdown | |
hide_branch_rate: false | |
hide_complexity: false | |
indicators: true | |
output: both | |
thresholds: '55 75' | |
- name: Add Coverage PR Comment | |
uses: marocchino/sticky-pull-request-comment@v2 | |
if: github.event_name == 'pull_request' | |
with: | |
recreate: true | |
path: code-coverage-results.md | |
build-release: | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build final release binary | |
run: ./scripts/release | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: terrashine-binary | |
path: target/release/terrashine |