Skip to content

Commit 7fb3b8f

Browse files
AlanGreenetekton-robot
authored andcommitted
Add GitHub Actions workflow for go coverage job
It uses workflow artifacts to store current coverage on merge to main, and uses this as a baseline for comparison when running on PRs. It's also configured to run at least once every 2 months to avoid the workflow artifact expiring.
1 parent a154e04 commit 7fb3b8f

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

.github/workflows/go-coverage.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Go coverage
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
branches: ["main"]
9+
push:
10+
branches: ["main"]
11+
# run at least once every 2 months to prevent the coverage artifact from expiring
12+
schedule:
13+
- cron: '14 3 2 */2 *'
14+
workflow_dispatch:
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
18+
cancel-in-progress: true
19+
20+
defaults:
21+
run:
22+
shell: bash
23+
24+
jobs:
25+
go-coverage:
26+
name: Go coverage
27+
runs-on: ubuntu-24.04
28+
permissions:
29+
pull-requests: write
30+
31+
steps:
32+
- name: Harden runner
33+
uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
34+
with:
35+
egress-policy: audit
36+
37+
- name: Checkout
38+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
39+
with:
40+
path: ${{ github.workspace }}/src/github.com/tektoncd/pipeline
41+
42+
- name: Set up Go
43+
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0
44+
with:
45+
go-version-file: "${{ github.workspace }}/src/github.com/tektoncd/pipeline/go.mod"
46+
47+
- name: Generate coverage
48+
working-directory: ${{ github.workspace }}/src/github.com/tektoncd/pipeline
49+
run: |
50+
go test -cover -coverprofile=coverage.txt ./... || true
51+
echo "Generated coverage profile"
52+
53+
- name: Archive coverage results
54+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
55+
with:
56+
name: code-coverage
57+
path: ${{ github.workspace }}/src/github.com/tektoncd/pipeline/coverage.txt
58+
59+
- name: Comment on PR
60+
if: github.event_name == 'pull_request'
61+
uses: fgrosse/go-coverage-report@8c1d1a09864211d258937b1b1a5b849f7e4f2682 # v1.2.0
62+
continue-on-error: true # This may fail if artifact on main branch does not exist (first run or expired)
63+
with:
64+
coverage-artifact-name: "code-coverage"
65+
coverage-file-name: "coverage.txt"

0 commit comments

Comments
 (0)