Repository navigation
319 lines (288 loc) · 11.5 KB
/
Copy pathjava-test.yaml
File metadata and controls
319 lines (288 loc) · 11.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
name: java-test
on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
branches:
- main
paths:
- "java/**"
# The consistency runner reads this shared manifest, so a golden-only
# change must re-run this workflow.
- "tests/consistency/**"
- ".github/workflows/java-test.yaml"
workflow_dispatch:
jobs:
test-and-build:
permissions:
actions: write # for styfle/cancel-workflow-action to cancel/stop running workflows
contents: read # for actions/checkout to fetch code
name: "${{ matrix.root-pom }} on JDK ${{ matrix.java }} for the classifier ${{ matrix.classifier }}"
strategy:
matrix:
include:
- os: ubuntu-latest
classifier: linux-aarch_64
java: 8
root-pom: 'pom.xml'
- os: windows-latest
classifier: windows-x86_64
java: 8
root-pom: 'pom.xml'
- os: macos-latest
classifier: osx-x86_64
java: 8
root-pom: 'pom.xml'
- os: macos-latest
classifier: osx-aarch_64
java: 8
root-pom: 'pom.xml'
runs-on: ${{ matrix.os }}
env:
ROOT_POM: ${{ matrix.root-pom }}
steps:
- uses: actions/checkout@v7
- name: 'Set up JDK ${{ matrix.java }}'
uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad
with:
java-version: ${{ matrix.java }}
distribution: 'zulu'
cache: 'maven'
- uses: actions/setup-python@v7
with:
python-version: '3.10'
- name: Install rust nightly toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.91
override: true
components: clippy, rustfmt
- name: Setup linux-aarch_64 rust target
if: "contains(matrix.classifier, 'linux-aarch_64')"
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
# Setup for cargo
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: 'Test'
shell: bash
working-directory: java
run: make test
- name: 'Build and Deploy'
shell: bash
working-directory: java
run: mvn clean package -DskipTests=true -Djni.classifier=${{ matrix.classifier }} -Dcargo-build.profile=release
- name: 'Upload artifact'
uses: actions/upload-artifact@v7
with:
name: kcl-lib-${{ matrix.classifier }}
path: |
java/target/classes/native
build-centos7:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [ test-and-build ]
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Download windows x86_64 lib
uses: actions/download-artifact@v8
with:
name: kcl-lib-windows-x86_64
path: java/native
- name: Download linux aarch_64 lib
uses: actions/download-artifact@v8
with:
name: kcl-lib-linux-aarch_64
path: java/native
- name: Download darwin x86_64 lib
uses: actions/download-artifact@v8
with:
name: kcl-lib-osx-x86_64
path: java/native
- name: Download darwin aarch_64 lib
uses: actions/download-artifact@v8
with:
name: kcl-lib-osx-aarch_64
path: java/native
- name: Run tests and package in CentOS 7 container
run: |
docker run --rm -v ${{ github.workspace }}/java:/work kcllang/kcl-java-builder-centos7:latest bash -c "
cd /work &&
rustup default stable &&
mvn package -DskipTests=true -Dcargo-build.profile=release
"
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: kcl-lib
path: java/target/*.jar
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [ test-and-build, build-centos7 ]
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up JDK 8
uses: actions/setup-java@v6.1.0
with:
distribution: 'temurin'
java-version: '8'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Download Jar
uses: actions/download-artifact@v8
with:
name: kcl-lib
path: java/release
- name: Release to Github Packages
if: "startsWith(github.ref, 'refs/tags/')"
working-directory: java
run: |
JAR_FILE=$(find ./release -name "*.jar" ! -name "*sources.jar")
echo "Deploying $JAR_FILE"
mvn deploy:deploy-file \
-Dfile=$JAR_FILE \
-DpomFile=./pom.xml \
-DrepositoryId=github \
-Durl=https://maven.pkg.github.com/kcl-lang/lib \
-s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}
# Maven Central publishing. Requires the four secrets listed in
# java/pom.xml's `central` profile comment to be set in repo settings.
# The job is skipped (not failed) when any secret is missing so the
# workflow can land the scaffold without red builds, and quietly
# enables Central publishing once the operator fills them in.
# The secrets context is unavailable in job-level `if` conditions, so
# the presence of the Central Portal credentials is computed here and
# consumed by deploy-central through job outputs. Skipped entirely on
# non-tag runs.
check-central-secrets:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
outputs:
present: ${{ steps.check.outputs.present }}
steps:
- id: check
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
MAVEN_CENTRAL_GPG_PRIVATE_KEY: ${{ secrets.MAVEN_CENTRAL_GPG_PRIVATE_KEY }}
MAVEN_CENTRAL_GPG_PASSPHRASE: ${{ secrets.MAVEN_CENTRAL_GPG_PASSPHRASE }}
run: |
if [ -n "$MAVEN_CENTRAL_USERNAME" ] && [ -n "$MAVEN_CENTRAL_TOKEN" ] &&
[ -n "$MAVEN_CENTRAL_GPG_PRIVATE_KEY" ] && [ -n "$MAVEN_CENTRAL_GPG_PASSPHRASE" ]; then
echo "present=true" >> "$GITHUB_OUTPUT"
else
echo "Central Portal secrets not configured; skipping the publish job"
echo "present=false" >> "$GITHUB_OUTPUT"
fi
# Probes the credentials against the Central Portal before the (slow)
# deploy-central job burns a full Rust rebuild on a doomed publish.
# A GET is rejected with 401 when auth fails and 500 once auth passes,
# since the upload endpoint only accepts POST multipart bodies.
- name: Probe Central Portal credentials
env:
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
run: |
set -uo pipefail
# Diagnostics only — never prints the secret. Length, a short
# digest and a whitespace check tell a malformed secret apart from
# a valid one without exposing either value.
for v in MAVEN_CENTRAL_USERNAME MAVEN_CENTRAL_TOKEN; do
val="${!v}"
echo "::group::$v"
echo "bytes: $(printf %s "$val" | wc -c | tr -d ' ')"
echo "sha256[0:8]: $(printf %s "$val" | sha256sum | cut -c1-8)"
if [ -z "$val" ]; then
echo "state: EMPTY"
elif [ "$val" != "$(printf %s "$val" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" ]; then
echo "state: leading/trailing WHITESPACE — this breaks HTTP Basic auth"
else
echo "state: clean"
fi
echo "::endgroup::"
done
code=$(curl -sS -o /dev/null -w '%{http_code}' --max-time 20 \
-u "$MAVEN_CENTRAL_USERNAME:$MAVEN_CENTRAL_TOKEN" \
https://central.sonatype.com/api/v1/publisher/upload) || code="000"
echo "Central Portal credential probe: HTTP $code (401 = credentials rejected, 500 = auth OK / endpoint rejects GET)"
if [ "$code" = "401" ]; then
echo "::error::Central Portal rejected MAVEN_CENTRAL_USERNAME/MAVEN_CENTRAL_TOKEN"
exit 1
fi
deploy-central:
runs-on: ubuntu-latest
permissions:
contents: read
needs: [ test-and-build, build-centos7, check-central-secrets ]
if: >-
startsWith(github.ref, 'refs/tags/') &&
needs.check-central-secrets.outputs.present == 'true'
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up JDK 8 + Central Portal credentials + GPG key
uses: actions/setup-java@v6.1.0
env:
# setup-java v6 treats server-username/server-password as *names of
# environment variables to read*, not as literal credentials. The
# deprecated inputs take the value here, emit ${env.<value>} into
# settings.xml, and Maven then resolves an empty user and password —
# which Central Portal rejects with an empty-bodied 401. The v6
# inputs below need the variables above to actually be exported.
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
with:
distribution: 'temurin'
java-version: '8'
# Writes <server id="central"> into $GITHUB_WORKSPACE/settings.xml
# with username/password read from the env vars above.
server-id: central
server-username-env-var: MAVEN_CENTRAL_USERNAME
server-password-env-var: MAVEN_CENTRAL_TOKEN
settings-path: ${{ github.workspace }}
# Imports the GPG key into the runner's keyring and stores the
# passphrase where maven-gpg-plugin picks it up.
gpg-private-key: ${{ secrets.MAVEN_CENTRAL_GPG_PRIVATE_KEY }}
gpg-passphrase: ${{ secrets.MAVEN_CENTRAL_GPG_PASSPHRASE }}
- name: Install Rust (cargo exec plugin re-builds the JNI lib)
uses: actions-rs/toolchain@v1
with:
toolchain: 1.91
override: true
- name: Install Python (build.py runs under python3)
uses: actions/setup-python@v7
with:
python-version: '3.10'
- name: Build, sign, and publish to Maven Central
working-directory: java
env:
# settings.xml references these by name; Maven expands ${env.X}
# when it reads the file, so they must be exported here too, not
# just during the setup-java step that wrote the file.
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
run: |
# -P central activates maven-gpg-plugin (signs all artifacts)
# and central-publishing-maven-plugin (uploads via Central
# Portal REST API with autoPublish=true). -DskipTests avoids
# re-running JUnit; -Dcargo-build.profile=release matches the
# release-mode binary the test-and-build job produced.
mvn deploy -P central \
-DskipTests=true \
-Dcargo-build.profile=release \
-s $GITHUB_WORKSPACE/settings.xml