From 164441005ab605225f476def815491d1b4d96abc Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Tue, 28 May 2024 14:03:19 +0100 Subject: [PATCH 01/11] Add test coverage GH action --- .github/.testcoverage.yaml | 64 ++++++++++++++++++++++++ .github/workflows/porch-go-covergae.yaml | 58 +++++++++++++++++++++ .prow.yaml | 11 ---- README.md | 2 + default-go-test.mk | 19 ++++--- 5 files changed, 135 insertions(+), 19 deletions(-) create mode 100644 .github/.testcoverage.yaml create mode 100644 .github/workflows/porch-go-covergae.yaml delete mode 100644 .prow.yaml 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 From 5af9420791d528c7f9f61e2851e71204521caaae Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Tue, 28 May 2024 15:35:21 +0100 Subject: [PATCH 02/11] Update token for badge push --- .github/workflows/porch-go-covergae.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/porch-go-covergae.yaml b/.github/workflows/porch-go-covergae.yaml index 92bc3450..ace68d1f 100644 --- a/.github/workflows/porch-go-covergae.yaml +++ b/.github/workflows/porch-go-covergae.yaml @@ -55,4 +55,4 @@ jobs: # Configure action using config file (option 1) config: ./.github/.testcoverage.yaml git-branch: badges - git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }} + git-token: ${{ secrets.GITHUB_TOKEN }} From 893795346ae1426518c806af646ab6446812b9e3 Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Tue, 28 May 2024 16:50:17 +0100 Subject: [PATCH 03/11] Add more permissions on gh action --- .github/workflows/porch-go-covergae.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/porch-go-covergae.yaml b/.github/workflows/porch-go-covergae.yaml index ace68d1f..87695522 100644 --- a/.github/workflows/porch-go-covergae.yaml +++ b/.github/workflows/porch-go-covergae.yaml @@ -32,6 +32,8 @@ on: permissions: contents: write + pull-requests: write + repository-projects: write jobs: coverage: From ea1d283ed128f201e8f0637fc09c4a295578550a Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Tue, 28 May 2024 16:58:13 +0100 Subject: [PATCH 04/11] Lower the pass threshold to 40% --- .github/.testcoverage.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/.testcoverage.yaml b/.github/.testcoverage.yaml index 4f332b4c..f75adbe0 100644 --- a/.github/.testcoverage.yaml +++ b/.github/.testcoverage.yaml @@ -29,15 +29,15 @@ local-prefix: "github.com/nephio-project/porch" threshold: # (optional; default 0) # The minimum coverage that each file should have - file: 70 + file: 0 # (optional; default 0) # The minimum coverage that each package should have - package: 80 + package: 0 # (optional; default 0) # The minimum total coverage project should have - total: 80 + total: 40 # Holds regexp rules which will override thresholds for matched files or packages # using their paths. @@ -54,10 +54,10 @@ override: # 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` + # # 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 From a3c1fbaaa0e9ca8b4f820eb9d13e0779b641e493 Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Thu, 30 May 2024 08:18:14 +0100 Subject: [PATCH 05/11] Update .github/workflows/porch-go-covergae.yaml Co-authored-by: Rado Chmiel --- .github/workflows/porch-go-covergae.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/porch-go-covergae.yaml b/.github/workflows/porch-go-covergae.yaml index 87695522..a3f652f8 100644 --- a/.github/workflows/porch-go-covergae.yaml +++ b/.github/workflows/porch-go-covergae.yaml @@ -42,7 +42,12 @@ jobs: steps: - name: checkout repo uses: actions/checkout@v4 - + - uses: actions/create-github-app-token@v1 + id: generate-token + with: + app-id: ${{ secrets.HELPER_APP_ID }} + private-key: ${{ secrets.HELPER_APP_KEY }} + owner: ${{ github.repository_owner }} - name: setup go uses: actions/setup-go@v5 with: From e042372a74370bf5c5c3d9fa562aeb7ca2d83d23 Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Thu, 30 May 2024 08:18:21 +0100 Subject: [PATCH 06/11] Update .github/workflows/porch-go-covergae.yaml Co-authored-by: Rado Chmiel --- .github/workflows/porch-go-covergae.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/porch-go-covergae.yaml b/.github/workflows/porch-go-covergae.yaml index a3f652f8..8e971f8e 100644 --- a/.github/workflows/porch-go-covergae.yaml +++ b/.github/workflows/porch-go-covergae.yaml @@ -62,4 +62,4 @@ jobs: # Configure action using config file (option 1) config: ./.github/.testcoverage.yaml git-branch: badges - git-token: ${{ secrets.GITHUB_TOKEN }} + git-token: ${{ steps.generate-token.outputs.token }} From 40439068494a3ef4f4486b9834e6deca9004c4e0 Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Thu, 30 May 2024 08:20:20 +0100 Subject: [PATCH 07/11] Update porch-go-covergae.yaml --- .github/workflows/porch-go-covergae.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/porch-go-covergae.yaml b/.github/workflows/porch-go-covergae.yaml index 8e971f8e..ccc6ff62 100644 --- a/.github/workflows/porch-go-covergae.yaml +++ b/.github/workflows/porch-go-covergae.yaml @@ -42,7 +42,7 @@ jobs: steps: - name: checkout repo uses: actions/checkout@v4 - - uses: actions/create-github-app-token@v1 + - uses: actions/create-github-app-token@v1 id: generate-token with: app-id: ${{ secrets.HELPER_APP_ID }} From 373dc50e608cf2550c3ef4cfad39599e95bbe6c0 Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Thu, 30 May 2024 08:31:31 +0100 Subject: [PATCH 08/11] Update .github/workflows/porch-go-covergae.yaml Co-authored-by: Rado Chmiel --- .github/workflows/porch-go-covergae.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/porch-go-covergae.yaml b/.github/workflows/porch-go-covergae.yaml index ccc6ff62..71bfae89 100644 --- a/.github/workflows/porch-go-covergae.yaml +++ b/.github/workflows/porch-go-covergae.yaml @@ -45,7 +45,7 @@ jobs: - uses: actions/create-github-app-token@v1 id: generate-token with: - app-id: ${{ secrets.HELPER_APP_ID }} + app-id: ${{ vars.HELPER_APP_ID }} private-key: ${{ secrets.HELPER_APP_KEY }} owner: ${{ github.repository_owner }} - name: setup go From c0e30018c53a0e3332f3d83a81a3d5dd8ef9b021 Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Thu, 30 May 2024 08:50:07 +0100 Subject: [PATCH 09/11] Update .github/workflows/porch-go-covergae.yaml Co-authored-by: Rado Chmiel --- .github/workflows/porch-go-covergae.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/porch-go-covergae.yaml b/.github/workflows/porch-go-covergae.yaml index 71bfae89..4300683e 100644 --- a/.github/workflows/porch-go-covergae.yaml +++ b/.github/workflows/porch-go-covergae.yaml @@ -47,7 +47,6 @@ jobs: with: app-id: ${{ vars.HELPER_APP_ID }} private-key: ${{ secrets.HELPER_APP_KEY }} - owner: ${{ github.repository_owner }} - name: setup go uses: actions/setup-go@v5 with: From e5bb05ff6d8e444be5b9d3d5cabdf638a7353d60 Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Thu, 30 May 2024 09:04:42 +0100 Subject: [PATCH 10/11] Update .github/workflows/porch-go-covergae.yaml Co-authored-by: Rado Chmiel --- .github/workflows/porch-go-covergae.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/porch-go-covergae.yaml b/.github/workflows/porch-go-covergae.yaml index 4300683e..9f526dbf 100644 --- a/.github/workflows/porch-go-covergae.yaml +++ b/.github/workflows/porch-go-covergae.yaml @@ -45,7 +45,7 @@ jobs: - uses: actions/create-github-app-token@v1 id: generate-token with: - app-id: ${{ vars.HELPER_APP_ID }} + app-id: 897412 private-key: ${{ secrets.HELPER_APP_KEY }} - name: setup go uses: actions/setup-go@v5 From 37d8933638955ed0a41ca3f72e6eaa099936e717 Mon Sep 17 00:00:00 2001 From: Fiachra Corcoran Date: Thu, 30 May 2024 09:43:02 +0100 Subject: [PATCH 11/11] Update porch-go-covergae.yaml --- .github/workflows/porch-go-covergae.yaml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/porch-go-covergae.yaml b/.github/workflows/porch-go-covergae.yaml index 9f526dbf..2a41861b 100644 --- a/.github/workflows/porch-go-covergae.yaml +++ b/.github/workflows/porch-go-covergae.yaml @@ -30,11 +30,6 @@ on: - "release/**" - "scripts/**" -permissions: - contents: write - pull-requests: write - repository-projects: write - jobs: coverage: name: Go test coverage check