Skip to content

Commit

Permalink
feat(ci): add coverage checks
Browse files Browse the repository at this point in the history
Signed-off-by: Riccardo Gallo <[email protected]>
  • Loading branch information
rgallor committed Aug 20, 2024
1 parent 3122838 commit 524bd54
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is part of Astarte.
#
# Copyright 2024 SECO Mind Srl
#
# SPDX-License-Identifier: Apache-2.0

# ref: https://docs.codecov.com/docs/codecovyml-reference
coverage:
range: 60..100
round: down
precision: 1
status:
# ref: https://docs.codecov.com/docs/commit-status
project:
default:
# Avoid false negatives
threshold: 1%

# Test files aren't important for coverage
ignore:
- "tests"
- "e2e-test"
- "benches"

# Make comments less noisy
comment:
layout: "files"
require_changes: yes
40 changes: 40 additions & 0 deletions .github/workflows/coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file is part of Astarte.
#
# Copyright 2024 SECO Mind Srl
#
# SPDX-License-Identifier: Apache-2.0

name: coverage
defaults:
run:
shell: bash
on:
workflow_run:
workflows: ["ci"]
types: [completed]
permissions:
contents: read
actions: read
jobs:
upload:
runs-on: ubuntu-latest
# Run only if originated from a PR
if: ${{ github.event.workflow_run.event == 'pull_request' }}
steps:
- name: Download coverage artifact
uses: actions/download-artifact@v4
with:
name: coverage
github-token: ${{ github.token }}
run-id: ${{ github.event.workflow_run.id }}
- name: Get PR number
run: |
echo "PR_NUMBER=$(cat ./pr_number)" >> "$GITHUB_ENV"
- name: Upload to codecov.io
uses: codecov/codecov-action@v4
with:
token: ${{secrets.CODECOV_TOKEN}}
fail_ci_if_error: true
override_branch: ${{ github.event.workflow_run.head_branch }}
override_commit: ${{ github.event.workflow_run.head_sha }}
override_pr: ${{ env.PR_NUMBER }}
40 changes: 40 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,43 @@ jobs:
run: cargo generate-lockfile
- name: cargo test
run: cargo test --locked --all-features --all-targets --workspace
coverage:
runs-on: ubuntu-latest
name: ubuntu / stable / coverage
steps:
- uses: actions/checkout@v4
- name: Install stable
uses: dtolnay/rust-toolchain@stable
with:
components: llvm-tools-preview
- name: Install sccache-cache
uses: mozilla-actions/[email protected]
- name: cargo install cargo-tarpaulin
uses: taiki-e/install-action@cargo-tarpaulin
- name: cargo generate-lockfile
if: hashFiles('Cargo.lock') == ''
run: cargo generate-lockfile
- name: Run cargo-tarpaulin with xml output
run: cargo tarpaulin --engine llvm --locked --all-features --ignore-tests --lib --out xml -- --test-threads 1
# Upload the coverage if we are not a PR from a fork, see ".github/workflows/coverage.yaml"
- name: Upload to codecov.io
if: ${{ github.event_name == 'push' }}
uses: codecov/codecov-action@v4
with:
token: ${{secrets.CODECOV_TOKEN}}
fail_ci_if_error: true
# Save data to use in workflow_run
- name: Save PR number
if: ${{ github.event_name == 'pull_request' }}
env:
PR_NUMBER: ${{ github.event.number }}
run: |
echo "$PR_NUMBER" > ./pr_number
- name: Upload coverage artifact
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v4
with:
name: coverage
path: |
pr_number
cobertura.xml
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file is part of Astarte.
//
// Copyright 2024 SECO Mind Srl
//
// SPDX-License-Identifier: Apache-2.0

0 comments on commit 524bd54

Please sign in to comment.