forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
425 lines (379 loc) · 18.3 KB
/
Copy pathjava-cd.yml
File metadata and controls
425 lines (379 loc) · 18.3 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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
name: Java Prepare Deployment
on:
push:
tags:
- "v*.*"
workflow_dispatch:
inputs:
version:
description: "The release version of GLIDE, formatted as *.*.* or *.*.*-rc*"
required: true
maven_publish:
description: "Publish to Maven Central"
required: true
type: boolean
concurrency:
group: java-cd-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions:
id-token: write
jobs:
load-platform-matrix:
runs-on: ubuntu-latest
environment: AWS_ACTIONS
outputs:
PLATFORM_MATRIX: ${{ steps.load-platform-matrix.outputs.PLATFORM_MATRIX }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: load-platform-matrix
id: load-platform-matrix
shell: bash
run: |
# Filter entries with maven in PACKAGE_MANAGERS and replace "ephemeral" with "persistent" in RUNNER
export PLATFORM_MATRIX=$(jq 'map(
select(.PACKAGE_MANAGERS != null and (.PACKAGE_MANAGERS | contains(["maven"])))
| .RUNNER = (
if (.RUNNER | type == "array")
then (.RUNNER | map(if . == "ephemeral" then "persistent" else . end))
else (if .RUNNER == "ephemeral" then "persistent" else .RUNNER end)
end
)
)' < .github/json_matrices/build-matrix.json | jq -c .)
echo "PLATFORM_MATRIX=${PLATFORM_MATRIX}" >> $GITHUB_OUTPUT
set-release-version:
runs-on: ubuntu-latest
outputs:
RELEASE_VERSION: ${{ steps.release-version.outputs.RELEASE_VERSION }}
steps:
- name: Set the release version
id: release-version
shell: bash
run: |
if ${{ github.event_name == 'workflow_dispatch' }}; then
R_VERSION="${{ env.INPUT_VERSION }}"
else
R_VERSION=${GITHUB_REF:11}
fi
echo "RELEASE_VERSION=${R_VERSION}" >> $GITHUB_ENV
echo "Release version detected: $R_VERSION"
echo "RELEASE_VERSION=$R_VERSION" >> $GITHUB_OUTPUT
env:
INPUT_VERSION: ${{ github.event.inputs.version }}
create-binaries-to-publish:
needs: [set-release-version, load-platform-matrix]
if: github.repository_owner == 'valkey-io'
timeout-minutes: 35
env:
JAVA_VERSION: "11"
RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }}
strategy:
# Run all jobs
fail-fast: false
matrix:
host: ${{ fromJson(needs.load-platform-matrix.outputs.PLATFORM_MATRIX) }}
runs-on: ${{ matrix.host.RUNNER }}
steps:
- name: Setup self-hosted runner access
if: runner.os != 'Windows'
shell: bash
run: |
GHA_HOME=/home/ubuntu/actions-runner/_work/valkey-glide
if [ -d $GHA_HOME ]; then
sudo chown -R $USER:$USER $GHA_HOME
sudo rm -rf $GHA_HOME
mkdir -p $GHA_HOME/valkey-glide
else
echo "No cleaning needed"
fi
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: ${{ env.JAVA_VERSION }}
- name: Install shared software dependencies
uses: ./.github/workflows/install-shared-dependencies
with:
os: ${{ matrix.host.OS }}
target: ${{ matrix.host.CD_TARGET || matrix.host.TARGET }}
github-token: ${{ secrets.GITHUB_TOKEN }}
language: java
- name: Run rustup with correct target
if: ${{ contains(matrix.host.TARGET, 'musl') }}
run: |
rustup target add ${{ matrix.host.TARGET }}
- name: Install protoc (protobuf)
uses: arduino/setup-protoc@v3
with:
version: "29.1"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-cd-${{ hashFiles('java/**/*.gradle*', 'java/**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-cd-
${{ runner.os }}-gradle-
- name: Create secret key ring file for all Java submodules
working-directory: java/client
shell: bash
run: |
# Decode the provided base64 GPG key into the client module
echo "$SECRING_GPG" | base64 --decode > ./secring.gpg
# Copy the key ring file into the jedis-compatibility module which also performs signing
if [ -d ../jedis-compatibility ]; then
cp ./secring.gpg ../jedis-compatibility/secring.gpg
else
echo "jedis-compatibility module directory not found" >&2
exit 1
fi
echo "Listing key ring files to verify presence:"
ls -l ./secring.gpg ../jedis-compatibility/secring.gpg
env:
SECRING_GPG: ${{ secrets.SECRING_GPG }}
- name: Build java client
working-directory: java
shell: bash
env:
GLIDE_RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
run: |
# Determine gradle command based on OS
if [[ "${{ matrix.host.OS }}" == "windows" ]]; then
GRADLE_CMD="./gradlew.bat"
else
GRADLE_CMD="./gradlew"
fi
if [[ "${{ matrix.host.TARGET }}" == *"musl"* ]]; then
# Build and publish client first
$GRADLE_CMD --build-cache :client:publishToMavenLocal -Psigning.secretKeyRingFile=secring.gpg \
-Psigning.password="${{ secrets.GPG_PASSWORD }}" -Psigning.keyId=${{ secrets.GPG_KEY_ID }} \
-Ptarget=${{ matrix.host.TARGET }}
# Then build jedis-compatibility
$GRADLE_CMD --build-cache :jedis-compatibility:publishToMavenLocal -Psigning.secretKeyRingFile=secring.gpg \
-Psigning.password="${{ secrets.GPG_PASSWORD }}" -Psigning.keyId=${{ secrets.GPG_KEY_ID }} \
-Ptarget=${{ matrix.host.TARGET }}
else
# Build and publish client first
$GRADLE_CMD --build-cache :client:publishToMavenLocal -Psigning.secretKeyRingFile=secring.gpg \
-Psigning.password="${{ secrets.GPG_PASSWORD }}" -Psigning.keyId=${{ secrets.GPG_KEY_ID }}
# Then build jedis-compatibility
$GRADLE_CMD --build-cache :jedis-compatibility:publishToMavenLocal -Psigning.secretKeyRingFile=secring.gpg \
-Psigning.password="${{ secrets.GPG_PASSWORD }}" -Psigning.keyId=${{ secrets.GPG_KEY_ID }}
fi
- name: Bundle JAR
working-directory: java
shell: bash
run: |
# Bundle client JAR
src_folder=~/.m2/repository/io/valkey/valkey-glide/${{ env.RELEASE_VERSION }}
cd $src_folder
jar -cvf bundle.jar *
ls -ltr
cd -
cp $src_folder/bundle.jar bundle-${{ matrix.host.TARGET }}.jar
# Bundle jedis-compatibility JAR
jedis_src_folder=~/.m2/repository/io/valkey/valkey-glide-jedis-compatibility/${{ env.RELEASE_VERSION }}
cd $jedis_src_folder
jar -cvf jedis-bundle.jar *
ls -ltr
cd -
cp $jedis_src_folder/jedis-bundle.jar jedis-bundle-${{ matrix.host.TARGET }}.jar
- name: Upload artifacts to publish
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: java-${{ matrix.host.TARGET }}
path: |
java/bundle*.jar
java/jedis-bundle*.jar
publish-to-maven-central-deployment:
if: ${{ inputs.maven_publish == true || github.event_name == 'push' }}
needs: [set-release-version, create-binaries-to-publish]
runs-on: ubuntu-latest
outputs:
DEPLOYMENT_ID: ${{ steps.maven-deployment.outputs.DEPLOYMENT_ID }}
env:
RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }}
steps:
- name: Download published artifacts
uses: actions/download-artifact@v4
- name: Move all required files to one directory
shell: bash
run: |
mkdir maven-files
cd maven-files
for file in $(find ../. -name "*.jar"); do jar xf "$file" ; done
- name: Generate sha1 and md5 files for all Maven files
shell: bash
run: |
cd maven-files
for i in *.jar *.pom *.module; do md5sum $i | cut -d ' ' -f 1 > $i.md5; done
for i in *.jar *.pom *.module; do sha1sum $i | cut -d ' ' -f 1 > $i.sha1; done
- name: Move files to the correct directory tree
shell: bash
run: |
mkdir -p build/io/valkey/valkey-glide/${{ env.RELEASE_VERSION }}
mkdir -p build/io/valkey/valkey-glide-jedis-compatibility/${{ env.RELEASE_VERSION }}
# Move jedis-compatibility files first
cp -a maven-files/valkey-glide-jedis-compatibility* build/io/valkey/valkey-glide-jedis-compatibility/${{ env.RELEASE_VERSION }}
# Move client files (exclude jedis-compatibility files)
find maven-files -name "valkey-glide-*" ! -name "*jedis-compatibility*" -exec cp {} build/io/valkey/valkey-glide/${{ env.RELEASE_VERSION }}/ \;
rm -rf build/io/valkey/valkey-glide/${{ env.RELEASE_VERSION }}/META-INF
rm -rf build/io/valkey/valkey-glide-jedis-compatibility/${{ env.RELEASE_VERSION }}/META-INF
cd build
zip -r ../build io
- name: Upload bundle to CI artifacts
uses: actions/upload-artifact@v4
with:
name: valkey-${{ env.RELEASE_VERSION }}
path: |
build
- name: Publish to Maven Central
id: maven-deployment
shell: bash
run: |
export DEPLOYMENT_ID=`curl --request POST \
-u "${{ secrets.CENTRAL_TOKEN_USERNAME }}:${{ secrets.CENTRAL_TOKEN_PASSWORD }}" \
--form bundle=@build.zip \
https://central.sonatype.com/api/v1/publisher/upload | tail -n 1`
echo "DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_ENV
echo "DEPLOYMENT_ID=$DEPLOYMENT_ID" >> $GITHUB_OUTPUT
echo Uploaded to Maven deployment with deployment ID $DEPLOYMENT_ID. Will be released if smoke tests pass and approved for release.
- name: Check status of deployment
shell: bash
run: |
for ((retries = 0; retries < 20; retries++)); do
sleep 5
export DEPLOYMENT_STATUS=`curl --request POST \
-u "${{ secrets.CENTRAL_TOKEN_USERNAME }}:${{ secrets.CENTRAL_TOKEN_PASSWORD }}" \
"https://central.sonatype.com/api/v1/publisher/status?id=${{ env.DEPLOYMENT_ID }}" \
| jq '.deploymentState'`
if [[ $DEPLOYMENT_STATUS == ""\"VALIDATED"\"" ]]; then exit 0; fi
done
curl --request POST \
-u "${{ secrets.CENTRAL_TOKEN_USERNAME }}:${{ secrets.CENTRAL_TOKEN_PASSWORD }}" \
"https://central.sonatype.com/api/v1/publisher/status?id=${{ env.DEPLOYMENT_ID }}" \
| jq
echo "Deployment ${{ env.DEPLOYMENT_ID }} was unsuccessful with status $DEPLOYMENT_STATUS"
exit 1
test-deployment-on-all-architectures:
needs:
[
set-release-version,
load-platform-matrix,
publish-to-maven-central-deployment,
]
env:
JAVA_VERSION: "11"
RELEASE_VERSION: ${{ needs.set-release-version.outputs.RELEASE_VERSION }}
strategy:
# Run all jobs
fail-fast: false
matrix:
host: ${{ fromJson(needs.load-platform-matrix.outputs.PLATFORM_MATRIX) }}
exclude:
- host:
TARGET: aarch64-unknown-linux-musl
runs-on: ${{ matrix.host.test-runner || matrix.host.runner }}
container:
image: ${{ matrix.host.IMAGE || ''}}
options: ${{ join(' -q ', matrix.host.CONTAINER_OPTIONS) }} # adding `-q` to bypass empty options
steps:
- name: Setup self-hosted runner access
if: ${{matrix.host.TARGET == 'aarch64-unknown-linux-gnu' }}
run: sudo chown -R $USER:$USER /home/ubuntu/action-runner-ilia/_work/valkey-glide
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: ${{ env.JAVA_VERSION }}
- name: Install git and Java for musl
if: ${{ contains(matrix.host.TARGET, 'musl') }}
run: |
# Set environment variable to indicate container environment for Gradle
echo "GLIDE_CONTAINER_BUILD=true" >> $GITHUB_ENV
apk add openjdk11 git bash
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
# Create gradle user home and disable auto-download
mkdir -p ~/.gradle
echo "org.gradle.java.installations.auto-download=false" >> ~/.gradle/gradle.properties
echo JAVA_HOME=/usr/lib/jvm/java-11-openjdk >> $GITHUB_ENV
env:
JAVA_HOME: ${{ env.JAVA_HOME }}
- name: Install shared software dependencies
uses: ./.github/workflows/install-shared-dependencies
with:
os: ${{ matrix.host.OS }}
engine-version: "7.2"
target: ${{ matrix.host.TARGET }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install protoc (protobuf)
uses: arduino/setup-protoc@v3
with:
version: "29.1"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-test-cd-${{ hashFiles('java/**/*.gradle*', 'java/**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-test-cd-
${{ runner.os }}-gradle-cd-
${{ runner.os }}-gradle-
- name: Start standalone Valkey server
working-directory: utils
id: port
run: |
PORT=$(python3 ./cluster_manager.py start -r 0 2>&1 | grep CLUSTER_NODES | cut -d = -f 2 | cut -d , -f 1 | cut -d : -f 2)
echo "PORT=$PORT" >> $GITHUB_OUTPUT
- name: Test deployment
working-directory: java
env:
PORT: ${{ steps.port.outputs.PORT }}
run: |
export ORG_GRADLE_PROJECT_centralManualTestingAuthHeaderName="Authorization"
export ORG_GRADLE_PROJECT_centralManualTestingAuthHeaderValue="Bearer $(echo "${{ secrets.CENTRAL_TOKEN_USERNAME }}:${{ secrets.CENTRAL_TOKEN_PASSWORD }}" | base64)"
export GLIDE_RELEASE_VERSION=${{ env.RELEASE_VERSION }}
./gradlew --build-cache :benchmarks:run --args="--minimal --clients glide --port ${{ env.PORT }}"
publish-release-to-maven:
if: ${{ inputs.maven_publish == true || github.event_name == 'push' }}
needs:
[
publish-to-maven-central-deployment,
test-deployment-on-all-architectures,
]
runs-on: ubuntu-latest
environment: AWS_ACTIONS
env:
DEPLOYMENT_ID: ${{ needs.publish-to-maven-central-deployment.outputs.DEPLOYMENT_ID }}
steps:
- name: Publish to Maven
run: |
curl --request POST \
-u "${{ secrets.CENTRAL_TOKEN_USERNAME }}:${{ secrets.CENTRAL_TOKEN_PASSWORD }}" \
"https://central.sonatype.com/api/v1/publisher/deployment/${{ env.DEPLOYMENT_ID }}"
drop-deployment-if-validation-fails:
if: ${{ failure() }}
needs:
[
publish-to-maven-central-deployment,
test-deployment-on-all-architectures,
]
runs-on: ubuntu-latest
env:
DEPLOYMENT_ID: ${{ needs.publish-to-maven-central-deployment.outputs.DEPLOYMENT_ID }}
steps:
- name: Drop deployment if validation fails
run: |
curl --request DELETE \
-u "${{ secrets.CENTRAL_TOKEN_USERNAME }}:${{ secrets.CENTRAL_TOKEN_PASSWORD }}" \
"https://central.sonatype.com/api/v1/publisher/deployment/${{ env.DEPLOYMENT_ID }}"