Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
[sc-102926]: add basic code coverage support (#72)
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Stephens <[email protected]>
  • Loading branch information
patrick-stephens authored Aug 5, 2024
1 parent f12e042 commit 3aca1d8
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Unit testing and code coverage

on:
push:
branches:
- main
pull_request:

jobs:
unit-test:
name: Go unit test and code coverage
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install cmetrics library
run: |
curl -L https://github.com/fluent/cmetrics/releases/download/${CMETRICS_RELEASE}/cmetrics_${CMETRICS_VERSION}_${ARCH}-headers.deb --output cmetrics_${CMETRICS_VERSION}_${ARCH}-headers.deb
curl -L https://github.com/fluent/cmetrics/releases/download/${CMETRICS_RELEASE}/cmetrics_${CMETRICS_VERSION}_${ARCH}.deb --output cmetrics_${CMETRICS_VERSION}_${ARCH}.deb
sudo dpkg -i *.deb
shell: bash
env:
CMETRICS_VERSION: "0.9.1"
CMETRICS_RELEASE: "v0.9.1"
ARCH: "amd64"

- name: setup-go
uses: actions/setup-go@v5
with:
go-version: "^1.22"

- name: Test
run: go test -v -race -cover -covermode=atomic -coverprofile=coverage.txt ./...
shell: bash

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
file: coverage.txt
flags: unittest
verbose: true
36 changes: 36 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
coverage:
status:
project:
default:
# Each PR must increase coverage
target: auto
# This allows a 2% drop from the previous base commit coverage to cope with any jitter or flakes
threshold: 2%

github_checks:
annotations: true

comment:
layout: "header, diff, flags, components, files, footer" # show component info in the PR comment
require_changes: false # if true: only post the comment if coverage changes
require_base: false # [yes :: must have a base report to post]
require_head: true # [yes :: must have a head report to post]
show_carryforward_flags: true
show_critical_paths: true #new option to labeled critical files
hide_comment_details: true #collapse all the "detailed info" for the PR comment

component_management:
default_rules: # default rules that will be inherited by all components
statuses:
- type: project # in this case every component that does not have a status defined will have a project type one
target: auto
branches:
- "!main"

ignore:
- '**/*.md'
- '**/*.sh'
- '**/*.rb'
- '.github/**/*'
- 'examples/**/*'
- 'testing/**/*'

0 comments on commit 3aca1d8

Please sign in to comment.