diff --git a/.github/.testcoverage.yaml b/.github/.testcoverage.yaml new file mode 100644 index 00000000..4f332b4c --- /dev/null +++ b/.github/.testcoverage.yaml @@ -0,0 +1,64 @@ +# Copyright 2024 The Nephio Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# (mandatory) +# Path to coverprofile file (output of `go test -coverprofile` command). +# +# For cases where there are many coverage profiles, such as when running +# unit tests and integration tests separately, you can combine all those +# profiles into one. In this case, the profile should have a comma-separated list +# of profile files, e.g., 'cover_unit.out,cover_integration.out'. +profile: lcov.info + +# (optional; but recommended to set) +# When specified reported file paths will not contain local prefix in the output +local-prefix: "github.com/nephio-project/porch" + +# Holds coverage thresholds percentages, values should be in range [0-100] +threshold: + # (optional; default 0) + # The minimum coverage that each file should have + file: 70 + + # (optional; default 0) + # The minimum coverage that each package should have + package: 80 + + # (optional; default 0) + # The minimum total coverage project should have + total: 80 + +# Holds regexp rules which will override thresholds for matched files or packages +# using their paths. +# +# First rule from this list that matches file or package is going to apply +# new threshold to it. If project has multiple rules that match same path, +# override rules should be listed in order from specific to more general rules. +override: + # # Increase coverage threshold to 100% for `foo` package + # # (default is 80, as configured above in this example) + # - threshold: 100 + # path: ^pkg/lib/foo$ + +# Holds regexp rules which will exclude matched files or packages +# from coverage statistics +exclude: + # Exclude files or packages matching their paths + paths: + - \.pb\.go$ # excludes all protobuf generated files + - ^pkg/bar # exclude package `pkg/bar` + +# NOTES: +# - symbol `/` in all path regexps will be replaced by current OS file path separator +# to properly work on Windows \ No newline at end of file diff --git a/.github/workflows/porch-go-covergae.yaml b/.github/workflows/porch-go-covergae.yaml new file mode 100644 index 00000000..92bc3450 --- /dev/null +++ b/.github/workflows/porch-go-covergae.yaml @@ -0,0 +1,58 @@ +# Copyright 2024 The Nephio Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +name: "Go test coverage" +on: + push: + paths-ignore: + - "build/**" + - "deployments/**" + - "docs/**" + - "examples/**" + - "release/**" + - "scripts/**" + pull_request: + paths-ignore: + - "build/**" + - "deployments/**" + - "docs/**" + - "examples/**" + - "release/**" + - "scripts/**" + +permissions: + contents: write + +jobs: + coverage: + name: Go test coverage check + runs-on: ubuntu-latest + steps: + - name: checkout repo + uses: actions/checkout@v4 + + - name: setup go + uses: actions/setup-go@v5 + with: + go-version: '1.22.2' + + - name: generate test coverage + run: make test + + - name: check test coverage + uses: vladopajic/go-test-coverage@v2 + with: + # Configure action using config file (option 1) + config: ./.github/.testcoverage.yaml + git-branch: badges + git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }} diff --git a/.prow.yaml b/.prow.yaml deleted file mode 100644 index 2849fd39..00000000 --- a/.prow.yaml +++ /dev/null @@ -1,11 +0,0 @@ -presubmits: - - name: presubmit-nephio-go-test - decorate: true - run_if_changed: "(\\.go|Makefile|\\.mk)$" - spec: - containers: - - image: nephio/gotests:1782782171367346176 - command: - - make - args: - - ci-unit diff --git a/README.md b/README.md index e7d14032..97befafb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Package Orchestration Server +[![coverage](https://raw.githubusercontent.com/nephio-project/porch/badges/.badges/main/coverage.svg)](/.github/.testcoverage.yaml) + Package Orchestration Server (a.k.a. Porch) is a k8s extension apiserver which manages the lifecycle of KRM configuration packages. diff --git a/default-go-test.mk b/default-go-test.mk index da976f13..985f19bb 100644 --- a/default-go-test.mk +++ b/default-go-test.mk @@ -1,4 +1,4 @@ -# Copyright 2023 The Nephio Authors. +# Copyright 2023-2024 The Nephio Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,6 +14,7 @@ GO_VERSION ?= 1.22.2 TEST_COVERAGE_FILE=lcov.info +TEST_COVERAGE_TMP_FILE=lcov.tmp.info TEST_COVERAGE_HTML_FILE=coverage_unit.html TEST_COVERAGE_FUNC_FILE=func_coverage.out GIT_ROOT_DIR ?= $(dir $(lastword $(MAKEFILE_LIST))) @@ -26,13 +27,15 @@ unit: test test: ## Run unit tests (go test) ifeq ($(CONTAINER_RUNNABLE), 0) $(RUN_CONTAINER_COMMAND) docker.io/nephio/gotests:1782782171367346176 \ - sh -e -c "git config --global --add user.name test; \ - git config --global --add user.email test@nephio.org; \ - go test ./... -v -coverprofile ${TEST_COVERAGE_FILE}; \ - go tool cover -html=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_HTML_FILE}; \ - go tool cover -func=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_FUNC_FILE}" + sh -e -c "git config --global --add user.name test; \ + git config --global --add user.email test@nephio.org; \ + go test ./... -v -covermode=atomic -coverpkg=./... -coverprofile ${TEST_COVERAGE_TMP_FILE}; \ + cat ${TEST_COVERAGE_TMP_FILE} | grep -v 'test\|api' > ${TEST_COVERAGE_FILE}; \ + go tool cover -html=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_HTML_FILE}; \ + go tool cover -func=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_FUNC_FILE}" else - go test ./... -v -coverprofile ${TEST_COVERAGE_FILE} + go test ./... -v -covermode=atomic -coverpkg=./... -coverprofile ${TEST_COVERAGE_TMP_FILE}; \ + cat ${TEST_COVERAGE_TMP_FILE} | grep -v 'test\|api' > ${TEST_COVERAGE_FILE}; \ go tool cover -html=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_HTML_FILE} go tool cover -func=${TEST_COVERAGE_FILE} -o ${TEST_COVERAGE_FUNC_FILE} endif @@ -42,4 +45,4 @@ unit-clean: ## Clean up the artifacts created by the unit tests ifeq ($(CONTAINER_RUNNABLE), 0) $(CONTAINER_RUNTIME) system prune -f endif - rm -f ${TEST_COVERAGE_FILE} ${TEST_COVERAGE_HTML_FILE} ${TEST_COVERAGE_FUNC_FILE} > /dev/null 2>&1 + rm -f ${TEST_COVERAGE_TMP_FILE} ${TEST_COVERAGE_FILE} ${TEST_COVERAGE_HTML_FILE} ${TEST_COVERAGE_FUNC_FILE} > /dev/null 2>&1