Skip to content

Commit

Permalink
ci: Enable code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
emgrav committed Oct 25, 2024
1 parent 6b54d85 commit 94995e5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 51 deletions.
9 changes: 9 additions & 0 deletions .codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
coverage:
status:
project:
default:
# Do not pass if PR reduces coverage by more than 5%
target: auto
threshold: 5
comment:
layout: "header, diff, components, files, footer"
6 changes: 6 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[profile.ci]
fail-fast = false
[profile.ci.junit]
path = "junit.xml"
store-success-output = true
store-failure-output = true
72 changes: 21 additions & 51 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ env:
SQLX_OFFLINE: "true"
jobs:
check:
runs-on: ubuntu-latest-16core
container: ghcr.io/famedly/rust-container:nightly
runs-on: ubuntu-latest
container: docker-oss.nexus.famedly.de/rust-container:nightly
name: Formatting, lints, syntax, and typos
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: famedly/backend-build-workflows/.github/actions/rust-prepare@main
with:
gitlab_user: ${{ secrets.GITLAB_USER }}
gitlab_pass: ${{ secrets.GITLAB_PASS }}
gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY}}

- name: Caching
uses: Swatinem/rust-cache@b8a6852b4f997182bdea832df3f9e153038b5191
uses: Swatinem/rust-cache@68b3cb7503c78e67dae8373749990a220eb65352
with:
shared-key: "stable"

Expand All @@ -42,11 +42,11 @@ jobs:
SQLX_OFFLINE: "true"
run: |
cargo +${NIGHTLY_VERSION} fmt -- --check
cargo lints clippy --workspace --all-targets -- -D warnings
cargo clippy --workspace --all-targets -- -D warnings
test:
runs-on: ubuntu-latest-16core
container: ghcr.io/famedly/rust-container:nightly
runs-on: ubuntu-latest
container: docker-oss.nexus.famedly.de/rust-container:nightly
name: Tests and coverage
services:
postgres:
Expand All @@ -64,9 +64,7 @@ jobs:
- 5432:5432

steps:
- uses: actions/checkout@v3
with:
path: head
- uses: actions/checkout@v4

- uses: famedly/backend-build-workflows/.github/actions/rust-prepare@main
with:
Expand All @@ -75,70 +73,42 @@ jobs:
gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY}}

- name: Caching
uses: Swatinem/rust-cache@b8a6852b4f997182bdea832df3f9e153038b5191
uses: Swatinem/rust-cache@68b3cb7503c78e67dae8373749990a220eb65352
with:
shared-key: "stable"
workspaces: "head -> target"

- name: Test
shell: bash
working-directory: head
run: |
sqlx migrate run
cargo sqlx prepare --check -- --all-targets --all-features
cargo llvm-cov nextest --workspace --lcov --output-path $GITHUB_WORKSPACE/new-cov.lcov
cargo llvm-cov nextest --profile ci --workspace --lcov --output-path lcov.info
- name: Load base coverage results from cache
if: github.event_name == 'pull_request'
id: cache-coverage
uses: actions/cache@v3
- name: Codecov - Upload coverage
uses: codecov/codecov-action@v4
with:
path: ./old-cov.lcov
key: coverage-${{ github.event.pull_request.base.sha }}
token: ${{secrets.CODECOV_TOKEN}}
files: "lcov.info"

- name: Pull base
uses: actions/checkout@v3
if: github.event_name == 'pull_request' && steps.cache-coverage.outputs.cache-hit != 'true'
- name: Codecov - Upload test results
uses: codecov/test-results-action@v1
with:
ref: ${{ github.event.pull_request.base.ref }}
repository: ${{ github.event.pull_request.base.full_name }}
path: base

- name: Generate base coverage
if: github.event_name == 'pull_request' && steps.cache-coverage.outputs.cache-hit != 'true'
working-directory: base
run: |
sqlx migrate run
cargo sqlx prepare --check -- --all-targets --all-features
cargo llvm-cov nextest --workspace --lcov --output-path $GITHUB_WORKSPACE/old-cov.lcov
- name: Meow Coverage
id: coverage-report
uses: famedly/meow-coverage@main
if: github.event_name == 'pull_request'
with:
new-lcov-file: 'new-cov.lcov'
old-lcov-file: ${{ github.event_name == 'pull_request' && 'old-cov.lcov' || '' }}
source-prefix: 'src/'
pr-number: ${{ github.event_name == 'pull_request' && github.event.pull_request.number || '' }}
repo-name: ${{ github.repository }}
commit-id: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.event.after }}
github-token: ${{ secrets.GITHUB_TOKEN }}
token: ${{secrets.CODECOV_TOKEN}}

doc-test:
runs-on: ubuntu-latest-16core
runs-on: ubuntu-latest
container: ghcr.io/famedly/rust-container:nightly
name: Documentation tests
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: famedly/backend-build-workflows/.github/actions/rust-prepare@main
with:
gitlab_user: ${{ secrets.GITLAB_USER }}
gitlab_pass: ${{ secrets.GITLAB_PASS }}
gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY}}

- name: Caching
uses: Swatinem/rust-cache@b8a6852b4f997182bdea832df3f9e153038b5191
uses: Swatinem/rust-cache@68b3cb7503c78e67dae8373749990a220eb65352
with:
shared-key: "nightly"

Expand All @@ -162,7 +132,7 @@ jobs:
gitlab_ssh: ${{ secrets.CI_SSH_PRIVATE_KEY}}

- name: Caching
uses: Swatinem/rust-cache@b8a6852b4f997182bdea832df3f9e153038b5191
uses: Swatinem/rust-cache@68b3cb7503c78e67dae8373749990a220eb65352
with:
shared-key: "nightly"

Expand Down

0 comments on commit 94995e5

Please # to comment.