Repository navigation
509 lines (470 loc) · 25.6 KB
/
Copy pathrelease.yml
File metadata and controls
509 lines (470 loc) · 25.6 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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# One-click release of the Java API: GitHub Packages, a GitHub Release, the MATLAB jar, and a PR moving
# ShimmerAndroidAPI to the new driver.
#
# How to release
# 0. On the bench, at the commit to release: tools/hil/run-java-hil.ps1 -Report (tools/hil/README.md).
# It posts the commit status "java-hil"; the build job stops unless that passed, or hil_waiver
# gives a Jira key (the waiver goes into the release notes). Dry runs only warn.
# 1. Actions -> "Release Java API" -> Run workflow (on master). Leave `version` blank for the next
# patch after the last API_v release (0.11.8_beta -> 0.11.9_beta), or type one.
# 2. Run a MATLAB example on a Shimmer3 and a Shimmer3R with the ShimmerJavaClass.jar PR it opens in
# Shimmer-MATLAB-ID, then merge it. Merging publishes a MATLAB API release (that repo's release.yml).
# 3. Android: the PR it opens in ShimmerAndroidAPI moves the default driver pin to this version, and
# its CI runs the unit tests and builds every example against it. Check the driver changes since
# the last pin for parser, CRC or ACK fixes: Android's Shimmer.java has its own Bluetooth stream
# parser, so those must be ported by hand. Merge it, run tools/hil/run-android-hil.ps1 -Report
# -DriverVersion <version> on the bench at master's new commit, then run "Release Android API",
# which builds against this version by default.
#
# The version is not kept in the source. The build files read it from -PreleaseVersion, which this
# workflow passes, and say 'local' otherwise; the API_v tags record what was released.
#
# One run does, in order, and creates nothing public until the build and tests have passed:
# build picks the version; fails if API_v<version> is already tagged; tests ShimmerDriver and builds
# ShimmerDriverPC exactly as gradle.yml does. Read-only: it runs on PRs too.
# publish real releases only, and the only job with packages:write. Publishes shimmerdriver,
# shimmerbluetoothmanager and shimmerdriverpc together with one `gradlew publish`
# (DEV-1115: publishing them one at a time by hand left shimmerbluetoothmanager
# 0.11.8_beta unpublished), and keeps the jars it published for the release
# matlab-jar builds ShimmerJavaClass.jar as Java 8 bytecode (`shadowJar -PmatlabJava8`), on a
# separate runner so its Java 8 classes cannot end up in the published jars
# release tags API_v<version> on the commit it built and creates the GitHub Release, with
# notes from the previous API_v release and the jars attached. It is not marked
# "Latest", which stays with the Consensys releases in this repo.
# update-matlab opens a PR in Shimmer-MATLAB-ID replacing libs/ShimmerJavaClass.jar; merging it
# publishes a MATLAB API release. Needs the MATLAB_REPO_TOKEN secret: a fine-grained
# token for ShimmerResearch/Shimmer-MATLAB-ID with Contents and Pull requests read/write.
# update-android opens a PR in ShimmerAndroidAPI moving the default driver version in
# ShimmerAndroidInstrumentDriver/build.gradle to this one, listing the Android steps.
# The Android release stays manual: it needs a passing bench test on its own commit.
# Needs the ANDROID_REPO_TOKEN secret: a fine-grained token for
# ShimmerResearch/ShimmerAndroidAPI with Contents and Pull requests read/write.
#
# A failed job can be re-run on its own with "Re-run failed jobs"; the jobs before it are not
# repeated. A failed publish can leave some of the three versions in GitHub Packages: delete those
# versions under the repo's Packages before re-running, or bump the version.
#
# dry_run runs build and matlab-jar without publishing, from any branch; a blank version still picks
# the next one, so the run shows what a real release would be called. The workflow also
# dry-runs on any PR that changes this file.
name: Release Java API
on:
workflow_dispatch:
inputs:
version:
description: 'Version, e.g. 0.12.0_beta. Blank = next patch after the last release'
type: string
required: false
dry_run:
description: 'Build and test only; publish nothing'
type: boolean
default: false
hil_waiver:
description: 'Jira key to release without a passing hardware test (HIL), e.g. DEV-1234. Blank = require one'
type: string
required: false
pull_request:
paths:
- '.github/workflows/release.yml'
concurrency:
group: release-java-api
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30 # a hung Gradle daemon otherwise holds the runner for 6 hours
# Read-only on purpose: this job also runs on PRs, and any code in a job can recover that
# job's token. Only the publish job, which runs on real releases alone, can write packages.
permissions:
contents: read
statuses: read # the hardware test result the bench posts on the commit
env:
DRY_RUN: ${{ github.event_name != 'workflow_dispatch' || inputs.dry_run }}
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
previous_tag: ${{ steps.version.outputs.previous_tag }}
hil: ${{ steps.hil.outputs.hil }}
steps:
- name: Release from master only
if: env.DRY_RUN != 'true' && github.ref != 'refs/heads/master'
run: |
echo "::error::A release must run on master, not ${GITHUB_REF_NAME}. Tick dry_run to try another branch."
exit 1
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
fetch-depth: 0 # tags, to refuse a version that is already released
# Keep the token out of .git/config, where the Gradle build (and any plugin or dependency
# it runs) could read it. Nothing here needs git credentials after checkout; gh uses GH_TOKEN.
persist-credentials: false
- name: Choose the version
id: version
env:
GH_TOKEN: ${{ github.token }}
REQUESTED: ${{ inputs.version }}
run: |
PREVIOUS_TAG=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 200 --json tagName,createdAt \
--jq '[.[] | select(.tagName | startswith("API_v"))] | sort_by(.createdAt) | last | .tagName // ""')
if [ -n "$REQUESTED" ]; then
VERSION=$REQUESTED
else
# Next patch after the last release, keeping its suffix: 0.11.8_beta -> 0.11.9_beta.
last=${PREVIOUS_TAG#API_v}
if ! [[ "$last" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(.*)$ ]]; then
echo "::error::Cannot work out the next version from '${PREVIOUS_TAG:-no previous release}'. Type one in the version box."
exit 1
fi
VERSION="${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.$((BASH_REMATCH[3] + 1))${BASH_REMATCH[4]}"
fi
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+[A-Za-z0-9_.-]*$ ]]; then
echo "::error::'$VERSION' is not a version like 0.11.9_beta."
exit 1
fi
TAG="API_v$VERSION"
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
if [ "$DRY_RUN" = true ]; then
echo "::warning::$TAG already exists, so a real release would stop here. Dry run continues."
else
echo "::error::$TAG already exists. Leave the version blank for the next one, or type another."
exit 1
fi
fi
{
echo "version=$VERSION"
echo "tag=$TAG"
echo "previous_tag=$PREVIOUS_TAG"
} >> "$GITHUB_OUTPUT"
echo "Releasing $VERSION as $TAG (notes since ${PREVIOUS_TAG:-the first commit})"
- name: Check the hardware test (HIL) result
id: hil
env:
GH_TOKEN: ${{ github.token }}
WAIVER: ${{ inputs.hil_waiver }}
run: |
context=java-hil
if [ -n "$WAIVER" ] && ! [[ "$WAIVER" =~ ^[A-Z][A-Z0-9]+-[0-9]+$ ]]; then
echo "::error::hil_waiver must be a Jira key such as DEV-1234, not '$WAIVER'."
exit 1
fi
# Newest first: the latest result for this context on this exact commit decides.
line=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/statuses" --paginate \
--jq '.[] | [.context, .state, .description] | @tsv' | awk -F'\t' -v c="$context" '$1 == c { print; exit }')
state=$(printf '%s' "$line" | cut -f2)
description=$(printf '%s' "$line" | cut -f3)
if [ "$state" = success ]; then
echo "Hardware test passed on $GITHUB_SHA: $description"
echo "hil=Tested on hardware before release: $description." >> "$GITHUB_OUTPUT"
elif [ -n "$WAIVER" ]; then
echo "::warning::No passing '$context' on $GITHUB_SHA (found: ${state:-none}); released under waiver $WAIVER."
echo "hil=Released without a passing hardware test (HIL), waived under $WAIVER." >> "$GITHUB_OUTPUT"
elif [ "$DRY_RUN" = true ]; then
echo "::warning::No passing '$context' on $GITHUB_SHA (found: ${state:-none}). A real release would stop here."
else
echo "::error::No passing '$context' on $GITHUB_SHA (found: ${state:-none}${description:+: $description}). On the bench, at this commit, run: tools/hil/run-java-hil.ps1 -Report. Then run this workflow again, or give a Jira key in hil_waiver."
exit 1
fi
- name: Set up JDK 11
uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1
with:
java-version: '11'
distribution: 'temurin'
# Same pinned action as gradle.yml, and likewise no gradle-version: build through the
# committed wrapper.
- name: Setup Gradle
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3.0.0
- name: Test ShimmerDriver
working-directory: ShimmerDriver
run: ./gradlew test
# ShimmerDriverPC includes :ShimmerDriver and :ShimmerBluetoothManager as subprojects.
- name: Build ShimmerDriverPC
working-directory: ShimmerDriverPC
run: ./gradlew build
publish:
needs: build
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run
runs-on: ubuntu-latest
timeout-minutes: 30 # a hung Gradle daemon otherwise holds the runner for 6 hours
permissions:
contents: read
packages: write
env:
VERSION: ${{ needs.build.outputs.version }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false # publish gets its token explicitly, below
- name: Set up JDK 11
uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1
with:
java-version: '11'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3.0.0
# `publish` runs in every project of the ShimmerDriverPC build, so all three artifacts go
# out in one invocation, and -PreleaseVersion versions all three (and their POM
# dependencies on each other). It builds the jars but does not re-run the tests, which the
# build job ran on this same commit. The build files read the credentials from USERNAME and TOKEN.
- name: Publish to GitHub Packages
working-directory: ShimmerDriverPC
env:
USERNAME: ${{ github.actor }}
TOKEN: ${{ github.token }}
run: ./gradlew publish -PreleaseVersion="$VERSION"
# The jars just published, so the GitHub Release carries the same files as GitHub Packages.
- name: Collect the published jars
run: |
mkdir -p release-assets
cp ShimmerDriver/build/libs/ShimmerDriver.jar "release-assets/shimmerdriver-$VERSION.jar"
cp ShimmerBluetoothManager/build/libs/ShimmerBluetoothManager.jar "release-assets/shimmerbluetoothmanager-$VERSION.jar"
cp ShimmerDriverPC/build/libs/ShimmerDriverPC.jar "release-assets/shimmerdriverpc-$VERSION.jar"
ls -l release-assets
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: release-jars
path: release-assets/
if-no-files-found: error
matlab-jar:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 30 # a hung Gradle daemon otherwise holds the runner for 6 hours
permissions:
contents: read
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
persist-credentials: false # the Gradle build needs no git credentials
- name: Set up JDK 11
uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1
with:
java-version: '11'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3.0.0
- name: Build ShimmerJavaClass.jar for MATLAB (Java 8 bytecode)
working-directory: ShimmerDriverPC
run: ./gradlew shadowJar -PmatlabJava8
# Every class in the jar, dependencies included, since a dependency built for a later Java
# breaks MATLAB just as surely as our own code would (~32,500 classes, about 2 s).
- name: Check every class in the jar is Java 8 bytecode
run: |
jar=ShimmerDriverPC/build/libs/ShimmerJavaClass.jar
python3 - "$jar" <<'EOF'
import struct, sys, zipfile
MAIN = "com/shimmerresearch/tools/matlab/ShimmerJavaClass.class"
jar = sys.argv[1]
checked, bad = 0, []
with zipfile.ZipFile(jar) as z:
names = z.namelist()
if MAIN not in names:
print(f"::error::{jar} does not contain {MAIN}.")
sys.exit(1)
for name in names:
# Java 8 never loads module descriptors or multi-release entries for later Javas.
if (not name.endswith(".class") or name.startswith("META-INF/versions/")
or name.endswith("module-info.class")):
continue
with z.open(name) as f:
head = f.read(8)
checked += 1
if len(head) < 8 or head[:4] != b"\xca\xfe\xba\xbe":
bad.append((name, "not a class file"))
elif struct.unpack(">H", head[6:8])[0] > 52:
bad.append((name, f"class version {struct.unpack('>H', head[6:8])[0]}"))
print(f"Checked {checked} classes; {len(bad)} newer than Java 8 (class version 52).")
for name, why in bad[:20]:
print(f"::error::{name}: {why}. MATLAB on Java 8 cannot load it.")
if len(bad) > 20:
print(f"::error::...and {len(bad) - 20} more.")
sys.exit(1 if bad else 0)
EOF
mkdir -p matlab-jar
cp "$jar" matlab-jar/ShimmerJavaClass.jar
ls -l matlab-jar
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: matlab-jar
path: matlab-jar/
if-no-files-found: error
release:
needs: [build, publish, matlab-jar]
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write # create the tag and the release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.build.outputs.version }}
TAG: ${{ needs.build.outputs.tag }}
PREVIOUS_TAG: ${{ needs.build.outputs.previous_tag }}
HIL: ${{ needs.build.outputs.hil }}
steps:
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: release-jars
path: release-assets
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: matlab-jar
path: matlab-jar
- name: Create the tag and GitHub Release
run: |
cp matlab-jar/ShimmerJavaClass.jar "release-assets/ShimmerJavaClass-$VERSION.jar"
# The generated notes, with the hardware test result (or its waiver) in front.
args=(-f tag_name="$TAG" -f target_commitish="$GITHUB_SHA")
if [ -n "$PREVIOUS_TAG" ]; then args+=(-f previous_tag_name="$PREVIOUS_TAG"); fi
{
if [ -n "$HIL" ]; then
echo "$HIL"
echo
fi
gh api "repos/$GITHUB_REPOSITORY/releases/generate-notes" "${args[@]}" --jq .body
} > notes.md
gh release create "$TAG" release-assets/* \
--repo "$GITHUB_REPOSITORY" \
--target "$GITHUB_SHA" \
--title "Shimmer Java API Rev $VERSION" \
--notes-file notes.md \
--latest=false
{
echo "### Released Java API $VERSION"
echo "- Release: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$TAG"
echo "- Packages: com.shimmerresearch:shimmerdriver, shimmerbluetoothmanager and shimmerdriverpc at $VERSION"
echo "- ${HIL:-No hardware test result}"
echo "- Next: run a MATLAB example on a Shimmer3 and a Shimmer3R and merge the MATLAB PR, which publishes a MATLAB API release. For Android, follow the steps in the ShimmerAndroidAPI driver PR: port any parser, CRC or ACK fix to Shimmer.java, merge, run the Android HIL with -DriverVersion $VERSION at master's new commit, then run Release Android API."
} >> "$GITHUB_STEP_SUMMARY"
update-matlab:
needs: [build, release]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions: {} # writes to Shimmer-MATLAB-ID with MATLAB_REPO_TOKEN, not this repo's token
env:
VERSION: ${{ needs.build.outputs.version }}
TAG: ${{ needs.build.outputs.tag }}
MATLAB_REPO: ShimmerResearch/Shimmer-MATLAB-ID
BRANCH: ShimmerJavaClass_${{ needs.build.outputs.version }}
HAS_TOKEN: ${{ secrets.MATLAB_REPO_TOKEN != '' }}
steps:
- name: Check for MATLAB_REPO_TOKEN
if: env.HAS_TOKEN != 'true'
run: |
echo "::error::Secret MATLAB_REPO_TOKEN is not set, so the Shimmer-MATLAB-ID PR cannot be opened. Add a fine-grained token for $MATLAB_REPO (Contents and Pull requests: read/write) as a repo secret, then re-run this job."
exit 1
# Credentials stay persisted here on purpose: the git push below uses them. Nothing else runs
# in this job.
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
repository: ${{ env.MATLAB_REPO }}
token: ${{ secrets.MATLAB_REPO_TOKEN }}
path: matlab
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: matlab-jar
path: matlab-jar
- name: Open the PR updating libs/ShimmerJavaClass.jar
env:
GH_TOKEN: ${{ secrets.MATLAB_REPO_TOKEN }}
working-directory: matlab
run: |
existing=$(gh pr list --repo "$MATLAB_REPO" --head "$BRANCH" --state open --json url --jq '.[0].url // ""')
if [ -n "$existing" ]; then
echo "PR already open: $existing"
echo "- MATLAB PR: $existing" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
cp ../matlab-jar/ShimmerJavaClass.jar libs/ShimmerJavaClass.jar
if git diff --quiet -- libs/ShimmerJavaClass.jar; then
echo "libs/ShimmerJavaClass.jar is already this build; no PR needed."
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -c "$BRANCH"
git add libs/ShimmerJavaClass.jar
git commit -m "Update ShimmerJavaClass.jar to Shimmer Java API $VERSION" \
-m "Built by $GITHUB_REPOSITORY's Release workflow from $TAG ($GITHUB_SHA), as Java 8 bytecode."
git push --force origin "HEAD:refs/heads/$BRANCH"
url=$(gh pr create --repo "$MATLAB_REPO" --base master --head "$BRANCH" \
--title "Update ShimmerJavaClass.jar to Shimmer Java API $VERSION" \
--body "Replaces \`libs/ShimmerJavaClass.jar\` with the build from [$TAG]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$TAG) (\`$GITHUB_SHA\`), compiled as Java 8 bytecode with \`gradlew shadowJar -PmatlabJava8\`.
- Before merging, run an example such as \`plotandwriteexample.m\` on a Shimmer3 and a Shimmer3R. MATLAB cannot run in CI.
- Merging publishes a MATLAB API release: the next patch version, with Java API $VERSION in its title.
Opened by the [Release Java API run]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID).")
echo "Opened $url"
echo "- MATLAB PR: $url" >> "$GITHUB_STEP_SUMMARY"
# Only the default pin moves here. Release Android API already builds against the newest Java
# release; this PR is so ShimmerAndroidAPI's CI tries the new driver, and so the Android steps
# that follow a Java release are written down where they are done.
update-android:
needs: [build, release]
runs-on: ubuntu-latest
timeout-minutes: 10
permissions: {} # writes to ShimmerAndroidAPI with ANDROID_REPO_TOKEN, not this repo's token
env:
VERSION: ${{ needs.build.outputs.version }}
TAG: ${{ needs.build.outputs.tag }}
ANDROID_REPO: ShimmerResearch/ShimmerAndroidAPI
BRANCH: driver_${{ needs.build.outputs.version }}
PIN_FILE: ShimmerAndroidInstrumentDriver/build.gradle
HAS_TOKEN: ${{ secrets.ANDROID_REPO_TOKEN != '' }}
steps:
- name: Check for ANDROID_REPO_TOKEN
if: env.HAS_TOKEN != 'true'
run: |
echo "::error::Secret ANDROID_REPO_TOKEN is not set, so the ShimmerAndroidAPI PR cannot be opened. Add a fine-grained token for $ANDROID_REPO (Contents and Pull requests: read/write) as a repo secret, then re-run this job."
exit 1
# Credentials stay persisted here on purpose: the git push below uses them. Nothing else runs
# in this job.
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
repository: ${{ env.ANDROID_REPO }}
token: ${{ secrets.ANDROID_REPO_TOKEN }}
path: android
- name: Open the PR moving the default driver to this version
env:
GH_TOKEN: ${{ secrets.ANDROID_REPO_TOKEN }}
working-directory: android
run: |
existing=$(gh pr list --repo "$ANDROID_REPO" --head "$BRANCH" --state open --json url --jq '.[0].url // ""')
if [ -n "$existing" ]; then
echo "PR already open: $existing"
echo "- Android PR: $existing" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
# The default is the one line: def shimmerDriverVersion = findProperty('driverVersion') ?: '<version>'
old=$(sed -n "s/.*findProperty('driverVersion') ?: '\([^']*\)'.*/\1/p" "$PIN_FILE")
if [ -z "$old" ] || [ "$(wc -l <<<"$old")" -ne 1 ]; then
echo "::error::$ANDROID_REPO's $PIN_FILE no longer has exactly one line like findProperty('driverVersion') ?: '0.11.11_beta'. Update this job to match it."
exit 1
fi
if [ "$old" = "$VERSION" ]; then
echo "$PIN_FILE already defaults to $VERSION; no PR needed."
echo "- Android: master already builds against $VERSION; no PR needed." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null; then
echo "::warning::Branch $BRANCH already exists in $ANDROID_REPO with no open PR, so this job leaves it alone. Open a PR from it, or delete it and re-run this job."
echo "- Android: branch $BRANCH already exists with no open PR. Open a PR from it, or delete it and re-run this job." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
# VERSION is checked against ^[0-9]+\.[0-9]+\.[0-9]+[A-Za-z0-9_.-]*$ in build, so it is safe in sed.
sed -i "s/\(findProperty('driverVersion') ?: '\)[^']*'/\1$VERSION'/" "$PIN_FILE"
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git switch -c "$BRANCH"
git add "$PIN_FILE"
git commit -m "Build against Shimmer Java API $VERSION by default" \
-m "Moves the default driver version in $PIN_FILE from $old to $VERSION. Opened by $GITHUB_REPOSITORY's Release workflow for $TAG ($GITHUB_SHA)."
git push origin "HEAD:refs/heads/$BRANCH"
url=$(gh pr create --repo "$ANDROID_REPO" --base master --head "$BRANCH" \
--title "Build against Shimmer Java API $VERSION by default" \
--body "Moves the default driver version in \`$PIN_FILE\` from $old to $VERSION, released as [$TAG]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$TAG). CI and local builds use the default. Release Android API builds against the newest Java release whether or not this merges, so this PR is the check that the library and the examples still work with it.
Before merging:
- [ ] CI passes: the library's unit tests and every example, built against $VERSION.
- [ ] Check the [driver changes since $old]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/API_v$old...$TAG) for Bluetooth stream parser, CRC or ACK fixes. \`Shimmer.java\` has its own copy of that parser, so those fixes never reach it through this pin: port each one by hand. AGENTS.md explains why (DEV-1148 ported DEV-1147's fix).
After merging:
- [ ] On the bench, at master's new commit: \`tools/hil/run-android-hil.ps1 -Report -DriverVersion $VERSION\`. The \`android-hil (driver $VERSION)\` status it posts is per commit, so a run on this branch does not count for the release.
- [ ] Run **Release Android API** with \`driver_version\` $VERSION, or blank for the newest Java release.
Opened by the [Release Java API run]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID).")
echo "Opened $url"
echo "- Android PR: $url" >> "$GITHUB_STEP_SUMMARY"