Skip to content

Commit 7004ad0

Browse files
authored
Merge pull request #1007 from hashicorp/TF-22370-add-test-coverage-report-to-go-tfe
2 parents e88ea68 + 8a4bdfa commit 7004ad0

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

.github/actions/test-go-tfe/action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ runs:
100100
GO111MODULE: "on"
101101
ENABLE_TFE: ${{ inputs.enterprise }}
102102
run: |
103-
gotestsum --junitfile summary.xml --format short-verbose -- -parallel=1 -timeout=59m -run "${{ steps.test_split.outputs.run }}"
103+
gotestsum --junitfile summary.xml --format short-verbose -- -parallel=1 -timeout=59m -coverprofile cover.out -run "${{ steps.test_split.outputs.run }}"
104104
105105
- name: Upload test artifacts
106106
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
107107
with:
108108
name: junit-test-summary-${{ matrix.index }}
109-
path: summary.xml
109+
path: |
110+
summary.xml
111+
cover.out
110112
retention-days: 1

.github/workflows/ci.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,56 @@ jobs:
6060
needs: [ tests ]
6161
runs-on: ubuntu-latest
6262
steps:
63+
- name: Checkout code
64+
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
65+
6366
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
6467
with:
6568
node-version: 20
6669

70+
- name: Set up Go
71+
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
72+
with:
73+
go-version: '^1.22'
74+
cache: true
75+
6776
- name: Download artifacts
6877
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
6978

7079
- name: Install junit-report-merger
7180
run: npm install -g junit-report-merger
7281

73-
- name: Merge reports
82+
- name: Install gocovmerge
83+
run: go install github.com/wadey/gocovmerge@latest
84+
85+
# Note -- we're intentionally including this in the same job as the running of the tests themselves. This is to
86+
# future proof for when Datadog supports tracing of Go tests rather than just uploading coverage results.
87+
# Ref: https://docs.datadoghq.com/continuous_integration/setup_tests/
88+
- name: prepare datadog-ci
89+
run: |
90+
curl -L --fail "https://github.com/DataDog/datadog-ci/releases/latest/download/datadog-ci_linux-x64" --output "/usr/local/bin/datadog-ci"
91+
chmod +x /usr/local/bin/datadog-ci
92+
93+
- name: Merge coverage reports
94+
run: |
95+
gocovmerge junit-test-summary-0/cover.out > merged-coverage.out
96+
97+
- name: Merge junit reports
7498
run: jrm ./ci-summary.xml "junit-test-summary-0/*.xml"
7599

76100
- name: Upload test artifacts
77101
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
78102
with:
79103
name: junit-test-summary
80104
path: ./ci-summary.xml
105+
106+
- name: upload coverage
107+
env:
108+
DATADOG_API_KEY: "${{ secrets.TF_WORKFLOW_DATADOG_API_KEY }}"
109+
DD_ENV: ci
110+
run: |
111+
coverage=$(go tool cover -func merged-coverage.out | tail -n 1 | awk '{print $3}' | tr -d -c 0-9.)
112+
datadog-ci junit upload --service "$GITHUB_REPOSITORY" --report-measures=test.code_coverage.lines_pct:$coverage ./ci-summary.xml
81113
82114
tests-summarize:
83115
name: Summarize Tests

0 commit comments

Comments
 (0)