From 2bc72adcab88508a3c656233362a840db3050648 Mon Sep 17 00:00:00 2001 From: Andrew Sisley Date: Fri, 8 Sep 2023 13:10:31 -0400 Subject: [PATCH] WIP - code cov for all --- .github/workflows/code-test-coverage.yml | 76 --------------------- .github/workflows/detect-change.yml | 2 +- .github/workflows/run-tests.yml | 29 ++++++++ .github/workflows/test-collection-named.yml | 29 ++++++++ .github/workflows/test-gql-mutations.yml | 29 ++++++++ Makefile | 20 +++++- 6 files changed, 105 insertions(+), 80 deletions(-) delete mode 100644 .github/workflows/code-test-coverage.yml diff --git a/.github/workflows/code-test-coverage.yml b/.github/workflows/code-test-coverage.yml deleted file mode 100644 index 65c0a92f1f..0000000000 --- a/.github/workflows/code-test-coverage.yml +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright 2022 Democratized Data Foundation -# -# Use of this software is governed by the Business Source License -# included in the file licenses/BSL.txt. -# -# As of the Change Date specified in that file, in accordance with -# the Business Source License, use of this software will be governed -# by the Apache License, Version 2.0, included in the file -# licenses/APL.txt. - -name: Code Test Coverage Workflow - -on: - pull_request: - branches: - - master - - develop - - push: - tags: - - 'v[0-9]+.[0-9]+.[0-9]+' - branches: - - master - - develop - -jobs: - code-test-coverage: - name: Code test coverage job - - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Setup Go environment explicitly - uses: actions/setup-go@v3 - with: - go-version: "1.20" - check-latest: true - - - name: Generate full test coverage report using go-acc - run: make test:coverage - - - name: Upload coverage to Codecov without token, retry on failure - env: - codecov_secret: ${{ secrets.CODECOV_TOKEN }} - if: env.codecov_secret == '' - uses: Wandalen/wretry.action@v1.0.36 - with: - attempt_limit: 5 - attempt_delay: 10000 - action: codecov/codecov-action@v3 - with: | - name: defradb-codecov - files: ./coverage.txt - flags: all-tests - os: 'linux' - fail_ci_if_error: true - verbose: true - - - name: Upload coverage to Codecov with token - env: - codecov_secret: ${{ secrets.CODECOV_TOKEN }} - if: env.codecov_secret != '' - uses: codecov/codecov-action@v3 - with: - token: ${{ env.codecov_secret }} - name: defradb-codecov - files: ./coverage.txt - flags: all-tests - os: 'linux' - fail_ci_if_error: true - verbose: true - # path_to_write_report: ./coverage/codecov_report.txt - # directory: ./coverage/reports/ diff --git a/.github/workflows/detect-change.yml b/.github/workflows/detect-change.yml index b6272c21cd..4609197443 100644 --- a/.github/workflows/detect-change.yml +++ b/.github/workflows/detect-change.yml @@ -45,7 +45,7 @@ jobs: make deps:test - name: Run detection for changes - run: make test:changes + run: make test:changes-ci ## Uncomment to enable ability to SSH into the runner. #- name: Setup upterm ssh session for debugging diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index bfa696a283..9e4501a5af 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -48,3 +48,32 @@ jobs: - name: Run the tests, showing name of each test run: make test:ci + + - name: Upload coverage to Codecov without token, retry on failure + env: + codecov_secret: ${{ secrets.CODECOV_TOKEN }} + if: env.codecov_secret == '' + uses: Wandalen/wretry.action@v1.0.36 + with: + attempt_limit: 5 + attempt_delay: 10000 + action: codecov/codecov-action@v3 + with: | + name: defradb-codecov + files: ./coverage.txt + os: 'linux' + fail_ci_if_error: true + verbose: true + + - name: Upload coverage to Codecov with token + env: + codecov_secret: ${{ secrets.CODECOV_TOKEN }} + if: env.codecov_secret != '' + uses: codecov/codecov-action@v3 + with: + token: ${{ env.codecov_secret }} + name: defradb-codecov + files: ./coverage.txt + os: 'linux' + fail_ci_if_error: true + verbose: true diff --git a/.github/workflows/test-collection-named.yml b/.github/workflows/test-collection-named.yml index 5adabe4fdf..3f22e584bc 100644 --- a/.github/workflows/test-collection-named.yml +++ b/.github/workflows/test-collection-named.yml @@ -52,3 +52,32 @@ jobs: - name: Run tests with Collection Named mutations run: make test:ci-col-named-mutations + + - name: Upload coverage to Codecov without token, retry on failure + env: + codecov_secret: ${{ secrets.CODECOV_TOKEN }} + if: env.codecov_secret == '' + uses: Wandalen/wretry.action@v1.0.36 + with: + attempt_limit: 5 + attempt_delay: 10000 + action: codecov/codecov-action@v3 + with: | + name: defradb-codecov + files: ./coverage.txt + os: 'linux' + fail_ci_if_error: true + verbose: true + + - name: Upload coverage to Codecov with token + env: + codecov_secret: ${{ secrets.CODECOV_TOKEN }} + if: env.codecov_secret != '' + uses: codecov/codecov-action@v3 + with: + token: ${{ env.codecov_secret }} + name: defradb-codecov + files: ./coverage.txt + os: 'linux' + fail_ci_if_error: true + verbose: true diff --git a/.github/workflows/test-gql-mutations.yml b/.github/workflows/test-gql-mutations.yml index 827dd22098..b0c1c3e449 100644 --- a/.github/workflows/test-gql-mutations.yml +++ b/.github/workflows/test-gql-mutations.yml @@ -46,3 +46,32 @@ jobs: - name: Run tests with gql mutations run: make test:ci-gql-mutations + + - name: Upload coverage to Codecov without token, retry on failure + env: + codecov_secret: ${{ secrets.CODECOV_TOKEN }} + if: env.codecov_secret == '' + uses: Wandalen/wretry.action@v1.0.36 + with: + attempt_limit: 5 + attempt_delay: 10000 + action: codecov/codecov-action@v3 + with: | + name: defradb-codecov + files: ./coverage.txt + os: 'linux' + fail_ci_if_error: true + verbose: true + + - name: Upload coverage to Codecov with token + env: + codecov_secret: ${{ secrets.CODECOV_TOKEN }} + if: env.codecov_secret != '' + uses: codecov/codecov-action@v3 + with: + token: ${{ env.codecov_secret }} + name: defradb-codecov + files: ./coverage.txt + os: 'linux' + fail_ci_if_error: true + verbose: true diff --git a/Makefile b/Makefile index 6eb3456fcc..677505cd21 100644 --- a/Makefile +++ b/Makefile @@ -187,15 +187,19 @@ test\:build: .PHONY: test\:ci test\:ci: + @$(MAKE) deps:coverage DEFRA_BADGER_MEMORY=true DEFRA_BADGER_FILE=true \ DEFRA_CLIENT_GO=true DEFRA_CLIENT_HTTP=true \ - $(MAKE) test:all + go-acc ./... --output=coverage.txt --covermode=atomic -- -coverpkg=./... $(TEST_FLAGS) + go tool cover -func coverage.txt | grep total | awk '{print $$3}' .PHONY: test\:ci-gql-mutations test\:ci-gql-mutations: + @$(MAKE) deps:coverage DEFRA_MUTATION_TYPE=gql DEFRA_BADGER_MEMORY=true \ DEFRA_CLIENT_GO=true DEFRA_CLIENT_HTTP=true \ - $(MAKE) test:all + go-acc ./... --output=coverage.txt --covermode=atomic -- -coverpkg=./... $(TEST_FLAGS) + go tool cover -func coverage.txt | grep total | awk '{print $$3}' .PHONY: test\:gql-mutations test\:gql-mutations: @@ -208,9 +212,11 @@ test\:gql-mutations: # UpdateDoc will call [Collection.Update]. .PHONY: test\:ci-col-named-mutations test\:ci-col-named-mutations: + @$(MAKE) deps:coverage DEFRA_MUTATION_TYPE=collection-named DEFRA_BADGER_MEMORY=true \ DEFRA_CLIENT_GO=true DEFRA_CLIENT_HTTP=true \ - $(MAKE) test:all + go-acc ./... --output=coverage.txt --covermode=atomic -- -coverpkg=./... $(TEST_FLAGS) + go tool cover -func coverage.txt | grep total | awk '{print $$3}' .PHONY: test\:col-named-mutations test\:col-named-mutations: @@ -297,6 +303,14 @@ test\:changes: @$(MAKE) deps:lens env DEFRA_DETECT_DATABASE_CHANGES=true DEFRA_CLIENT_GO=true gotestsum -- ./... -shuffle=on -p 1 +.PHONY: test\:changes-ci +test\:changes: + @$(MAKE) deps:coverage + @$(MAKE) deps:lens + env DEFRA_DETECT_DATABASE_CHANGES=true DEFRA_CLIENT_GO=true / + go-acc ./... --output=coverage.txt --covermode=atomic -- -coverpkg=./... -shuffle=on -p 1 + go tool cover -func coverage.txt | grep total | awk '{print $$3}' + .PHONY: validate\:codecov validate\:codecov: curl --data-binary @.github/codecov.yml https://codecov.io/validate