-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
228 lines (198 loc) · 8.27 KB
/
ci.yml
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
#
# CI build that assembles artifacts and runs tests.
# If validation is successful this workflow releases from the main dev branch.
#
# - skipping CI: add [skip ci] to the commit message
# - skipping release: add [skip release] to the commit message
#
name: CI
on:
push:
branches: ['main']
tags: [v*]
pull_request:
branches: ['**']
permissions:
contents: read
jobs:
#
# Main build job
#
build:
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
# Definition of the build matrix
strategy:
matrix:
java: [11, 17, 21]
entry:
- { mock-maker: 'mock-maker-default', member-accessor: 'member-accessor-default' }
- { mock-maker: 'mock-maker-inline', member-accessor: 'member-accessor-module' }
- { mock-maker: 'mock-maker-subclass', member-accessor: 'member-accessor-module' }
- { mock-maker: 'mock-maker-subclass', member-accessor: 'member-accessor-reflection' }
- { mock-maker: 'mock-maker-inline', member-accessor: 'member-accessor-reflection' }
# All build steps
# SINGLE-MATRIX-JOB means that the step does not need to be executed on every job in the matrix
steps:
- name: 1. Check out code
uses: actions/checkout@v4 # https://github.com/actions/checkout
with:
fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci
- name: 2. Set up Java for running Gradle build
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
- name: 3. Validate Gradle wrapper
if: matrix.java == 11 && matrix.entry.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
uses: gradle/wrapper-validation-action@v2.1.1 # https://github.com/gradle/wrapper-validation-action
- name: 4. Build and check reproducibility of artifacts (single job only)
if: matrix.java == 11 && matrix.entry.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
run: ./check_reproducibility.sh
- name: 5. Spotless check (single job only). Run './gradlew spotlessApply' locally if this job fails.
if: matrix.java == 11 && matrix.entry.mock-maker == 'mock-maker-default' # SINGLE-MATRIX-JOB
run: >
./gradlew
spotlessCheck
--stacktrace
--scan
- name: 6. Build on Java ${{ matrix.java }} with ${{ matrix.entry.mock-maker }} and ${{ matrix.entry.member-accessor }}
run: >
./gradlew
-Pmockito.test.java=${{ matrix.java }}
build
idea
--stacktrace
--scan
env:
MOCK_MAKER: ${{ matrix.entry.mock-maker }}
MEMBER_ACCESSOR: ${{ matrix.entry.member-accessor }}
- name: 7. Generate coverage report
run: >
./gradlew
-Pmockito.test.java=${{ matrix.java }}
coverageReport
--stacktrace
--scan
- name: 8. Upload coverage report
uses: codecov/codecov-action@v3
with:
files: build/reports/jacoco/mockitoCoverage/mockitoCoverage.xml
fail_ci_if_error: true
token: ${{secrets.CODECOV_TOKEN}}
#
# Android build job
#
android:
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"
timeout-minutes: 30
# Definition of the build matrix
strategy:
matrix:
# Minimum supported and maximum available.
android-api: [ 26, 33 ]
# All build steps
steps:
- name: 1. Check out code
uses: actions/checkout@v4
with:
fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci
- name: 2. Set up Java for running Gradle build
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 17
- name: 3. Enable KVM.
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: 4. Run Android tests on Android API level ${{ matrix.android-api }}
uses: reactivecircus/android-emulator-runner@v2
with:
arch: x86_64
api-level: ${{ matrix.android-api }}
# Override default "-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim"
# See emulator manual for reference: https://developer.android.com/studio/run/emulator-commandline
emulator-options: >
-no-window
-gpu swiftshader_indirect
-no-snapshot
-noaudio
-no-boot-anim
-camera-back none
-camera-front none
# See logcat manual for reference: https://developer.android.com/studio/command-line/logcat
script: |
# Capture logcat output from "Launch Emulator" to a file.
adb logcat -d > emulator-startup.log
# Shorten the logcat output, by truncating at this point, the relevant part is yet to come.
# Best effort, could fail with "failed to clear the 'main' log",
# because something is locking logcat, so try a few times, and ignore errors each time.
adb logcat --clear || true
adb logcat --clear || true
adb logcat --clear || true
# Capture full logcat output to a file.
adb logcat > emulator.log & echo $! > logcat_file.pid
# Output instrumentation test logs to the GitHub Actions output.
adb logcat "*:S MonitoringInstr:V AndroidJUnitRunner:V TestRequestBuilder:V TestExecutor:V TestRunner:V" --format=color & echo $! > logcat_console.pid
echo 0 > gradle.exit # Set a default exit code.
# Run the actual tests (suppress build failures by saving the exit code).
./gradlew :androidTest:connectedCheck --no-daemon --no-build-cache || echo $? > gradle.exit
# Stop capturing logcat output.
kill $(cat logcat_file.pid) || echo "::warning file=.github/workflows/ci.yml::Logcat process $(cat logcat_file.pid) didn't exist."
kill $(cat logcat_console.pid) || echo "::warning file=.github/workflows/ci.yml::Logcat process $(cat logcat_console.pid) didn't exist."
# Make sure the step fails if the tests failed.
exit $(cat gradle.exit)
- name: 5. Upload artifact "androidTest-results-${{ matrix.android-api }}"
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: androidTest-results-${{ matrix.android-api }}
path: |
${{ github.workspace }}/subprojects/androidTest/build/reports/androidTests/connected/**
${{ github.workspace }}/emulator.log
${{ github.workspace }}/emulator-startup.log
# :androidTest:connectedCheck (which depends on :androidTest:createDebugAndroidTestCoverageReport) already generated coverage report.
- name: 6. Upload coverage report
uses: codecov/codecov-action@v3
with:
files: subprojects/androidTest/build/reports/coverage/androidTest/debug/connected/report.xml
fail_ci_if_error: true
#
# Release job, only for pushes to the main development branch
#
release:
permissions:
contents: write
runs-on: ubuntu-latest
needs: [build] # build job must pass before we can release
if: github.event_name == 'push'
&& (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
&& github.repository == 'mockito/mockito'
&& !contains(toJSON(github.event.commits.*.message), '[skip release]')
steps:
- name: 1. Check out code
uses: actions/checkout@v4 # https://github.com/actions/checkout
with:
fetch-depth: '0' # https://github.com/shipkit/shipkit-changelog#fetch-depth-on-ci
- name: 2. Set up Java for running Gradle build
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
- name: 3. Build and release
run: >
./gradlew
githubRelease
publishToSonatype
closeAndReleaseStagingRepository
releaseSummary
--stacktrace
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
NEXUS_TOKEN_USER: ${{secrets.NEXUS_TOKEN_USER}}
NEXUS_TOKEN_PWD: ${{secrets.NEXUS_TOKEN_PWD}}
PGP_KEY: ${{secrets.PGP_KEY}}
PGP_PWD: ${{secrets.PGP_PWD}}