-
Notifications
You must be signed in to change notification settings - Fork 24
148 lines (125 loc) · 4.08 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
name: Test PRs
run-name: Tests for PR ${{ github.event.pull_request.number }}
on:
pull_request:
types:
- synchronize
- opened
- ready_for_review
- reopened
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: Test
runs-on: ubuntu-latest
needs: setup
strategy:
fail-fast: false
matrix:
test: ${{ fromJSON(needs.setup.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
- name: Test
run: ./gradlew --info -s ${{ matrix.test }}
# 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
id: format-artifact-name
# Use the GITHUB_OUTPUT mechanic to set the output variable
run: |
# We have two cases here, one with a gradle task path, there we replace the : with a - and strip the leading -
# The other case is complexer, again we replace the : with a - and strip the leading - but now we also remove the ' --tests ' part
# Remove the '"' from the string and replace the '.' with a '-'
NAME=$(echo "${{ matrix.test }}" | sed 's/:/-/g' | sed 's/^-//' | sed 's/ --tests /-/g' | sed 's/"//g' | sed 's/\./-/g')
# Check if the GITHUB_OUTPUT is set
if [ -z "$GITHUB_OUTPUT" ]; then
# We do not have github output, then use the set output command
echo "::set-output name=artifact-name::$NAME"
exit 0
fi
echo "artifact-name=$NAME" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
if-no-files-found: ignore
name: test-results-${{ steps.format-artifact-name.outputs.artifact-name }}
path: junit.xml
retention-days: 1
process-test-data:
runs-on: ubuntu-latest
needs: test
if: success() || failure()
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: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/*.xml'
- name: Merge Test Reports
if: success() || failure()
run: npx junit-report-merger junit.xml "**/*.xml"
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: test-results
path: junit.xml