From 7242ce9316185f3bf560f16656ab58ba051b2111 Mon Sep 17 00:00:00 2001 From: Derek Nola Date: Tue, 29 Jun 2021 11:27:50 -0700 Subject: [PATCH] Redux: Add Unit Test Coverage to CI (#3524) * Added Github action to run unit tests and connect to Codecov Signed-off-by: dereknola --- .github/.codecov.yml | 9 +++++++++ .github/workflows/unitcoverage.yaml | 27 +++++++++++++++++++++++++++ scripts/test | 3 +++ scripts/test-unit | 2 ++ scripts/validate | 2 -- 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 .github/.codecov.yml create mode 100644 .github/workflows/unitcoverage.yaml create mode 100755 scripts/test-unit diff --git a/.github/.codecov.yml b/.github/.codecov.yml new file mode 100644 index 0000000000..b2b3d7d8aa --- /dev/null +++ b/.github/.codecov.yml @@ -0,0 +1,9 @@ +coverage: + status: + project: + default: false # disable the default status that measures entire project + pkg: # declare a new status context "pkg" + paths: + - pkg/* # only include coverage in "pkg/" folder + informational: true # Always pass check + patch: off # disable the commit only checks diff --git a/.github/workflows/unitcoverage.yaml b/.github/workflows/unitcoverage.yaml new file mode 100644 index 0000000000..d90885dacd --- /dev/null +++ b/.github/workflows/unitcoverage.yaml @@ -0,0 +1,27 @@ +name: Unit Test Coverage +on: [push, pull_request] +jobs: + test: + name: Unit Tests + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-18.04, ubuntu-20.04] + timeout-minutes: 20 + steps: + - name: Install Go + uses: actions/setup-go@v2 + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 1 + - name: Run Unit Tests + run: | + go test ./pkg/... -coverprofile coverage.out + go tool cover -func coverage.out + - name: Upload Results To Codecov + uses: codecov/codecov-action@v1 + with: + files: ./coverage.out + flags: unittests # optional + verbose: true # optional (default = false) diff --git a/scripts/test b/scripts/test index 57b9c88af3..7256c4b908 100755 --- a/scripts/test +++ b/scripts/test @@ -21,6 +21,7 @@ echo "Did test-run-basics $?" . ./scripts/test-run-compat echo "Did test-run-compat $?" + # --- [ "$ARCH" != 'amd64' ] && \ @@ -38,4 +39,6 @@ echo "Did test-run-sonobuoy $?" test-run-sonobuoy mysql test-run-sonobuoy postgres +. ./scripts/test-unit + exit 0 diff --git a/scripts/test-unit b/scripts/test-unit new file mode 100755 index 0000000000..730885c227 --- /dev/null +++ b/scripts/test-unit @@ -0,0 +1,2 @@ +#!/bin/bash +go test -cover -v ./pkg/... diff --git a/scripts/validate b/scripts/validate index cc96d8c689..098fc4e77b 100755 --- a/scripts/validate +++ b/scripts/validate @@ -32,5 +32,3 @@ if [ -n "$DIRTY" ]; then git diff exit 1 fi - -"${GO}" test -v ./pkg/...