From 3aca1d8a4a2a9ad613e659b939862c28b2f49ebe Mon Sep 17 00:00:00 2001 From: Pat Date: Mon, 5 Aug 2024 05:49:06 -0400 Subject: [PATCH] [sc-102926]: add basic code coverage support (#72) Signed-off-by: Patrick Stephens --- .github/workflows/unit-test.yaml | 46 ++++++++++++++++++++++++++++++++ codecov.yml | 36 +++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 .github/workflows/unit-test.yaml create mode 100644 codecov.yml diff --git a/.github/workflows/unit-test.yaml b/.github/workflows/unit-test.yaml new file mode 100644 index 0000000..55ea778 --- /dev/null +++ b/.github/workflows/unit-test.yaml @@ -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 diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..01a6aac --- /dev/null +++ b/codecov.yml @@ -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/**/*'