-
Notifications
You must be signed in to change notification settings - Fork 24
199 lines (170 loc) · 6.26 KB
/
test-prs.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
name: Test PRs
run-name: Tests for PR ${{ github.event.pull_request.number }}
on:
pull_request:
types:
- synchronize
- opened
- ready_for_review
- reopened
concurrency:
group: ci-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
tests-to-run: ${{ steps.test.outputs.tests-to-run }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'microsoft'
- name: Setup Gradle
uses: gradle/gradle-build-action@v3
# Runs the collect-tests shell script and sets the output variable
- name: Determine tests to run
id: test
run: |
#!/bin/bash
./.github/scripts/collect-tests.sh
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'microsoft'
- name: Setup Gradle
uses: gradle/gradle-build-action@v3
- name: Build
run: ./gradlew --info -s -x assemble
test:
name: "${{ matrix.test.displayName }} (${{ matrix.os }})"
runs-on: "${{ matrix.os }}-latest"
needs: setup
strategy:
max-parallel: 15
fail-fast: false
matrix:
test: ${{ fromJSON(needs.setup.outputs.tests-to-run) }}
os: [ubuntu, windows, macos]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
fetch-tags: true
- name: Setup JDK
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'microsoft'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: Test
if: ${{ matrix.test.filter != null }}
run: ./gradlew --info -s ${{ matrix.test.path }} --tests "${{ matrix.test.filter }}"
- name: Test
if: ${{ matrix.test.filter == null }}
run: ./gradlew --info -s ${{ matrix.test.path }}
# Always upload test results
- name: Merge Test Reports
if: success() || failure()
run: npx junit-report-merger junit.xml "**/TEST-*.xml"
- name: Format test run name as artifact name
if: (success() || failure()) && runner.os == 'Windows'
id: format-artifact-name-windows
# Use the GITHUB_OUTPUT mechanic to set the output variable
run: |
# We need to remove all invalid characters from the test name:
# Invalid characters include: Double quote ", Colon :, Less than <, Greater than >, Vertical bar |, Asterisk *, Question mark ?, Carriage return \r, Line feed \n, Backslash \, Forward slash /
$NAME = "${{ matrix.test.displayName }}" -replace '[":<>|*?\\/]', '-' -replace ' ', ''
# Check if the GITHUB_OUTPUT is set
Write-Output "Determined name to be $NAME-${{ matrix.os }}"
if ([string]::IsNullOrEmpty($env:GITHUB_OUTPUT)) {
# We do not have github output, then use the set output command
Write-Output "::set-output name=artifact-name::$NAME-${{ matrix.os }}"
exit
}
Add-Content -Path $env:GITHUB_OUTPUT -Value "artifact-name=$NAME-${{ matrix.os }}"
- name: Format test run name as artifact name
if: (success() || failure()) && runner.os != 'Windows'
id: format-artifact-name-unix
# Use the GITHUB_OUTPUT mechanic to set the output variable
run: |
# We need to remove all invalid characters from the test name:
# Invalid characters include: Double quote ", Colon :, Less than <, Greater than >, Vertical bar |, Asterisk *, Question mark ?, Carriage return \r, Line feed \n, Backslash \, Forward slash /
NAME=$(echo "${{ matrix.test.displayName }}" | tr '":<>|*?\\/' '-' | tr -d ' ')
# Check if the GITHUB_OUTPUT is set
echo "Determined name to be $NAME-${{ matrix.os }}"
if [ -z "$GITHUB_OUTPUT" ]; then
# We do not have github output, then use the set output command
echo "::set-output name=artifact-name::$NAME-${{ matrix.os }}"
exit 0
fi
echo "artifact-name=$NAME-${{ matrix.os }}" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
if: (success() || failure()) && runner.os != 'Windows'
with:
if-no-files-found: ignore
name: test-results-${{ steps.format-artifact-name-unix.outputs.artifact-name }}
path: junit.xml
retention-days: 1
- uses: actions/upload-artifact@v4
if: (success() || failure()) && runner.os == 'Windows'
with:
if-no-files-found: ignore
name: test-results-${{ steps.format-artifact-name-windows.outputs.artifact-name }}
path: junit.xml
retention-days: 1
process-test-data:
name: Process Test Data
runs-on: ubuntu-latest
needs: test
if: always()
steps:
- uses: actions/checkout@v3
- name: Download reports' artifacts
uses: actions/download-artifact@v4
with:
pattern: test-results-**
path: downloaded_artifacts
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: always() # always run even if the previous step fails
with:
report_paths: '**/*.xml'
- name: Merge Test Reports
if: always()
run: npx junit-report-merger junit.xml "**/*.xml"
- uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: junit.xml
- name: Failed build detection
uses: actions/github-script@v7
if: >-
${{
contains(needs.*.result, 'failure')
|| contains(needs.*.result, 'cancelled')
|| contains(needs.*.result, 'skipped')
}}
with:
script: |
core.setFailed('Test build failure!')