-
Notifications
You must be signed in to change notification settings - Fork 2
237 lines (227 loc) · 9.57 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
229
230
231
232
233
234
235
236
237
name: 'Validate and publish'
on:
workflow_dispatch:
push:
branches: [ master, releases/** ]
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
branches: [ master, releases/** ]
env:
# Enable local build caching and disable daemon
GRADLE_OPTS: -Dorg.gradle.caching=true -Dorg.gradle.daemon=false
jobs:
configuration:
name: Configure build
runs-on: ubuntu-latest
outputs:
is_pr: ${{ steps.configuration.outputs.is_pr }}
is_fork_pr: ${{ steps.configuration.outputs.is_fork_pr }}
is_release: ${{ steps.configuration.outputs.is_release }}
publish_version: ${{ steps.get_publish_version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v3
# we need to fetch tags in order for the Axion plugin to properly determine the current snapshot version
- name: Fetch all tags
run: git fetch --prune --unshallow --tags --force
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: '8'
java-package: jdk
architecture: x64
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- id: get_publish_version
name: Extract publish version
run: |
echo 'run gradle warmup'
./gradlew
echo 'set version'
echo "version=`./gradlew cV -q -Prelease.quiet`" >> $GITHUB_OUTPUT
- id: configuration
name: Configure
run: |
echo "is_pr=${{ github.event_name == 'pull_request' || '' }}" >> $GITHUB_OUTPUT
echo "is_fork_pr=${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository || '' }}" >> $GITHUB_OUTPUT
echo "is_release=${{ !endsWith(steps.get_publish_version.outputs.version, '-SNAPSHOT') || '' }}" >> $GITHUB_OUTPUT
- name: Print summary
run: |
[[ '${{ steps.configuration.outputs.is_pr }}' ]] && echo "Running on a pull-request (${{ steps.configuration.outputs.is_fork_pr && 'from a fork' || 'internal' }})." >> $GITHUB_STEP_SUMMARY
[[ '${{ steps.configuration.outputs.is_pr }}' ]] && exit 0
echo "Publish version is ${{ steps.get_publish_version.outputs.version }} (${{ steps.configuration.outputs.is_release && 'RELEASE' || 'SNAPSHOT' }} version)." >> $GITHUB_STEP_SUMMARY
- name: Fail build in case of configuration inconsistency
if: ${{ steps.configuration.outputs.is_fork_pr && !steps.configuration.outputs.is_pr || steps.configuration.outputs.is_release && !startsWith(github.ref, 'refs/tags/v') }}
run: |
echo 'Failed to configure workflow.'
exit 1
validation:
name: Validate Gradle wrapper
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v3
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
compile:
name: Compile sources
needs: validation
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: '8'
java-package: jdk
architecture: x64
distribution: 'temurin'
- name: Compile sources
uses: gradle/gradle-build-action@v2
with:
arguments: clean testClasses
test:
name: Run tests
needs: compile
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: '8'
java-package: jdk
architecture: x64
distribution: 'temurin'
- name: Run tests
uses: gradle/gradle-build-action@v2
with:
arguments: test
- name: Create JUnit HTML test report artifact
# don't run this step only if workflow was cancelled
if: ${{ success() || failure() }}
uses: actions/upload-artifact@v3
with:
name: junit-html-test-report
path: build/reports/tests/test
- name: Create JUnit XML test report artifact
# don't run this step only if workflow was cancelled
if: ${{ success() || failure() }}
uses: actions/upload-artifact@v3
with:
name: junit-xml-test-report
path: build/test-results/test
publish_test_results_overview:
name: Publish test results overview
# don't run this job only if workflow was cancelled
if: ${{ success() || failure() }}
concurrency: gh-pages-test-results
needs: test
runs-on: ubuntu-latest
steps:
- name: Download XML test results artifact
uses: actions/download-artifact@v3
with:
name: junit-xml-test-report
path: junit-xml-test-report
- name: Publish summary
uses: EnricoMi/publish-unit-test-result-action@v2
with:
junit_files: junit-xml-test-report/**/*.xml
check_name: Test results overview
publish_html_test_report:
name: Publish HTML test report
needs: [ test, configuration ]
# don't run this job only if workflow was cancelled, or we're running on a fork PR
if: ${{ !needs.configuration.outputs.is_fork_pr && (success() || failure()) }}
runs-on: ubuntu-latest
outputs:
test_report_url: ${{ steps.generate_report_url.outputs.test_report_url }}
steps:
- name: Download XML test results artifact
uses: actions/download-artifact@v3
with:
name: junit-html-test-report
path: junit-html-test-report
- name: Generate report path
id: generate_report_path
run: echo 'test_report_path=test-results/${{ github.run_id }}/${{ github.run_attempt }}' >> $GITHUB_OUTPUT
- name: Publish report to Github Pages
uses: peaceiris/actions-gh-pages@v3
if: ${{ always() }}
with:
external_repository: fingo/results-xactus
deploy_key: ${{ secrets.XACTUS_RESULTS_TOKEN }}
publish_dir: ./junit-html-test-report
destination_dir: ${{ steps.generate_report_path.outputs.test_report_path }}
keep_files: true
- name: Generate report URL
id: generate_report_url
run: echo 'test_report_url=https://fingo.github.io/results-xactus/${{ steps.generate_report_path.outputs.test_report_path }}' >> $GITHUB_OUTPUT
- name: Place report URL in the summary
run: |
echo 'Link to the HTML test report: <${{ steps.generate_report_url.outputs.test_report_url }}>' >> $GITHUB_STEP_SUMMARY
publish:
name: Publish artifacts
needs: [ test, configuration ]
if: ${{ !needs.configuration.outputs.is_pr }}
runs-on: ubuntu-latest
outputs:
artifact_url: ${{ steps.publication_configuration.outputs.artifact_url }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: '8'
java-package: jdk
architecture: x64
distribution: 'temurin'
- name: Configure publication
id: publication_configuration
run: |
echo 'ORG_GRADLE_PROJECT_version=${{ needs.configuration.outputs.publish_version }}' >> $GITHUB_ENV
echo 'ORG_GRADLE_PROJECT_ossrhUserName=${{ secrets.OSSRH_USERNAME }}' >> $GITHUB_ENV
echo 'ORG_GRADLE_PROJECT_ossrhPassword=${{ secrets.OSSRH_TOKEN }}' >> $GITHUB_ENV
if [[ '${{ needs.configuration.outputs.is_release }}' ]]
then
echo 'ORG_GRADLE_PROJECT_pgpSecretKeyPassword=${{ secrets.MAVEN_GPG_PASSPHRASE }}' >> $GITHUB_ENV
echo 'ORG_GRADLE_PROJECT_pgpSecretKey<<EOF' >> $GITHUB_ENV
echo "${{ secrets.MAVEN_GPG_PRIVATE_KEY }}" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
fi
echo 'arguments=${{ needs.configuration.outputs.is_release && 'publishToSonatype closeAndReleaseSonatypeStagingRepository' || 'publishToSonatype' }}' >> $GITHUB_OUTPUT
echo 'artifact_url=${{ format(needs.configuration.outputs.is_release && 'https://repo.maven.apache.org/maven2/info/fingo/xactus/xactus/{0}/' || 'https://oss.sonatype.org/content/repositories/snapshots/info/fingo/xactus/xactus/{0}/', needs.configuration.outputs.publish_version) }}' >> $GITHUB_OUTPUT
- name: Publish
uses: gradle/gradle-build-action@v2
with:
arguments: -i ${{ steps.publication_configuration.outputs.arguments }}
- name: Place artifact URL in the summary
run: |
echo "Published artifact URL: ${{ steps.publication_configuration.outputs.artifact_url }}" >> $GITHUB_STEP_SUMMARY
slack:
needs: [ test, publish, publish_html_test_report, configuration ]
# don't run this job only if we're running on a fork PR
if: ${{ !needs.configuration.outputs.is_fork_pr && always() }}
name: Send out Slack notification
runs-on: ubuntu-latest
steps:
- name: Send Slack message
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.XPATH_SLACK_URL }}
SLACK_COLOR: ${{job.status}}
SLACK_ICON: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png
SLACK_USERNAME: Github
SLACK_TITLE: Reports
SLACK_MESSAGE: |
*HTML test report*
${{ needs.publish_html_test_report.outputs.test_report_url }}
*Artifact URL*
${{ needs.publish.outputs.artifact_url }}
_Usually artifacts and test results become available with a delay (usually up to a few minutes, but sometimes it may take longer)._