-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With golang 1.20.x, we can build a binary with coverage support. " Cover Go 1.20 supports collecting code coverage profiles for programs (applications and integration tests), as opposed to just unit tests. To collect coverage data for a program, build it with go build's -cover flag, then run the resulting binary with the environment variable GOCOVERDIR set to an output directory for coverage profiles. See the 'coverage for integration tests' landing page for more on how to get started. For details on the design and implementation, see the proposal. " Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
- Loading branch information
Showing
6 changed files
with
171 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
name: Reusable stacker build for coverage | ||
on: | ||
workflow_call: | ||
inputs: | ||
# note >-, args needs to be strings to be used as inputs | ||
# for the reusable build.yaml workflow | ||
go-version: | ||
required: false | ||
type: string | ||
description: 'Stringified JSON object listing go versions' | ||
default: >- | ||
["1.20.x"] | ||
privilege-level: | ||
required: false | ||
type: string | ||
description: 'Stringified JSON object listing stacker privilege-level' | ||
default: >- | ||
["unpriv", "priv"] | ||
build-id: | ||
required: false | ||
type: string | ||
description: 'build-id' | ||
default: "${{ github.sha }}" | ||
slow-test: | ||
required: false | ||
type: boolean | ||
description: 'Should slow tests be run?' | ||
default: true | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
services: | ||
registry: | ||
image: ghcr.io/project-stacker/registry:2 | ||
ports: | ||
- 5000:5000 | ||
strategy: | ||
matrix: | ||
go-version: ${{fromJson(inputs.go-version)}} | ||
privilege-level: ${{fromJson(inputs.privilege-level)}} | ||
name: "golang ${{ matrix.go-version }} privilege ${{ matrix.privilege-level }}" | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Clean disk space | ||
uses: ./.github/actions/clean-runner | ||
- uses: benjlevesque/short-sha@v2.1 | ||
id: short-sha | ||
- name: Set up golang ${{ matrix.go-version }} | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: ${{ matrix.go-version }} | ||
- name: Setup Environment | ||
run: | | ||
gopath=$PWD/.build/gopath | ||
echo "GOPATH=$gopath" >> $GITHUB_ENV | ||
echo "GOCACHE=$gopath/gocache" >> $GITHUB_ENV | ||
echo "PATH=$gopath/bin:$PATH" >> $GITHUB_ENV | ||
echo "SLOW_TEST=${{inputs.slow-test}}" >> $GITHUB_ENV | ||
echo "STACKER_DOCKER_BASE=oci:$PWD/.build/oci-clone:" >> $GITHUB_ENV | ||
echo "PWD=$PWD" | ||
cat "$GITHUB_ENV" | ||
- name: install dependencies | ||
run: | | ||
./install-build-deps.sh | ||
echo "running kernel is: $(uname -a)" | ||
- name: docker-clone | ||
run: | | ||
make docker-clone "STACKER_DOCKER_BASE=docker://" CLONE_D="$PWD/.build/oci-clone" | ||
- name: Go-download | ||
run: | | ||
make go-download | ||
- name: Show disk usage before building the binaries | ||
uses: ./.github/actions/show-disk-usage | ||
- name: Build-level1 | ||
run: | | ||
make show-info | ||
make stacker-dynamic VERSION_FULL=${{ inputs.build-id }} | ||
- name: Show disk usage before running the tests | ||
if: always() | ||
uses: ./.github/actions/show-disk-usage | ||
- name: Build and test | ||
run: | | ||
export GOCOVERDIR=$(mktemp -d) | ||
make check-cov GOCOVERDIR=$GOCOVERDIR PRIVILEGE_LEVEL=${{ matrix.privilege-level }} | ||
go tool covdata textfmt -i $GOCOVERDIR -o coverage-${{ matrix.privilege-level }}.txt | ||
go tool covdata percent -i $GOCOVERDIR | ||
ls -altR | ||
env: | ||
REGISTRY_URL: localhost:5000 | ||
ZOT_HOST: localhost | ||
ZOT_PORT: 8080 | ||
- name: Show disk usage after running the tests | ||
if: always() | ||
uses: ./.github/actions/show-disk-usage | ||
- name: Upload code coverage | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
files: coverage-${{ matrix.privilege-level}}.txt | ||
- uses: actions/cache@v3 | ||
id: restore-build | ||
with: | ||
path: stacker | ||
key: ${{ inputs.build-id }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package stacker | ||
|
||
import "os" | ||
|
||
func isCoverageEnabled() bool { | ||
_, ok := os.LookupEnv("GOCOVERDIR") | ||
return ok | ||
} | ||
|
||
func getCoverageDir() string { | ||
val, ok := os.LookupEnv("GOCOVERDIR") | ||
if ok { | ||
return val | ||
} | ||
|
||
return "" | ||
} |