Repository navigation
119 lines (107 loc) · 3.38 KB
/
Copy pathcode-coverage.yml
File metadata and controls
119 lines (107 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: Code Coverage
on:
push:
branches:
- main
paths:
- '**/*.go'
- '**/go.mod'
- '**/go.sum'
- 'Makefile'
- 'scripts/**'
- '.github/workflows/code-coverage.yml'
- 'server/events/templates/**'
- 'server/i18n/**'
- '**/testdata/**'
- 'testdata/**'
pull_request:
branches:
- main
types:
- opened
- reopened
- synchronize
- ready_for_review
paths:
- '**/*.go'
- '**/go.mod'
- '**/go.sum'
- 'Makefile'
- 'scripts/**'
- '.github/workflows/code-coverage.yml'
- 'server/events/templates/**'
- 'server/i18n/**'
- '**/testdata/**'
- 'testdata/**'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions: {}
jobs:
go-coverage:
name: Go Coverage
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
permissions:
contents: read
runs-on: ubuntu-24.04
timeout-minutes: 45
container: ghcr.io/runatlantis/testing-env:latest@sha256:dc683c36e7fb8f26fcc8628fdcf328f42d3b1903e130aebb8484223fbdedfd98
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
persist-credentials: false
- name: Setup Go
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6
with:
go-version-file: go.mod
- name: Run Go tests with coverage
run: make test-coverage
- name: Convert Go coverage to Cobertura XML
run: |
go install github.com/boumenot/gocover-cobertura@v1.5.0
gocover-cobertura < .cover/cover.out > .cover/coverage.xml
test -s .cover/coverage.xml
- name: Validate Cobertura XML
run: |
python3 - <<'PY'
import xml.etree.ElementTree as ET
path = ".cover/coverage.xml"
root = ET.parse(path).getroot()
if root.tag != "coverage":
raise SystemExit(f"unexpected root tag: {root.tag}")
print(f"validated {path}")
PY
- name: Upload coverage artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: go-coverage-cobertura
path: .cover/coverage.xml
if-no-files-found: error
retention-days: 1
upload-coverage:
name: Upload Coverage
needs: go-coverage
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: read
code-quality: write
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- name: Harden Runner
uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4
with:
egress-policy: audit
- name: Download coverage artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: go-coverage-cobertura
path: .cover
- name: Upload coverage report
uses: actions/upload-code-coverage@1c15be36fc3733ba839b1dd643bd9556e4426dc1 # v1
with:
file: .cover/coverage.xml
language: Go
label: code-coverage/go