From 0621856bdf841ccee049eff76967bb7f9a616f84 Mon Sep 17 00:00:00 2001 From: Shahzad Lone Date: Wed, 17 May 2023 19:55:27 +0500 Subject: [PATCH] ci: Reconfigure CodeCov action to ensure stability (#1414) ## Relevant issue(s) Resolves #1413 ## Description - Ensures Codecov doesn't run on every push (code coverage reports will only generate for every PR, or pushes on `master` and `develop`). This also means contributors don't need to have codecov to have a build run successfully on their fork pushes. - If for whatever reason the code cov token doesn't exist, still run the action (but might be flakey - so retry until passes up to 5 times). Future: Should probably rework this to do the `pull_request` -> trigger a `workflow_run` that will be passed the code coverage report that will then have the secrets in the second privileged action run. But until then hopefully this can get us by. ## How has this been tested? Fork pushes and this PR pushes. --- .github/workflows/build-ami-with-packer.yml | 4 +-- .github/workflows/build-dependencies.yml | 5 ++- .github/workflows/code-test-coverage.yml | 35 ++++++++++++++++--- .../workflows/deploy-ami-with-terraform.yml | 3 ++ .github/workflows/detect-change.yml | 5 ++- .github/workflows/lint-then-benchmark.yml | 2 +- .github/workflows/run-tests.yml | 3 ++ .github/workflows/start-binary.yml | 5 ++- 8 files changed, 51 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-ami-with-packer.yml b/.github/workflows/build-ami-with-packer.yml index ee5392338b..4b3fd62b64 100644 --- a/.github/workflows/build-ami-with-packer.yml +++ b/.github/workflows/build-ami-with-packer.yml @@ -12,7 +12,8 @@ name: Build AMI With Packer Workflow on: push: - tags: ["v[0-9].[0-9]+.[0-9]+"] + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' env: PACKER_LOG: 1 @@ -28,7 +29,6 @@ jobs: - name: Checkout code into the directory uses: actions/checkout@v3 - - name: Environment version target run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV # run: echo ${{ env.RELEASE_VERSION }} diff --git a/.github/workflows/build-dependencies.yml b/.github/workflows/build-dependencies.yml index 4eeb238726..e442f8dc89 100644 --- a/.github/workflows/build-dependencies.yml +++ b/.github/workflows/build-dependencies.yml @@ -12,10 +12,13 @@ name: Build Dependencies Workflow on: pull_request: + branches: + - master + - develop push: tags: - - v* + - 'v[0-9]+.[0-9]+.[0-9]+' branches: - master - develop diff --git a/.github/workflows/code-test-coverage.yml b/.github/workflows/code-test-coverage.yml index bb1be36296..40ddad3180 100644 --- a/.github/workflows/code-test-coverage.yml +++ b/.github/workflows/code-test-coverage.yml @@ -12,9 +12,16 @@ 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: @@ -25,10 +32,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v3 - with: - fetch-depth: 2 - - name: Setup Go + - name: Setup Go environment explicitly uses: actions/setup-go@v3 with: go-version: "1.19" @@ -37,9 +42,29 @@ jobs: - name: Generate full test coverage report using go-acc run: make test:coverage - - name: Upload coverage to Codecov + - 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: | + fail_ci_if_error: true + files: ./coverage.txt + flags: defra-tests + name: codecov-umbrella + 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 }} fail_ci_if_error: true files: ./coverage.txt flags: defra-tests diff --git a/.github/workflows/deploy-ami-with-terraform.yml b/.github/workflows/deploy-ami-with-terraform.yml index 3ec9d074ab..80a0daefde 100644 --- a/.github/workflows/deploy-ami-with-terraform.yml +++ b/.github/workflows/deploy-ami-with-terraform.yml @@ -28,6 +28,9 @@ on: - completed pull_request: + branches: + - master + - develop jobs: deploy-ami-with-terraform: diff --git a/.github/workflows/detect-change.yml b/.github/workflows/detect-change.yml index 65238e78da..f17a4d80ba 100644 --- a/.github/workflows/detect-change.yml +++ b/.github/workflows/detect-change.yml @@ -12,10 +12,13 @@ name: Detect Change Workflow on: pull_request: + branches: + - master + - develop push: tags: - - v* + - 'v[0-9]+.[0-9]+.[0-9]+' branches: - master - develop diff --git a/.github/workflows/lint-then-benchmark.yml b/.github/workflows/lint-then-benchmark.yml index 9c1bdf42eb..172df4d6b8 100644 --- a/.github/workflows/lint-then-benchmark.yml +++ b/.github/workflows/lint-then-benchmark.yml @@ -15,7 +15,7 @@ on: push: tags: - - v* + - 'v[0-9]+.[0-9]+.[0-9]+' branches: - master - develop diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 1bab3e5a05..e078dfcfec 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -12,6 +12,9 @@ name: Run Tests Workflow on: pull_request: + branches: + - master + - develop push: diff --git a/.github/workflows/start-binary.yml b/.github/workflows/start-binary.yml index 97db056df9..6061b1c59e 100644 --- a/.github/workflows/start-binary.yml +++ b/.github/workflows/start-binary.yml @@ -12,10 +12,13 @@ name: Start Binary Workflow on: pull_request: + branches: + - master + - develop push: tags: - - v* + - 'v[0-9]+.[0-9]+.[0-9]+' branches: - master - develop