-
Notifications
You must be signed in to change notification settings - Fork 2
338 lines (321 loc) · 11.3 KB
/
pull-requests.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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
name: Pull Request Build
on: pull_request
# if another commit is added to the PR (same github.head_ref), then cancel already running jobs
# and start a new build
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
permissions:
contents: read # to fetch code (actions/checkout)
env:
LANG: 'en_US.UTF-8'
jobs:
compile:
runs-on: ubuntu-latest
timeout-minutes: 20
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- uses: actions/cache@v4
with:
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: maven-
path: ~/.m2/repository
enableCrossOsArchive: true
- name: Fast Build with Maven
run: |
./mvnw --show-version --errors --batch-mode \
verify -PfastSkip -DskipTests \
deploy:deploy -DdogfoodStagingRepo="$(pwd)/target/staging"
- name: Cleanup local repository
run: |
# Cleanup local repository to not poison the shared cache with our SNAPSHOTS of the current build.
# Some information is stored in maven-metadata-*.xml files which tells maven which
# version exactly is available in the staging repo. But if we rerun the build using the
# older cache, it points to the old staging versions, which are not available anymore.
find ~/.m2/repository/net/sourceforge/pmd -type d -name "*-SNAPSHOT" -and -not -wholename "*/pmd-designer/*" | xargs rm -vrf
- uses: actions/upload-artifact@v4
with:
name: compile-artifact
if-no-files-found: error
path: |
*/target
*/*/target
!pmd-dist/target/pmd-dist-*-bin.zip
!pmd-dist/target/pmd-dist-*-src.zip
- uses: actions/upload-artifact@v4
with:
name: staging-repository
if-no-files-found: error
path: target/staging
- uses: actions/upload-artifact@v4
with:
name: dist-artifact
if-no-files-found: error
path: |
pmd-dist/target/pmd-dist-*-bin.zip
pmd-dist/target/pmd-dist-*-src.zip
verify:
needs: compile
timeout-minutes: 30
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- uses: actions/cache@v4
with:
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: maven-
path: ~/.m2/repository
enableCrossOsArchive: true
- uses: actions/download-artifact@v4
with:
name: compile-artifact
- name: Full Build with Maven
run: |
./mvnw --show-version --errors --batch-mode \
verify \
-DskipTests -Dmaven.test.skip=true
verify-unittests:
needs: compile
timeout-minutes: 30
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
# don't fail fast - we want to know the results of all runs
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-java@v4
# under linux we execute more extensive integration tests with various java versions
if: ${{ runner.os == 'Linux' }}
with:
distribution: 'temurin'
java-version: |
8
17
21
- uses: actions/setup-java@v4
# default java version for all os is 11
with:
distribution: 'temurin'
java-version: '11'
# only restore the cache, don't create a new cache
# under Windows, hashFiles('**/pom.xml') gives a different result due to line endings
- uses: actions/cache/restore@v4
with:
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: maven-
path: ~/.m2/repository
enableCrossOsArchive: true
- uses: actions/download-artifact@v4
# we can only reuse compile-artifacts under linux due to file timestamp issues and
# platform specific line endings in test files.
if: ${{ runner.os == 'Linux' }}
with:
name: compile-artifact
- name: Build with Maven and run unit tests
run: |
./mvnw --show-version --errors --batch-mode \
verify \
-PfastSkip -Dcyclonedx.skip=false \
-Djava8.home="${JAVA_HOME_8_X64}" \
-Djava17.home="${JAVA_HOME_17_X64}" \
-Djava21.home="${JAVA_HOME_21_X64}"
dogfood:
needs: compile
timeout-minutes: 30
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- uses: actions/cache@v4
with:
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: maven-
path: ~/.m2/repository
enableCrossOsArchive: true
- uses: actions/download-artifact@v4
with:
name: compile-artifact
- uses: actions/download-artifact@v4
with:
name: staging-repository
path: target/staging
- name: Run PMD on PMD
run: |
# this only works if the triggering event of this workflow is "pull_request"
pr_number="$(jq -r ".number" "${GITHUB_EVENT_PATH}")"
echo "Determined PR number: ${pr_number}"
current_pmd_version=$(./mvnw --batch-mode --no-transfer-progress \
help:evaluate -Dexpression=project.version -q -DforceStdout || echo "failed_to_determine_current_pmd_version")
echo "Determined current pmd version: ${current_pmd_version}"
new_version="${current_pmd_version}-pr-${pr_number}-dogfood-SNAPSHOT"
echo "::group::Set version to ${new_version}"
./mvnw versions:set --quiet -DnewVersion="${new_version}" -DgenerateBackupPoms=false
sed -i 's/<version>[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}.*<\/version>\( *<!-- pmd.dogfood.version -->\)/<version>'"${current_pmd_version}"'<\/version>\1/' pom.xml
echo "::endgroup::"
echo "::group::Run ./mvnw verify"
./mvnw --show-version --errors --batch-mode \
verify \
-PfastSkip \
-DdogfoodStagingRepo="$(pwd)/target/staging" \
-DskipTests \
-Dpmd.skip=false \
-Dcpd.skip=false
echo "::endgroup::"
echo "::group::Restore version to ${current_pmd_version}"
./mvnw versions:set --quiet -DnewVersion="${current_pmd_version}" -DgenerateBackupPoms=false
git checkout -- pom.xml
echo "::endgroup::"
documentation:
needs: compile
timeout-minutes: 30
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- uses: actions/cache@v4
with:
key: maven-${{ hashFiles('**/pom.xml') }}
restore-keys: maven-
path: ~/.m2/repository
enableCrossOsArchive: true
- uses: actions/download-artifact@v4
with:
name: compile-artifact
- name: Generate rule docs
run: |
./mvnw --show-version --errors --batch-mode \
verify \
-Pgenerate-rule-docs,fastSkip \
-DskipTests -Dmaven.test.skip=true -Dassembly.skipAssembly=true
- name: Set up Ruby 3.3
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
- name: Setup bundler
run: |
cd docs
bundle config set --local path vendor/bundle
bundle install
- name: Build documentation
run: |
cd docs
bundle exec jekyll build
- uses: actions/upload-artifact@v4
with:
name: docs-artifact
if-no-files-found: error
path: docs/_site
regressiontester:
needs: compile
timeout-minutes: 60
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
- name: Set up Ruby 3.3
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.3
- uses: actions/cache@v4
with:
path: |
~/.m2/repository
~/.gradle/caches
~/work/pmd/target/repositories
vendor/bundle
key: regressiontester-${{ hashFiles('.ci/files/project-list.xml', 'Gemfile.lock') }}
restore-keys: regressiontester-
- uses: actions/download-artifact@v4
with:
name: dist-artifact
path: pmd-dist/target
- name: Setup bundler
run: |
bundle config set --local gemfile .ci/files/Gemfile
bundle config set --local path vendor/bundle
bundle install
- name: Prepare HOME/openjdk11
run: |
ln -sfn "${JAVA_HOME_11_X64}" "${HOME}/openjdk11"
- name: Run pmdtester
env:
# this only works if the triggering event of this workflow is "pull_request"
PMD_CI_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
PMD_CI_BRANCH: ${{ github.base_ref }}
run: |
echo "::group::Fetching additional commits"
# git clone initially only fetched with depth 2. Regression tester
# needs more history, so we'll fetch more here
# and create local branches as well (${PMD_CI_BRANCH} and pr-fetch)
echo "Fetching 25 commits for ${PMD_CI_BRANCH} and pull/${PMD_CI_PULL_REQUEST_NUMBER}/head"
git fetch --no-tags --depth=25 origin "${PMD_CI_BRANCH}:${PMD_CI_BRANCH}" "pull/${PMD_CI_PULL_REQUEST_NUMBER}/head:pr-fetch"
# if the PR is older, base might have advanced more than 25 commits... fetch more, up to 150
for i in $(seq 1 3); do
if [ -z "$( git merge-base "${PMD_CI_BRANCH}" "pr-fetch" )" ]; then
echo "No merge-base yet - fetching more commits... (try $i)"
git fetch --no-tags --deepen=50 origin "${PMD_CI_BRANCH}:" "pull/${PMD_CI_PULL_REQUEST_NUMBER}/head:pr-fetch"
fi
done
echo "Merge base is: $( git merge-base "${PMD_CI_BRANCH}" "pr-fetch" )"
echo "::endgroup::"
echo "::group::Running pmdtester on branch ${PMD_CI_BRANCH}"
bundle exec ruby .ci/files/pmdtester.rb
echo "::endgroup::"
- name: Workaround actions/upload-artifact#176
run: |
echo "artifacts_path=$(realpath ..)" >> "${GITHUB_ENV}"
- name: Upload regression tester report
uses: actions/upload-artifact@v4
with:
name: pmd-regression-tester
if-no-files-found: error
path: ${{ env.artifacts_path }}/target/reports/diff