-
Notifications
You must be signed in to change notification settings - Fork 436
379 lines (357 loc) · 15.5 KB
/
pr.yml
File metadata and controls
379 lines (357 loc) · 15.5 KB
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
name: PR CI
on:
pull_request:
branches:
- master
paths-ignore:
- '.github/workflows/scripts-android.yml'
- '.github/workflows/scripts-ios.yml'
- 'scripts/**'
- '!scripts/setup-workspace.sh'
- 'docs/**'
- '**/*.md'
- '.github/workflows/developer-guide-docs.yml'
- '.github/workflows/website-docs.yml'
- '.github/workflows/initializr-cn1-version-pr.yml'
- 'CodenameOneDesigner/**'
- 'Ports/IOSPort/**'
push:
branches:
- master
paths-ignore:
- '.github/workflows/scripts-android.yml'
- '.github/workflows/scripts-ios.yml'
- 'scripts/**'
- '!scripts/setup-workspace.sh'
- 'docs/**'
- '**/*.md'
- '.github/workflows/developer-guide-docs.yml'
- '.github/workflows/website-docs.yml'
- '.github/workflows/initializr-cn1-version-pr.yml'
- 'CodenameOneDesigner/**'
- 'Ports/IOSPort/**'
permissions:
contents: write
pull-requests: write
issues: write
packages: read
jobs:
build-test:
runs-on: ubuntu-latest
container: ghcr.io/codenameone/codenameone/pr-ci-container:latest
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
java-version: [8, 17, 21]
steps:
- uses: actions/checkout@v1
- name: Set up Java
run: |
if [ "${{ matrix.java-version }}" = "8" ]; then
echo "JAVA_HOME=${JAVA_HOME_8}" >> $GITHUB_ENV
echo "${JAVA_HOME_8}/bin" >> $GITHUB_PATH
elif [ "${{ matrix.java-version }}" = "17" ]; then
echo "JAVA_HOME=${JAVA_HOME_17}" >> $GITHUB_ENV
echo "${JAVA_HOME_17}/bin" >> $GITHUB_PATH
elif [ "${{ matrix.java-version }}" = "21" ]; then
echo "JAVA_HOME=${JAVA_HOME_21}" >> $GITHUB_ENV
echo "${JAVA_HOME_21}/bin" >> $GITHUB_PATH
fi
- name: Cache Maven dependencies
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-m2
- name: Run Unit Tests
run: |
MVN_ARGS=""
if [ "${{ matrix.java-version }}" != "8" ]; then
MVN_ARGS="-Dspotbugs.skip=true"
fi
cd maven
mvn clean verify -DunitTests=true -pl core-unittests -am -Dmaven.javadoc.skip=true -Plocal-dev-javase $MVN_ARGS
cd ..
- name: Prepare Codename One binaries for Maven plugin tests
run: |
set -euo pipefail
rm -rf maven/target/cn1-binaries
mkdir -p maven/target
cp -r /opt/cn1-binaries maven/target/cn1-binaries
- name: Run Maven plugin tests
working-directory: maven
env:
CN1_BINARIES: ${{ github.workspace }}/maven/target/cn1-binaries
run: |
mvn -B -Dmaven.javadoc.skip=true \
-DunitTests=true \
-Dcodename1.platform=javase \
-Dcn1.binaries="${CN1_BINARIES}" \
-pl codenameone-maven-plugin -am -Plocal-dev-javase test
- name: Run SpotBugs for ports and Maven plugin
if: ${{ matrix.java-version == 8 }}
working-directory: maven
env:
CN1_BINARIES: ${{ github.workspace }}/maven/target/cn1-binaries
run: |
mvn -B -DskipTests=true \
-Dcn1.binaries="${CN1_BINARIES}" \
-Pcompile-android \
-pl android,ios,codenameone-maven-plugin -am verify
- name: Run SpotBugs for ByteCodeTranslator
if: ${{ matrix.java-version == 8 }}
run: mvn -B -DskipTests=true -f vm/ByteCodeTranslator/pom.xml verify
- name: Generate static analysis HTML summaries
if: ${{ always() && matrix.java-version == 8 }}
env:
QUALITY_REPORT_TARGET_DIRS: maven/core-unittests/target:maven/android/target:maven/ios/target:vm/ByteCodeTranslator/target:maven/codenameone-maven-plugin/target
QUALITY_REPORT_SERVER_URL: ${{ github.server_url }}
QUALITY_REPORT_REPOSITORY: ${{ github.repository }}
QUALITY_REPORT_REF: ${{ github.event.pull_request.head.sha || github.sha }}
QUALITY_REPORT_GENERATE_HTML_ONLY: "1"
run: python3 .github/scripts/generate-quality-report.py
- name: Collect quality artifacts
if: ${{ always() && matrix.java-version == 8 }}
run: |
set -euo pipefail
mkdir -p quality-artifacts/static-analysis
mkdir -p quality-artifacts/coverage
shopt -s nullglob
for entry in \
"core-unittests:maven/core-unittests/target" \
"android:maven/android/target" \
"ios:maven/ios/target" \
"bytecode-translator:vm/ByteCodeTranslator/target" \
"maven-plugin:maven/codenameone-maven-plugin/target"; do
label="${entry%%:*}"
dir="${entry#*:}"
for filename in spotbugsXml.xml spotbugs.xml; do
if [ -f "${dir}/${filename}" ]; then
cp "${dir}/${filename}" "quality-artifacts/static-analysis/spotbugs-${label}.xml"
break
fi
done
done
if [ -f maven/core-unittests/target/pmd.xml ]; then
cp maven/core-unittests/target/pmd.xml quality-artifacts/static-analysis/
fi
if [ -f maven/core-unittests/target/checkstyle-result.xml ]; then
cp maven/core-unittests/target/checkstyle-result.xml quality-artifacts/static-analysis/
fi
if [ -d target/quality-report ]; then
mkdir -p quality-artifacts/static-analysis/html
cp -R target/quality-report/. quality-artifacts/static-analysis/html/
fi
if [ -d maven/core-unittests/target/site/jacoco ]; then
cp -R maven/core-unittests/target/site/jacoco quality-artifacts/coverage/
fi
if [ "$(find quality-artifacts -type f | wc -l)" -eq 0 ]; then
echo "No quality artifacts were generated." > quality-artifacts/README.txt
fi
- name: Upload quality artifacts
if: ${{ always() && matrix.java-version == 8 }}
id: upload-quality-artifacts
uses: actions/upload-artifact@v4
with:
name: quality-artifacts
path: quality-artifacts
- name: Publish quality report previews
if: ${{ always() && matrix.java-version == 8 && github.server_url == 'https://github.com' && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) }}
id: publish-quality-previews
env:
GITHUB_TOKEN: ${{ github.token }}
SERVER_URL: ${{ github.server_url }}
REPOSITORY: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
run: |
set -euo pipefail
if [ "${SERVER_URL}" != "https://github.com" ]; then
echo "HTML previews are only published for github.com instances."
exit 0
fi
run_dir="runs/${RUN_ID}-${RUN_ATTEMPT}"
tmp_dir=$(mktemp -d)
dest_dir="${tmp_dir}/${run_dir}"
mkdir -p "${dest_dir}"
has_content=0
if compgen -G "target/quality-report/*.html" > /dev/null; then
mkdir -p "${dest_dir}/static-analysis"
cp target/quality-report/*.html "${dest_dir}/static-analysis/"
has_content=1
fi
if [ -d maven/core-unittests/target/site/jacoco ] && [ -f maven/core-unittests/target/site/jacoco/index.html ]; then
mkdir -p "${dest_dir}/coverage"
cp -R maven/core-unittests/target/site/jacoco/. "${dest_dir}/coverage/"
has_content=1
fi
if [ "${has_content}" -eq 0 ]; then
echo "No HTML outputs detected; skipping preview publishing."
exit 0
fi
printf '%s\n%s\n%s\n' \
'# Quality report previews' \
'' \
'This branch is automatically managed by the PR CI workflow and may be force-pushed.' \
> "${tmp_dir}/README.md"
git -C "${tmp_dir}" init -b previews >/dev/null
git -C "${tmp_dir}" config user.name "github-actions[bot]"
git -C "${tmp_dir}" config user.email "github-actions[bot]@users.noreply.github.com"
git -C "${tmp_dir}" add .
git -C "${tmp_dir}" commit -m "Publish quality report previews for run ${RUN_ID} (attempt ${RUN_ATTEMPT})" >/dev/null
remote_url="${SERVER_URL}/${REPOSITORY}.git"
token_remote_url="${remote_url/https:\/\//https://x-access-token:${GITHUB_TOKEN}@}"
git -C "${tmp_dir}" push --force "${token_remote_url}" previews:quality-report-previews >/dev/null
commit_sha=$(git -C "${tmp_dir}" rev-parse HEAD)
raw_base="https://raw.githubusercontent.com/${REPOSITORY}/${commit_sha}/${run_dir}"
preview_base="https://htmlpreview.github.io/?${raw_base}"
{
echo "commit=${commit_sha}"
echo "run_path=${run_dir}"
} >> "$GITHUB_OUTPUT"
if [ -f "${dest_dir}/static-analysis/spotbugs.html" ]; then
echo "spotbugs_url=${preview_base}/static-analysis/spotbugs.html" >> "$GITHUB_OUTPUT"
fi
if [ -f "${dest_dir}/static-analysis/pmd.html" ]; then
echo "pmd_url=${preview_base}/static-analysis/pmd.html" >> "$GITHUB_OUTPUT"
fi
if [ -f "${dest_dir}/static-analysis/checkstyle.html" ]; then
echo "checkstyle_url=${preview_base}/static-analysis/checkstyle.html" >> "$GITHUB_OUTPUT"
fi
if [ -f "${dest_dir}/coverage/index.html" ]; then
echo "jacoco_url=${preview_base}/coverage/index.html" >> "$GITHUB_OUTPUT"
fi
- name: Generate quality report summary
if: ${{ always() && matrix.java-version == 8 }}
env:
QUALITY_REPORT_TARGET_DIRS: maven/core-unittests/target:maven/android/target:maven/ios/target:vm/ByteCodeTranslator/target:maven/codenameone-maven-plugin/target
QUALITY_REPORT_SERVER_URL: ${{ github.server_url }}
QUALITY_REPORT_REPOSITORY: ${{ github.repository }}
QUALITY_REPORT_REF: ${{ github.event.pull_request.head.sha || github.sha }}
SPOTBUGS_REPORT_URL: ${{ steps.upload-quality-artifacts.outputs.artifact-url }}
PMD_REPORT_URL: ${{ steps.upload-quality-artifacts.outputs.artifact-url }}
CHECKSTYLE_REPORT_URL: ${{ steps.upload-quality-artifacts.outputs.artifact-url }}
JACOCO_REPORT_URL: ${{ steps.upload-quality-artifacts.outputs.artifact-url }}
SPOTBUGS_HTML_URL: ${{ steps.publish-quality-previews.outputs.spotbugs_url }}
PMD_HTML_URL: ${{ steps.publish-quality-previews.outputs.pmd_url }}
CHECKSTYLE_HTML_URL: ${{ steps.publish-quality-previews.outputs.checkstyle_url }}
JACOCO_HTML_URL: ${{ steps.publish-quality-previews.outputs.jacoco_url }}
run: python3 .github/scripts/generate-quality-report.py
- name: Upload quality report summary
if: ${{ always() && matrix.java-version == 8 }}
uses: actions/upload-artifact@v4
with:
name: quality-report
path: quality-report.md
- name: Publish quality report comment
if: ${{ github.event_name == 'pull_request' && matrix.java-version == 8 }}
uses: actions/github-script@v7
with:
script: |
const { publishQualityComment } = require('./.github/scripts/publish-quality-comment.js');
await publishQualityComment({ github, context, core });
- name: Link cn1-binaries
run: ln -s /opt/cn1-binaries ../cn1-binaries
- name: Build CLDC11 JAR
run: |
ANT_OPTS_ARGS=""
if [ "${{ matrix.java-version }}" != "8" ]; then
ANT_OPTS_ARGS="-Djavac.source=1.8 -Djavac.target=1.8"
fi
ant $ANT_OPTS_ARGS -noinput -buildfile Ports/CLDC11/build.xml jar
- name: Build with Ant
run: |
mkdir -p ~/.codenameone
cp maven/UpdateCodenameOne.jar ~/.codenameone/
ANT_OPTS_ARGS=""
if [ "${{ matrix.java-version }}" != "8" ]; then
ANT_OPTS_ARGS="-Djavac.source=1.8 -Djavac.target=1.8"
fi
xvfb-run ant $ANT_OPTS_ARGS test-javase
- name: Build Release
if: matrix.java-version == 8
run: ant -noinput -buildfile CodenameOne/build.xml weeklyLibUpdate
- name: Set up Java 25 for JavaDocs
if: matrix.java-version == 8
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '25'
- name: Build JavaDocs
if: matrix.java-version == 8
run: ./.github/scripts/build_javadocs.sh
- name: Restore Java 8 after JavaDocs
if: matrix.java-version == 8
run: |
echo "JAVA_HOME=${JAVA_HOME_8}" >> $GITHUB_ENV
echo "${JAVA_HOME_8}/bin" >> $GITHUB_PATH
- name: Upload JavaDocs artifact
if: matrix.java-version == 8
uses: actions/upload-artifact@v4
with:
name: CodenameOne-javadocs
path: CodenameOne/javadocs.zip
- name: Build iOS Port
run: |
ANT_OPTS_ARGS=""
if [ "${{ matrix.java-version }}" != "8" ]; then
ANT_OPTS_ARGS="-Djavac.source=1.8 -Djavac.target=1.8"
fi
ant $ANT_OPTS_ARGS -noinput -buildfile Ports/iOSPort/build.xml jar
- name: Build iOS VM API
run: mvn -f vm/JavaAPI/pom.xml package
- name: Upload a Build Artifact
if: matrix.java-version == 8
uses: actions/upload-artifact@v4
with:
name: JavaAPI.jar
path: vm/JavaAPI/target/JavaAPI-1.0-SNAPSHOT.jar
- name: Build iOS VM
run: mvn -f vm/ByteCodeTranslator/pom.xml package
- name: Build CLDC 11 VM
run: |
ANT_OPTS_ARGS=""
if [ "${{ matrix.java-version }}" != "8" ]; then
ANT_OPTS_ARGS="-Djavac.source=1.8 -Djavac.target=1.8"
fi
ant $ANT_OPTS_ARGS -noinput -buildfile Ports/CLDC11/build.xml jar
- name: Upload a Build Artifact
if: matrix.java-version == 8
uses: actions/upload-artifact@v4
with:
name: ByteCodeTranslator.jar
path: vm/ByteCodeTranslator/target/ByteCodeTranslator-1.0-SNAPSHOT.jar
- name: Upload a Build Artifact
if: matrix.java-version == 8
uses: actions/upload-artifact@v4
with:
name: CLDC11.jar
path: Ports/CLDC11/dist/CLDC11.jar
- name: Build Android Port
run: |
ANT_OPTS_ARGS=""
if [ "${{ matrix.java-version }}" != "8" ]; then
ANT_OPTS_ARGS="-Djavac.source=1.8 -Djavac.target=1.8"
fi
ant $ANT_OPTS_ARGS -noinput -buildfile Ports/Android/build.xml jar
- name: Packaging Everything
if: matrix.java-version == 8
run: zip -j result.zip CodenameOne/javadocs.zip CodenameOne/dist/CodenameOne.jar CodenameOne/updatedLibs.zip Ports/JavaSE/dist/JavaSE.jar build/CodenameOneDist/CodenameOne/demos/CodenameOne_SRC.zip
- name: Copying Files to Server
if: matrix.java-version == 8
uses: marcodallasanta/ssh-scp-deploy@v1.0.5
with:
host: ${{ secrets.WP_HOST }}
user: ${{ secrets.WP_USER }}
password: ${{ secrets.WP_PASSWORD }}
local: result.zip
- name: Upload a Build Artifact
if: matrix.java-version == 8
uses: actions/upload-artifact@v4
with:
name: JavaSE.jar
path: Ports/JavaSE/dist/JavaSE.jar