-
Notifications
You must be signed in to change notification settings - Fork 0
169 lines (168 loc) · 6.62 KB
/
code-coverage-kotlin.yml
File metadata and controls
169 lines (168 loc) · 6.62 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Code Coverage (Kotlin)
on:
workflow_call:
inputs:
service-name:
required: true
type: string
description: "The name of the project that will appear in the reporting, must be in kebab-case format"
runner-size:
required: false
type: string
description: "Runner to use for the job (normal, or large)"
default: "normal"
architecture:
required: false
type: string
description: "Runner architecture (x64 or arm64)"
default: "x64"
java-version:
required: false
type: string
description: "Java version to use"
default: "21"
gradle-module:
required: false
type: string
description: "Name of the gradle module being tested - only needed if you want to test one module in a multi-module project"
kover-report-path:
required: false
type: string
description: "Path to the Kover report XML file"
default: "build/reports/kover/report.xml"
catalog-info-path:
required: false
type: string
description: "Path to the catalog-info.yaml file"
default: "catalog-info.yaml"
cloc-source-path:
required: false
type: string
description: 'Path to analyze for total lines of code counting (defaults to current directory)'
default: '.'
cloc-exclude-dirs:
required: false
type: string
description: 'Comma-separated list of directories to exclude from LOC count when analyzing subdirectories'
default: 'build,target,dist,node_modules,.gradle,.idea,out'
team-override:
required: false
type: string
description: 'Optional override for the team name. If provided, this value will be used instead of reading from catalog-info.yaml'
division-override:
required: false
type: string
description: 'Optional override for the division name. If provided, this value will be used instead of reading from catalog-info.yaml'
test-timeout-minutes:
required: false
type: number
description: "Timeout for the test job in minutes"
default: 30
gradle-args:
required: false
type: string
default: "--no-daemon --parallel"
description: 'Additional Gradle arguments'
secrets:
TAILSCALE_AUTHKEY:
required: true
description: "Authentication token used for logging into Tailscale"
GHL_USERNAME:
required: true
description: "Github Username (Gradle plugin)"
GHL_PASSWORD:
required: true
description: "Github Password (Gradle plugin)"
SONAR_TOKEN:
required: false
description: "SonarCloud authentication token (optional, for code quality analysis)"
jobs:
setup:
name: Setup
runs-on: linux-arm64
outputs:
runner-name: ${{ steps.runner.outputs.runner-name }}
steps:
- name: Get runner name
id: runner
uses: monta-app/github-workflows/.github/actions/runner-size-converter@main
with:
runner-size: ${{ inputs.runner-size }}
architecture: ${{ inputs.architecture }}
generate-coverage-report:
needs:
- setup
runs-on: ${{ needs.setup.outputs.runner-name }}
timeout-minutes: ${{ inputs.test-timeout-minutes }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Validate service-name format
run: |
if ! echo "${{ inputs.service-name }}" | grep -qE '^[a-z0-9]+(-[a-z0-9]+)*$'; then
echo "Error: service-name '${{ inputs.service-name }}' is not in kebab-case format"
echo "Expected format: lowercase letters and numbers separated by hyphens (e.g., 'my-service-name')"
exit 1
fi
echo "✓ service-name '${{ inputs.service-name }}' is valid"
- name: Set up JDK
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
java-version: ${{ inputs.java-version }}
distribution: "corretto"
cache: "gradle"
- name: Run tests with Kover
env:
GHL_USERNAME: ${{ secrets.GHL_USERNAME }}
GHL_PASSWORD: ${{ secrets.GHL_PASSWORD }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
uses: monta-app/github-workflows/.github/actions/gradle-multi-module@main
with:
gradle-module: ${{ inputs.gradle-module }}
gradle-tasks: "test koverXmlReport"
gradle-args: ${{ inputs.gradle-args }}
- name: Upload coverage report
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: coverage-report-${{ inputs.service-name }}
path: ${{ inputs.kover-report-path }}
retention-days: 1
push-coverage-to-server:
needs:
- setup
- generate-coverage-report
runs-on: linux-arm64
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Check if can access Dev Lens
run: |
curl --retry 3 --retry-delay 5 --retry-all-errors -f -s -o /dev/null --max-time 30 https://dev-lens.staging.monta.app/health
- name: Download coverage report
id: download-coverage
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: coverage-report-${{ inputs.service-name }}
- name: Set coverage report path
id: coverage-path
run: |
filename=$(basename "${{ inputs.kover-report-path }}")
echo "report-path=${{ steps.download-coverage.outputs.download-path }}/$filename" >> "$GITHUB_OUTPUT"
- name: Disable man-db trigger refreshes (https://github.com/actions/runner-images/issues/10977)
run: |
echo 'set man-db/auto-update false' | sudo debconf-communicate >/dev/null
sudo dpkg-reconfigure man-db
- name: Install cloc
run: |
sudo apt-get install -y cloc
- name: Push coverage to Dev Lens
uses: monta-app/push-kover-prometheus-action@main
with:
endpoint-url: "https://dev-lens.staging.monta.app/api/v1/code-coverage/metrics"
kover-report-path: ${{ steps.coverage-path.outputs.report-path }}
catalog-info-path: ${{ inputs.catalog-info-path }}
service-name: ${{ inputs.service-name }}
cloc-source-path: ${{ inputs.cloc-source-path }}
cloc-exclude-dirs: ${{ inputs.cloc-exclude-dirs }}
team-override: ${{ inputs.team-override }}
division-override: ${{ inputs.division-override }}