From 00ff688ebeaa086dfd1c89c49b637163832d8704 Mon Sep 17 00:00:00 2001 From: taylanisikdemir Date: Fri, 15 Mar 2024 12:48:21 -0700 Subject: [PATCH] Enable codecov and generate metadata file as artifact (#1320) --- .buildkite/pipeline.yml | 7 +++- .buildkite/scripts/gen_coverage_metadata.sh | 17 +++++++++ .github/workflows/codecov.yml | 30 ++++++++++++++++ codecov.yml | 40 +++++++++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100755 .buildkite/scripts/gen_coverage_metadata.sh create mode 100644 .github/workflows/codecov.yml create mode 100644 codecov.yml diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 8ab783253..50fe75f99 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -4,13 +4,18 @@ steps: queue: "init" docker: "*" command: ".buildkite/scripts/fossa.sh" + - label: ":golang: unit-test" agents: queue: "workers" docker: "*" - command: "make unit_test" + commands: + - "make unit_test" + - ".buildkite/scripts/gen_coverage_metadata.sh .build/metadata.txt" artifact_paths: - ".build/*/coverage/*.out" + - ".build/cover.out" + - ".build/metadata.txt" plugins: - docker-compose#v3.0.0: run: unit-test diff --git a/.buildkite/scripts/gen_coverage_metadata.sh b/.buildkite/scripts/gen_coverage_metadata.sh new file mode 100755 index 000000000..3eedf2357 --- /dev/null +++ b/.buildkite/scripts/gen_coverage_metadata.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +set -ex + +# This script generates coverage metadata for the coverage report. +# Output is used by SonarQube integration in Uber and not used by OS repo coverage tool itself. + +# Example output: +# commit-sha: 6953daa563e8e44512bc349c9608484cfd4ec4ff +# timestamp: 2024-03-04T19:29:16Z + +output_path="$1" + +echo "commit-sha: $(git rev-parse HEAD)" > "$output_path" +echo "timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$output_path" + +echo "Coverage metadata written to $output_path" diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 000000000..bef5fe19f --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,30 @@ +name: Workflow for Codecov integration +on: [push, pull_request] +jobs: + codecov: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: 1.22.x + cache: false + + - name: Download dependencies + run: go mod download + + - name: Test and generate coverage report + run: make unit_test + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4.0.1 # https://github.com/codecov/codecov-action + with: + file: .build/cover.out + exclude: ./ + token: ${{ secrets.CODECOV_TOKEN }} + slug: uber-go/cadence-client diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..eedb41aad --- /dev/null +++ b/codecov.yml @@ -0,0 +1,40 @@ +# Refs: +# - https://docs.codecov.com/docs/common-recipe-list +# - https://docs.codecov.com/docs/codecovyml-reference +# +# After making changes, run below command to validate +# curl --data-binary @codecov.yml https://codecov.io/validate +coverage: + range: 80...100 + round: down + precision: 2 + status: + project: # measuring the overall project coverage + default: # context, you can create multiple ones with custom titles + informational: true + target: 85% # specify the target coverage for each commit status + # option: "auto" (compare against parent commit or pull request base) + # option: "X%" a static target percentage to hit + threshold: 0% # allow the coverage drop by x% before marking as failure + if_ci_failed: ignore # require the CI to pass before setting the status + patch: + default: + informational: true +comment: + layout: "header, files, footer" + hide_project_coverage: false +codecov: + require_ci_to_pass: false +ignore: + - "**/*_generated.go" + - "**/*_mock.go" + - "**/testdata/**" + - "**/*_test.go" + - "**/*_testsuite.go" + - "compatibility/**" + - "idls/**" + - "internal/compatibility/**" + - "internal/tools/**" + - "mocks/**" + - "test/**" + - "testsuite/**"