From 47437b6c165e0a537806d2d51f2438db202ce226 Mon Sep 17 00:00:00 2001 From: mehabhalodiya Date: Tue, 29 Aug 2023 16:13:47 +0530 Subject: [PATCH 1/4] Add codecov workflow Signed-off-by: mehabhalodiya --- .codecov.yml | 8 ++++++ .github/workflows/pr-checks.yml | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 .codecov.yml create mode 100644 .github/workflows/pr-checks.yml diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 000000000..4a0a11bd2 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,8 @@ +coverage: + status: + patch: off + project: + default: + target: auto + threshold: 0.2% + removed_code_behavior: adjust_base diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml new file mode 100644 index 000000000..db65d8fd7 --- /dev/null +++ b/.github/workflows/pr-checks.yml @@ -0,0 +1,48 @@ +name: static checks +on: + workflow_dispatch: + push: + branches: + - "master" + pull_request: + branches: + - "*" + +jobs: + lint: + name: Code Quality + runs-on: ubuntu-20.04 + + steps: + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "^1.18" + + - name: Checkout repo + uses: actions/checkout@v3 + + unit: + name: Unit Tests with Code coverage + runs-on: ubuntu-20.04 + + steps: + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "^1.18" + + - name: Checkout Git Repository + uses: actions/checkout@v3 + + - name: Unit Tests with Code Coverage + run: | + make test + + - name: Upload Code Coverage Report + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: cover.out + verbose: true + fail_ci_if_error: true From 6cfe2c69c128d9e911af179c3b35a4a3c4f29a15 Mon Sep 17 00:00:00 2001 From: Meha Bhalodiya Date: Thu, 26 Oct 2023 17:06:08 +0530 Subject: [PATCH 2/4] remove token Signed-off-by: mehabhalodiya --- .github/workflows/pr-checks.yml | 39 ++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index db65d8fd7..59e047ed0 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -35,14 +35,37 @@ jobs: - name: Checkout Git Repository uses: actions/checkout@v3 - - name: Unit Tests with Code Coverage + - name: Run Go Tests + run: make test + + - name: Check format run: | - make test + if [[ $(go fmt `go list ./... | grep -v vendor`) ]]; then + echo "not well formatted sources are found" + exit 1 + fi - - name: Upload Code Coverage Report - uses: codecov/codecov-action@v3 + - name: Generate coverage report + run: | + go test `go list ./... | grep -v examples` -coverprofile=coverage.txt -covermode=atomic + + - name: Upload coverage report + uses: codecov/codecov-action@v1 + with: + file: ./coverage.txt + flags: unittests + name: codecov-umbrella + + - name: Get code coverage artifiact + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: code-coverage + - name: Get test result artifact + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: test-results + path: test-results + - name: Upload code coverage information to codecov.io + uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 with: - token: ${{ secrets.CODECOV_TOKEN }} - file: cover.out - verbose: true - fail_ci_if_error: true + file: coverage.out From 4ec2bded1012dfb9b7fe7dd071f07ef7479b8a83 Mon Sep 17 00:00:00 2001 From: mehabhalodiya Date: Tue, 23 Jan 2024 19:02:14 +0530 Subject: [PATCH 3/4] Modify PR checks Signed-off-by: mehabhalodiya --- .codecov.yml | 40 ++++++++++++++--- .github/workflows/pr-checks.yml | 77 +++++++++++++++++---------------- 2 files changed, 73 insertions(+), 44 deletions(-) diff --git a/.codecov.yml b/.codecov.yml index 4a0a11bd2..5a9bdf017 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,8 +1,36 @@ +# See http://docs.codecov.io/docs/coverage-configuration coverage: + precision: 2 # 2 = xx.xx%, 0 = xx% + round: down + # For example: 20...60 would result in any coverage less than 20% + # would have a red background. The color would gradually change to + # green approaching 60%. Any coverage over 60% would result in a + # solid green color. + range: "20...60" + status: - patch: off - project: - default: - target: auto - threshold: 0.2% - removed_code_behavior: adjust_base + # project will give us the diff in the total code coverage between a commit + # and its parent + project: yes + # Patch gives just the coverage of the patch + patch: yes + # changes tells us if there are unexpected code co verage changes in other files + # which were not changed by the diff + changes: yes + + # See http://docs.codecov.io/docs/ignoring-paths + ignore: + - "build/*" + - "hack/*" + - "openshift-ci/*" + - "Makefile" + - ".travis.yml" + +# See http://docs.codecov.io/docs/pull-request-comments-1 +comment: + layout: "diff, files" + behavior: "" + # default = posts once then update, posts new if delete + # once = post once then updates + # new = delete old, post new + # spammy = post new \ No newline at end of file diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 59e047ed0..00772a248 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -1,12 +1,10 @@ -name: static checks +name: PR checks + on: - workflow_dispatch: - push: - branches: - - "master" pull_request: branches: - - "*" + - master + - 'v*.*' jobs: lint: @@ -15,12 +13,22 @@ jobs: steps: - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: "^1.18" + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.11" + architecture: "x64" + - name: Checkout repo - uses: actions/checkout@v3 + uses: actions/checkout@v4 + + - name: Run linters + run: make lint + unit: name: Unit Tests with Code coverage @@ -28,44 +36,37 @@ jobs: steps: - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: "^1.18" - name: Checkout Git Repository - uses: actions/checkout@v3 - - - name: Run Go Tests - run: make test - - - name: Check format - run: | - if [[ $(go fmt `go list ./... | grep -v vendor`) ]]; then - echo "not well formatted sources are found" - exit 1 - fi + uses: actions/checkout@v4 - - name: Generate coverage report + - name: Unit Tests with Code Coverage run: | - go test `go list ./... | grep -v examples` -coverprofile=coverage.txt -covermode=atomic + make test - - name: Upload coverage report - uses: codecov/codecov-action@v1 + - name: Upload Code Coverage Report + uses: codecov/codecov-action@v3 with: - file: ./coverage.txt - flags: unittests - name: codecov-umbrella + file: cover.out + verbose: true + fail_ci_if_error: true + + source-scan: + name: Gosec code scanning + runs-on: ubuntu-20.04 + steps: + - name: Checkout code + uses: actions/checkout@v4 - - name: Get code coverage artifiact - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: code-coverage - - name: Get test result artifact - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + - name: Run gosec + uses: securego/gosec@v2.18.2 with: - name: test-results - path: test-results - - name: Upload code coverage information to codecov.io - uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4 + args: '-no-fail -fmt sarif -out gosec.sarif ./...' + + - name: Upload gosec scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v2 with: - file: coverage.out + sarif_file: 'gosec.sarif' From bce18f4e45222b869a044a04fcdbb481b2dc97f4 Mon Sep 17 00:00:00 2001 From: mehabhalodiya Date: Tue, 23 Jan 2024 21:27:34 +0530 Subject: [PATCH 4/4] Add test Signed-off-by: mehabhalodiya --- .codecov.yml | 39 ++++--------- .github/workflows/go.yml | 63 +++++++++++++++++++++ .github/workflows/gosec.yaml | 27 +++++++++ .github/workflows/{pr-checks.yml => pr.yml} | 38 +++++-------- Makefile | 7 ++- 5 files changed, 120 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/go.yml create mode 100644 .github/workflows/gosec.yaml rename .github/workflows/{pr-checks.yml => pr.yml} (61%) diff --git a/.codecov.yml b/.codecov.yml index 5a9bdf017..e692c0ef8 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,36 +1,19 @@ -# See http://docs.codecov.io/docs/coverage-configuration coverage: - precision: 2 # 2 = xx.xx%, 0 = xx% - round: down - # For example: 20...60 would result in any coverage less than 20% - # would have a red background. The color would gradually change to - # green approaching 60%. Any coverage over 60% would result in a - # solid green color. - range: "20...60" - status: - # project will give us the diff in the total code coverage between a commit - # and its parent - project: yes - # Patch gives just the coverage of the patch - patch: yes - # changes tells us if there are unexpected code co verage changes in other files - # which were not changed by the diff - changes: yes + # allow test coverage to drop by 0.1%, assume that it's typically due to CI problems + patch: + default: + threshold: 0.1 + project: + default: + threshold: 0.1 - # See http://docs.codecov.io/docs/ignoring-paths ignore: + - "api/v1alpha1/*" - "build/*" + - "common/*" - "hack/*" - "openshift-ci/*" + - "vendor/.*" + - "version/*" - "Makefile" - - ".travis.yml" - -# See http://docs.codecov.io/docs/pull-request-comments-1 -comment: - layout: "diff, files" - behavior: "" - # default = posts once then update, posts new if delete - # once = post once then updates - # new = delete old, post new - # spammy = post new \ No newline at end of file diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 000000000..6217b0d1e --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,63 @@ +name: Go +on: + push: + branches: + - "master" + pull_request: + branches: + - "master" +env: + # Golang version to use across CI steps + GOLANG_VERSION: '1.20' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + +jobs: + event_file: + name: "Event File" + runs-on: ubuntu-latest + steps: + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: Event File + path: ${{ github.event_path }} + + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v5.0.0 + with: + go-version: ${{ env.GOLANG_VERSION }} + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - name: Restore go build cache + uses: actions/cache@v4 + with: + path: ~/.cache/go-build + key: ${{ runner.os }}-go-build-v1-${{ github.run_id }} + + - name: Download all Go modules + run: | + go mod download + + - name: Generate code coverage artifacts + uses: actions/upload-artifact@v4 + with: + name: code-coverage + path: coverage.out + + - name: Upload code coverage information to codecov.io + uses: codecov/codecov-action@v3.1.4 + with: + file: coverage.out diff --git a/.github/workflows/gosec.yaml b/.github/workflows/gosec.yaml new file mode 100644 index 000000000..ee786730b --- /dev/null +++ b/.github/workflows/gosec.yaml @@ -0,0 +1,27 @@ +--- +name: Go Test on Pull Requests +on: # yamllint disable-line rule:truthy + pull_request: + types: + - opened + - synchronize + - reopened + paths: + - '**.go' + workflow_dispatch: +jobs: + gosec: + name: Check GO security + runs-on: ubuntu-20.04 + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + fetch-depth: 1 + ref: ${{ github.event.pull_request.head.sha }} + - name: Run Gosec Security Scanner + uses: securego/gosec@master + with: + args: -exclude-generated ./... + env: + GOROOT: "" diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr.yml similarity index 61% rename from .github/workflows/pr-checks.yml rename to .github/workflows/pr.yml index 00772a248..ce4e1684c 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr.yml @@ -4,7 +4,17 @@ on: pull_request: branches: - master - - 'v*.*' + +env: + GO111MODULE: on + SDK_VERSION: "1.17.0" + MINIKUBE_WANTUPDATENOTIFICATION: false + MINIKUBE_WANTREPORTERRORPROMPT: false + K8S_VERSION: "1.21.3" + MINIKUBE_VERSION: "1.26.0" + OLM_VERSION: "0.22.0" + TEST_ACCEPTANCE_CLI: "kubectl" + TEST_RESULTS: "out/acceptance-tests" jobs: lint: @@ -26,10 +36,6 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 - - name: Run linters - run: make lint - - unit: name: Unit Tests with Code coverage runs-on: ubuntu-20.04 @@ -44,29 +50,11 @@ jobs: uses: actions/checkout@v4 - name: Unit Tests with Code Coverage - run: | - make test + run: ./scripts/openshiftci-presubmit-unittests.sh - name: Upload Code Coverage Report uses: codecov/codecov-action@v3 with: - file: cover.out + file: coverage.out verbose: true fail_ci_if_error: true - - source-scan: - name: Gosec code scanning - runs-on: ubuntu-20.04 - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Run gosec - uses: securego/gosec@v2.18.2 - with: - args: '-no-fail -fmt sarif -out gosec.sarif ./...' - - - name: Upload gosec scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v2 - with: - sarif_file: 'gosec.sarif' diff --git a/Makefile b/Makefile index 3e2efd82b..602a8166b 100644 --- a/Makefile +++ b/Makefile @@ -110,7 +110,12 @@ test-gitopsservice-nondefault: go test -p 1 -timeout 30m ./test/nondefaulte2e -ginkgo.focus="GitOpsServiceNoDefaultInstall" -coverprofile cover.out -ginkgo.v test: manifests generate fmt vet ## Run unit tests. - go test `go list ./... | grep -v test` -coverprofile cover.out + go test `go list ./... | grep -v test` -coverprofile coverage.out + +.PHONY: coverage +coverage: test ## run coverage tests + go tool cover -html=coverage.out -o coverage.html + open coverage.html .PHONY: e2e-tests-sequential e2e-tests-sequential: ## Runs kuttl e2e sequentail tests