-
Notifications
You must be signed in to change notification settings - Fork 0
294 lines (257 loc) · 9.36 KB
/
Copy pathci.yml
File metadata and controls
294 lines (257 loc) · 9.36 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
name: Test a Scala project
on:
workflow_call:
inputs:
scala_versions:
description: 'JSON array of Scala versions to build against'
type: string
default: '["2.13.18", "3.3.8"]'
java_version:
description: 'JDK version'
type: string
default: '17'
java_distribution:
description: 'JDK distribution'
type: string
default: 'temurin'
test_task:
description: >-
sbt task that runs the tests. Defaults to `testFull` on sbt 2 and `test` on sbt 1,
detected from project/build.properties.
type: string
default: ''
clean_task:
description: >-
sbt task that cleans the working directory. Defaults to `cleanFull` on sbt 2 and
`clean` on sbt 1, detected from project/build.properties.
type: string
default: ''
sonar:
description: >-
Run a SonarQube Cloud scan. Requires a SONAR_TOKEN secret and an existing project on
SonarQube Cloud with Automatic Analysis turned off, otherwise the two conflict.
type: boolean
default: false
sonar_project_key:
description: 'SonarQube project key. Defaults to <owner>_<repo>.'
type: string
default: ''
sonar_args:
description: 'Extra -D arguments for the Sonar scanner'
type: string
default: ''
secrets:
SONAR_TOKEN:
description: >-
Only needed with `sonar: true`. Declared so callers do not have to use `secrets: inherit`,
which SonarQube Cloud's own quality gate flags.
required: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
sbt-tasks:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v7
with:
persist-credentials: false
- name: resolve test task
id: test-task
env:
TEST_TASK: ${{ inputs.test_task }}
run: |
if [[ -n "$TEST_TASK" ]]; then
echo "test=$TEST_TASK" >> "$GITHUB_OUTPUT"
elif grep -qE '^sbt\.version\s*=\s*2\.' project/build.properties; then
# sbt 2 redefined `test` to run only tests that failed or never ran
echo "test=testFull" >> "$GITHUB_OUTPUT"
else
echo "test=test" >> "$GITHUB_OUTPUT"
fi
- name: resolve clean task
id: clean-task
env:
CLEAN_TASK: ${{ inputs.clean_task }}
run: |
if [[ -n "$CLEAN_TASK" ]]; then
echo "clean=$CLEAN_TASK" >> "$GITHUB_OUTPUT"
elif grep -qE '^sbt\.version\s*=\s*2\.' project/build.properties; then
# in sbt 2 the `clean` doesn't remove all generated classes
echo "clean=cleanFull" >> "$GITHUB_OUTPUT"
else
echo "clean=clean" >> "$GITHUB_OUTPUT"
fi
outputs:
test: ${{ steps.test-task.outputs.test }}
clean: ${{ steps.clean-task.outputs.clean }}
test-coverage:
runs-on: ubuntu-latest
needs: [sbt-tasks]
strategy:
fail-fast: false
matrix:
scala: ${{ fromJSON(inputs.scala_versions) }}
steps:
- name: checkout
uses: actions/checkout@v7
with:
persist-credentials: false
# checkout whole history with all tags - required by `sonar` for blame
fetch-depth: 0
- name: restore cache
uses: coursier/cache-action@v8
- name: setup Java ${{ inputs.java_version }}
uses: actions/setup-java@v5
with:
java-version: ${{ inputs.java_version }}
distribution: ${{ inputs.java_distribution }}
cache: 'sbt'
- name: setup SBT
uses: sbt/setup-sbt@v1
with:
# sbt 2's disk cache is restored across runs. Disable disk cache to force full coverage run
disk-cache: false
# The coverage build runs before any other compile: scoverage's instrumentation is not part of
# sbt's compile cache key, so a plain compile done first would be reused here and the coverage
# report would come out empty.
- name: build ${{ matrix.scala }}
run: |
sbt "++${{ matrix.scala }}; ${{ needs.sbt-tasks.outputs.clean }}; coverage; ${{ needs.sbt-tasks.outputs.test }}; coverageAggregate"
- name: locate coverage report
id: coverage
if: success()
run: echo "file=$(find . -path '*/coverage-report/cobertura.xml' | head -1)" >> "$GITHUB_OUTPUT"
- name: fail if coverage report is empty
if: success()
env:
REPORT: ${{ steps.coverage.outputs.file }}
run: |
if [[ -z "$REPORT" || ! -f "$REPORT" ]]; then
echo "::error::no cobertura report was produced"
exit 1
fi
# Only the root <coverage> element's totals matter; individual classes may legitimately
# have no lines.
valid=$(grep -m1 -oE 'lines-valid="[0-9]+"' "$REPORT" | grep -oE '[0-9]+')
if [[ "${valid:-0}" -eq 0 ]]; then
echo "::error::coverage report is empty - instrumentation did not run"
exit 1
fi
- name: upload coverage
if: success()
uses: coverallsapp/github-action@v2
with:
file: ${{ steps.coverage.outputs.file }}
format: cobertura
flag-name: Scala ${{ matrix.scala }}
parallel: true
# Scanned once, on the first Scala version only: SonarQube tracks one analysis per branch, so
# running it per matrix leg would have the legs overwrite each other.
- name: sonar settings
id: sonar
if: inputs.sonar && matrix.scala == fromJSON(inputs.scala_versions)[0]
env:
KEY: ${{ inputs.sonar_project_key }}
run: |
if [[ -z "$KEY" ]]; then
KEY="${GITHUB_REPOSITORY/\//_}"
fi
echo "key=$KEY" >> "$GITHUB_OUTPUT"
# scoverage writes one report per module; Sonar takes a comma separated list
reports=$(find . -path '*/scoverage-report/scoverage.xml' | paste -sd, -)
echo "reports=$reports" >> "$GITHUB_OUTPUT"
- name: sonar scan
if: inputs.sonar && matrix.scala == fromJSON(inputs.scala_versions)[0]
uses: SonarSource/sonarqube-scan-action@v8
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.organization=${{ github.repository_owner }}
-Dsonar.projectKey=${{ steps.sonar.outputs.key }}
-Dsonar.scala.coverage.reportPaths=${{ steps.sonar.outputs.reports }}
${{ inputs.sonar_args }}
# Closes the parallel Coveralls build once every matrix leg has uploaded its part. Without
# `parallel: true` the first upload closes the build and the other legs get rejected with
# "Can't add a job to a build that is already closed".
coverage-finished:
runs-on: ubuntu-latest
needs: [test-coverage]
if: ${{ !cancelled() }}
steps:
- name: finish Coveralls build
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
binary-compatibility:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
scala: ${{ fromJSON(inputs.scala_versions) }}
steps:
- name: checkout
uses: actions/checkout@v7
with:
persist-credentials: false
# checkout whole history with all tags - required by `versionPolicyCheck` for version comparison
fetch-depth: 0
- name: restore cache
uses: coursier/cache-action@v8
- name: setup Java ${{ inputs.java_version }}
uses: actions/setup-java@v5
with:
java-version: ${{ inputs.java_version }}
distribution: ${{ inputs.java_distribution }}
cache: 'sbt'
- name: setup SBT
uses: sbt/setup-sbt@v1
- name: binary compatibility ${{ matrix.scala }}
run: sbt "++${{ matrix.scala }}; versionPolicyCheck"
formatting:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v7
with:
persist-credentials: false
- name: restore cache
uses: coursier/cache-action@v8
- name: setup Java ${{ inputs.java_version }}
uses: actions/setup-java@v5
with:
java-version: ${{ inputs.java_version }}
distribution: ${{ inputs.java_distribution }}
cache: 'sbt'
- name: setup SBT
uses: sbt/setup-sbt@v1
- name: formatting
run: sbt "scalafmtCheckRepo"
scaladoc:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
scala: ${{ fromJSON(inputs.scala_versions) }}
steps:
- name: checkout
uses: actions/checkout@v7
with:
persist-credentials: false
- name: restore cache
uses: coursier/cache-action@v8
- name: setup Java ${{ inputs.java_version }}
uses: actions/setup-java@v5
with:
java-version: ${{ inputs.java_version }}
distribution: ${{ inputs.java_distribution }}
cache: 'sbt'
- name: setup SBT
uses: sbt/setup-sbt@v1
with:
# sbt 2's disk cache is restored across runs. Disable disk cache to force full Scaladoc recompilation
disk-cache: false
- name: scaladoc ${{ matrix.scala }}
run: sbt "++${{ matrix.scala }}; Compile/doc"