From c09344c4024253f995200151b2db7a0f41afbd38 Mon Sep 17 00:00:00 2001 From: JongChern Date: Thu, 15 Oct 2026 12:11:25 +0800 Subject: [PATCH 1/9] DEV-1115 Replace Process.onExit() so the MATLAB jar runs on Java 8 Process.onExit() is Java 9+. ShimmerJavaClass.jar is built as Java 8 bytecode for MATLAB, and source/target 1.8 compiled this call without complaint, so starting the BLE gRPC server from MATLAB on Java 8 would throw NoSuchMethodError. The jar currently in Shimmer-MATLAB-ID/libs (built 2025-11-24) contains the call. Wait on the process in a daemon thread instead, which logs the same exit message. Found by building the jar with --release 8. Co-Authored-By: Claude Opus 5.5 --- .../grpc/GrpcBLERadioByteTools.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/ShimmerDriver/src/main/java/com/shimmerresearch/grpc/GrpcBLERadioByteTools.java b/ShimmerDriver/src/main/java/com/shimmerresearch/grpc/GrpcBLERadioByteTools.java index 254d1ce60..360d54199 100644 --- a/ShimmerDriver/src/main/java/com/shimmerresearch/grpc/GrpcBLERadioByteTools.java +++ b/ShimmerDriver/src/main/java/com/shimmerresearch/grpc/GrpcBLERadioByteTools.java @@ -153,11 +153,20 @@ public int startServer() throws Exception { e.printStackTrace(); } }); - runningProcess.onExit().thenAccept(p -> { - int code = p.exitValue(); - System.err.println("[BLEGrpcServer] exited: code=" + code + - (code >= 128 ? " (likely signal " + (code - 128) + ")" : "")); - }); + // Not Process.onExit(): that is Java 9+, and MATLAB loads this class on Java 8 via + // ShimmerJavaClass.jar, where it throws NoSuchMethodError. Daemon, like onExit()'s pool thread. + final Process process = runningProcess; + Thread exitWatcher = new Thread(() -> { + try { + int code = process.waitFor(); + System.err.println("[BLEGrpcServer] exited: code=" + code + + (code >= 128 ? " (likely signal " + (code - 128) + ")" : "")); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + }, "BLEGrpcServer-exit"); + exitWatcher.setDaemon(true); + exitWatcher.start(); processThread.start(); return port; From 44f9f98c3f01fb0fbf3b4950741077bf49b7cbf9 Mon Sep 17 00:00:00 2001 From: JongChern Date: Thu, 15 Oct 2026 12:11:25 +0800 Subject: [PATCH 2/9] DEV-1115 Add one-click Release Java API workflow Actions -> "Release Java API" releases the version already in the build files (bumped by the usual uprev PR; master is protected): - tests and builds as gradle.yml does - publishes shimmerdriver, shimmerbluetoothmanager and shimmerdriverpc in one gradlew publish, so they cannot drift apart again - tags API_v and creates the GitHub Release with the jars, not marked Latest - builds ShimmerJavaClass.jar as Java 8 bytecode on its own runner and opens a PR replacing Shimmer-MATLAB-ID/libs/ShimmerJavaClass.jar (needs the MATLAB_REPO_TOKEN secret) ShimmerDriverPC gains -PmatlabJava8, which compiles all three projects with --release 8 in place of hand-editing three build files to 1.8. Publishing URLs move from ShimmerEngineering, now a user account, to ShimmerResearch. AGENTS.md documents the release steps. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 291 +++++++++++++++++++++++++++ AGENTS.md | 17 ++ ShimmerBluetoothManager/build.gradle | 2 +- ShimmerDriver/build.gradle | 2 +- ShimmerDriverPC/build.gradle | 20 +- ShimmerLSL/build.gradle | 2 +- ShimmerPCBasicExamples/build.gradle | 2 +- 7 files changed, 325 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..0d8c2778e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,291 @@ +# One-click release of the Java API: GitHub Packages, a GitHub Release, and the MATLAB jar. +# +# How to release +# 1. Merge the usual uprev PR, which bumps the publishing `version` in ShimmerDriver, +# ShimmerBluetoothManager and ShimmerDriverPC build.gradle. master is protected, so this +# workflow cannot commit the bump itself. +# 2. Actions -> "Release Java API" -> Run workflow (on master). +# 3. Review and merge the ShimmerJavaClass.jar PR it opens in Shimmer-MATLAB-ID. +# +# One run does, in order, and creates nothing public until the build and tests have passed: +# build reads the version from the three build.gradle files and fails if they disagree; +# fails if API_v is already tagged; tests ShimmerDriver and builds +# ShimmerDriverPC exactly as gradle.yml does; then 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) +# 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 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. Needs the +# MATLAB_REPO_TOKEN secret: a fine-grained token for ShimmerResearch/Shimmer-MATLAB-ID +# 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. The workflow also +# dry-runs on any PR that changes this file. + +name: Release Java API + +on: + workflow_dispatch: + inputs: + dry_run: + description: 'Build and test only; publish nothing' + type: boolean + default: false + pull_request: + paths: + - '.github/workflows/release.yml' + +concurrency: + group: release-java-api + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + 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 }} + 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@v4 + with: + fetch-depth: 0 # tags, to refuse a version that is already released + + - name: Read the version from the build files + id: version + env: + GH_TOKEN: ${{ github.token }} + run: | + VERSION= + for p in ShimmerDriver ShimmerBluetoothManager ShimmerDriverPC; do + v=$(sed -nE "s/^[[:space:]]*version = '([^']+)'.*/\1/p" "$p/build.gradle") + echo "$p: ${v:-}" + if [ "$(printf '%s\n' "$v" | grep -c .)" -ne 1 ]; then + echo "::error file=$p/build.gradle::Expected exactly one publishing version = '...' line" + exit 1 + fi + if [ -n "$VERSION" ] && [ "$v" != "$VERSION" ]; then + echo "::error file=$p/build.gradle::$p is at $v but ShimmerDriver is at $VERSION. The uprev must bump all three." + exit 1 + fi + VERSION=$v + done + TAG="API_v$VERSION" + if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then + echo "::error::$TAG already exists. Bump the version with an uprev PR first." + exit 1 + fi + PREVIOUS_TAG=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 200 --json tagName,createdAt \ + --jq '[.[] | select(.tagName | startswith("API_v"))] | sort_by(.createdAt) | last | .tagName // ""') + { + 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: Set up JDK 11 + uses: actions/setup-java@v4 + 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` runs in every project of the ShimmerDriverPC build, so all three artifacts go + # out in one invocation. The build files read these credentials from USERNAME and TOKEN. + - name: Publish to GitHub Packages + if: env.DRY_RUN != 'true' + working-directory: ShimmerDriverPC + env: + USERNAME: ${{ github.actor }} + TOKEN: ${{ github.token }} + run: ./gradlew publish + + - name: Collect the release jars + env: + VERSION: ${{ steps.version.outputs.version }} + 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@v4 + with: + name: release-jars + path: release-assets/ + if-no-files-found: error + + matlab-jar: + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + 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 + + - name: Check the jar is Java 8 bytecode + run: | + jar=ShimmerDriverPC/build/libs/ShimmerJavaClass.jar + for c in com/shimmerresearch/tools/matlab/ShimmerJavaClass.class \ + com/shimmerresearch/driver/ShimmerObject.class \ + com/shimmerresearch/managers/bluetoothManager/ShimmerBluetoothManager.class; do + major=$(unzip -p "$jar" "$c" | head -c 8 | od -An -tu1 | awk '{print $7 * 256 + $8}') + echo "$c: class file major version $major" + if [ "$major" != 52 ]; then + echo "::error::$c is class version $major, not 52 (Java 8); MATLAB on Java 8 cannot load it." + exit 1 + fi + done + mkdir -p matlab-jar + cp "$jar" matlab-jar/ShimmerJavaClass.jar + ls -l matlab-jar + + - uses: actions/upload-artifact@v4 + with: + name: matlab-jar + path: matlab-jar/ + if-no-files-found: error + + release: + needs: [build, matlab-jar] + if: github.event_name == 'workflow_dispatch' && !inputs.dry_run + runs-on: ubuntu-latest + 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 }} + steps: + - uses: actions/download-artifact@v4 + with: + name: release-jars + path: release-assets + + - uses: actions/download-artifact@v4 + 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" + gh release create "$TAG" release-assets/* \ + --repo "$GITHUB_REPOSITORY" \ + --target "$GITHUB_SHA" \ + --title "Shimmer Java API Rev $VERSION" \ + --generate-notes ${PREVIOUS_TAG:+--notes-start-tag "$PREVIOUS_TAG"} \ + --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 "- Next: bump the shimmerdriver and shimmerbluetoothmanager pins in ShimmerAndroidAPI to $VERSION, then run its Release workflow." + } >> "$GITHUB_STEP_SUMMARY" + + update-matlab: + needs: [build, release] + runs-on: ubuntu-latest + 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 + + - uses: actions/checkout@v4 + with: + repository: ${{ env.MATLAB_REPO }} + token: ${{ secrets.MATLAB_REPO_TOKEN }} + path: matlab + + - uses: actions/download-artifact@v4 + 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\`. + + 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" diff --git a/AGENTS.md b/AGENTS.md index 5e47628f6..7e26a89c1 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,6 +18,23 @@ all: they are legacy Eclipse ADT Android projects. Test results land in `**/build/test-results/test/*.xml`. +## Releasing +Releases are cut by the **Release Java API** workflow (`release.yml`), not from a developer machine: +1. Merge an uprev PR that bumps the publishing `version` in `ShimmerDriver`, `ShimmerBluetoothManager` + and `ShimmerDriverPC` `build.gradle` — all three, to the same value; the workflow refuses a mismatch. +2. Run the workflow on `master`. It tests and builds as CI does, publishes all three artifacts to + GitHub Packages in one `gradlew publish`, tags `API_v`, and creates the GitHub Release + with the jars attached (not marked Latest — that stays with Consensys). +3. It also builds `ShimmerJavaClass.jar` for MATLAB and opens a PR replacing + `Shimmer-MATLAB-ID/libs/ShimmerJavaClass.jar` (needs the `MATLAB_REPO_TOKEN` secret). Review and + merge it. +4. Bump the driver pins in `ShimmerAndroidAPI` to the new version, then run its own Release workflow. + +`ShimmerJavaClass.jar` must be Java 8 bytecode, because MATLAB may load it on Java 8. Build it locally +with `cd ShimmerDriverPC && ./gradlew shadowJar -PmatlabJava8`, which compiles all three projects with +`--release 8` — that also rejects any API newer than Java 8, so `Process.onExit()`, `var` and the like +fail the build here instead of throwing `NoSuchMethodError` inside MATLAB. + ## Subprojects | Project | Role | |---|---| diff --git a/ShimmerBluetoothManager/build.gradle b/ShimmerBluetoothManager/build.gradle index b5ed8183e..72fd006ae 100644 --- a/ShimmerBluetoothManager/build.gradle +++ b/ShimmerBluetoothManager/build.gradle @@ -40,7 +40,7 @@ publishing { repositories { maven { name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API") + url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API") credentials { /* Create gradle.properties file in GRADLE_USER_HOME/.gradle/ (e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your diff --git a/ShimmerDriver/build.gradle b/ShimmerDriver/build.gradle index 8cce51299..47840827c 100644 --- a/ShimmerDriver/build.gradle +++ b/ShimmerDriver/build.gradle @@ -63,7 +63,7 @@ publishing { repositories { maven { name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API") + url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API") credentials { /* Create gradle.properties file in GRADLE_USER_HOME/.gradle/ (e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your diff --git a/ShimmerDriverPC/build.gradle b/ShimmerDriverPC/build.gradle index 00ee312ac..dd821701a 100644 --- a/ShimmerDriverPC/build.gradle +++ b/ShimmerDriverPC/build.gradle @@ -57,7 +57,7 @@ publishing { repositories { maven { name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API") + url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API") credentials { /* Create gradle.properties file in GRADLE_USER_HOME/.gradle/ (e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your @@ -110,12 +110,18 @@ dependencies { implementation("org.bouncycastle:bcprov-jdk15on:1.61") } -// Shadow JAR task to create a runnable JAR with dependencies -/* -Change to using the following below for ShimmerDriverPC/ShimmerDriver/ShimmerBluetoothManager -sourceCompatibility = '1.8' // Ensure code is compiled with Java 8 -targetCompatibility = '1.8' // Ensure bytecode is compatible with Java 8 -*/ +// Shadow JAR task to create a runnable JAR with dependencies. +// ShimmerJavaClass.jar is loaded by MATLAB, which may run it on Java 8, so build it as Java 8 +// bytecode with: ./gradlew shadowJar -PmatlabJava8 +// This applies to the ShimmerDriver and ShimmerBluetoothManager subprojects too, so their build files +// no longer need editing to 1.8 by hand. --release 8 also fails the compile if the code uses an API +// newer than Java 8, which sourceCompatibility = '1.8' alone would let through to fail in MATLAB. +// The "Release Java API" workflow builds the jar this way and opens a PR into Shimmer-MATLAB-ID/libs. +if (hasProperty('matlabJava8')) { + allprojects { + tasks.withType(JavaCompile).configureEach { options.release = 8 } + } +} shadowJar { archiveBaseName.set('ShimmerJavaClass') // Use archiveBaseName instead of baseName archiveClassifier.set('') // Remove classifier so it’s named shimmerjavaclass.jar diff --git a/ShimmerLSL/build.gradle b/ShimmerLSL/build.gradle index 4227dc2c0..419de8816 100644 --- a/ShimmerLSL/build.gradle +++ b/ShimmerLSL/build.gradle @@ -39,7 +39,7 @@ publishing { repositories { maven { name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API") + url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API") credentials { /* Create gradle.properties file in GRADLE_USER_HOME/.gradle/ (e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your diff --git a/ShimmerPCBasicExamples/build.gradle b/ShimmerPCBasicExamples/build.gradle index e3b8eb351..213a64eab 100644 --- a/ShimmerPCBasicExamples/build.gradle +++ b/ShimmerPCBasicExamples/build.gradle @@ -22,7 +22,7 @@ repositories { } maven { name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/ShimmerEngineering/Shimmer-Java-Android-API") + url = uri("https://maven.pkg.github.com/ShimmerResearch/Shimmer-Java-Android-API") credentials { /* Create gradle.properties file in GRADLE_USER_HOME/.gradle/ (e.g. C:/Users/YourUsername/.gradle/) with the two lines listed below. Fill in your From 1bd3a654f4554961c526f251571ffdd83faab37a Mon Sep 17 00:00:00 2001 From: JongChern Date: Thu, 15 Oct 2026 12:12:53 +0800 Subject: [PATCH 3/9] DEV-1115 Let a dry run continue past an already-released version The version in the build files is normally one that has already been released until the next uprev, so stopping there made every PR dry run end before the build it is meant to test. Dry runs now warn; a real release still refuses. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0d8c2778e..a58e518ac 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -91,8 +91,12 @@ jobs: done TAG="API_v$VERSION" if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then - echo "::error::$TAG already exists. Bump the version with an uprev PR first." - exit 1 + 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. Bump the version with an uprev PR first." + exit 1 + fi fi PREVIOUS_TAG=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 200 --json tagName,createdAt \ --jq '[.[] | select(.tagName | startswith("API_v"))] | sort_by(.createdAt) | last | .tagName // ""') From d5f5b44e9e9110492a26bbefc459c4b2160e25bc Mon Sep 17 00:00:00 2001 From: JongChern Date: Fri, 16 Oct 2026 10:45:37 +0800 Subject: [PATCH 4/9] DEV-1115 Pick the release version in the Run form, not an uprev PR The version no longer lives in the source. The three publishing blocks read -PreleaseVersion (falling back to 'local'), and Release Java API passes it: the version typed in the Run form, or by default the next patch after the last API_v release (0.11.8_beta -> 0.11.9_beta). The API_v tags record what was released, so a release needs no uprev PR and nothing has to be committed to the protected master. Checked locally: with -PreleaseVersion=0.11.9_beta all three POMs and their dependencies on each other are 0.11.9_beta; without it, 'local'. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 64 ++++++++++++++++------------ AGENTS.md | 20 +++++---- ShimmerBluetoothManager/build.gradle | 2 +- ShimmerDriver/build.gradle | 2 +- ShimmerDriverPC/build.gradle | 2 +- 5 files changed, 52 insertions(+), 38 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a58e518ac..a34d69d8a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,15 +1,16 @@ # One-click release of the Java API: GitHub Packages, a GitHub Release, and the MATLAB jar. # # How to release -# 1. Merge the usual uprev PR, which bumps the publishing `version` in ShimmerDriver, -# ShimmerBluetoothManager and ShimmerDriverPC build.gradle. master is protected, so this -# workflow cannot commit the bump itself. -# 2. Actions -> "Release Java API" -> Run workflow (on master). -# 3. Review and merge the ShimmerJavaClass.jar PR it opens in Shimmer-MATLAB-ID. +# 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. Review and merge the ShimmerJavaClass.jar PR it opens in Shimmer-MATLAB-ID. +# 3. Run "Release Android API" in ShimmerAndroidAPI, 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 reads the version from the three build.gradle files and fails if they disagree; -# fails if API_v is already tagged; tests ShimmerDriver and builds +# build picks the version; fails if API_v is already tagged; tests ShimmerDriver and builds # ShimmerDriverPC exactly as gradle.yml does; then publishes shimmerdriver, # shimmerbluetoothmanager and shimmerdriverpc together with one `gradlew publish` # (DEV-1115: publishing them one at a time by hand left shimmerbluetoothmanager @@ -27,7 +28,8 @@ # 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. The workflow also +# 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 @@ -35,6 +37,10 @@ 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 @@ -70,36 +76,38 @@ jobs: with: fetch-depth: 0 # tags, to refuse a version that is already released - - name: Read the version from the build files + - name: Choose the version id: version env: GH_TOKEN: ${{ github.token }} + REQUESTED: ${{ inputs.version }} run: | - VERSION= - for p in ShimmerDriver ShimmerBluetoothManager ShimmerDriverPC; do - v=$(sed -nE "s/^[[:space:]]*version = '([^']+)'.*/\1/p" "$p/build.gradle") - echo "$p: ${v:-}" - if [ "$(printf '%s\n' "$v" | grep -c .)" -ne 1 ]; then - echo "::error file=$p/build.gradle::Expected exactly one publishing version = '...' line" - exit 1 - fi - if [ -n "$VERSION" ] && [ "$v" != "$VERSION" ]; then - echo "::error file=$p/build.gradle::$p is at $v but ShimmerDriver is at $VERSION. The uprev must bump all three." + 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=$v - done + 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. Bump the version with an uprev PR first." + echo "::error::$TAG already exists. Leave the version blank for the next one, or type another." exit 1 fi fi - PREVIOUS_TAG=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 200 --json tagName,createdAt \ - --jq '[.[] | select(.tagName | startswith("API_v"))] | sort_by(.createdAt) | last | .tagName // ""') { echo "version=$VERSION" echo "tag=$TAG" @@ -128,14 +136,16 @@ jobs: run: ./gradlew build # `publish` runs in every project of the ShimmerDriverPC build, so all three artifacts go - # out in one invocation. The build files read these credentials from USERNAME and TOKEN. + # out in one invocation, and -PreleaseVersion versions all three (and their POM + # dependencies on each other). The build files read the credentials from USERNAME and TOKEN. - name: Publish to GitHub Packages if: env.DRY_RUN != 'true' working-directory: ShimmerDriverPC env: USERNAME: ${{ github.actor }} TOKEN: ${{ github.token }} - run: ./gradlew publish + VERSION: ${{ steps.version.outputs.version }} + run: ./gradlew publish -PreleaseVersion="$VERSION" - name: Collect the release jars env: @@ -232,7 +242,7 @@ jobs: 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 "- Next: bump the shimmerdriver and shimmerbluetoothmanager pins in ShimmerAndroidAPI to $VERSION, then run its Release workflow." + echo "- Next: merge the MATLAB PR, then run Release Android API in ShimmerAndroidAPI; it builds against $VERSION unless you pick another driver version." } >> "$GITHUB_STEP_SUMMARY" update-matlab: diff --git a/AGENTS.md b/AGENTS.md index 7e26a89c1..987a978b2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,16 +19,20 @@ all: they are legacy Eclipse ADT Android projects. Test results land in `**/build/test-results/test/*.xml`. ## Releasing -Releases are cut by the **Release Java API** workflow (`release.yml`), not from a developer machine: -1. Merge an uprev PR that bumps the publishing `version` in `ShimmerDriver`, `ShimmerBluetoothManager` - and `ShimmerDriverPC` `build.gradle` — all three, to the same value; the workflow refuses a mismatch. -2. Run the workflow on `master`. It tests and builds as CI does, publishes all three artifacts to - GitHub Packages in one `gradlew publish`, tags `API_v`, and creates the GitHub Release - with the jars attached (not marked Latest — that stays with Consensys). -3. It also builds `ShimmerJavaClass.jar` for MATLAB and opens a PR replacing +Releases are cut by the **Release Java API** workflow (`release.yml`), not from a developer machine, +and need no uprev PR: +1. Run the workflow on `master`. Leave `version` blank for the next patch after the last `API_v` + release, or type one. It tests and builds as CI does, publishes all three artifacts to GitHub + Packages in one `gradlew publish`, tags `API_v`, and creates the GitHub Release with the + jars attached (not marked Latest — that stays with Consensys). +2. It also builds `ShimmerJavaClass.jar` for MATLAB and opens a PR replacing `Shimmer-MATLAB-ID/libs/ShimmerJavaClass.jar` (needs the `MATLAB_REPO_TOKEN` secret). Review and merge it. -4. Bump the driver pins in `ShimmerAndroidAPI` to the new version, then run its own Release workflow. +3. Run `ShimmerAndroidAPI`'s own Release workflow, which builds against the newest Java release unless + told otherwise. + +The version is not stored in the source: the three publishing blocks read `-PreleaseVersion`, which +the workflow passes, and fall back to `local`. The `API_v` tags are the record of what was released. `ShimmerJavaClass.jar` must be Java 8 bytecode, because MATLAB may load it on Java 8. Build it locally with `cd ShimmerDriverPC && ./gradlew shadowJar -PmatlabJava8`, which compiles all three projects with diff --git a/ShimmerBluetoothManager/build.gradle b/ShimmerBluetoothManager/build.gradle index 72fd006ae..c4961ecda 100644 --- a/ShimmerBluetoothManager/build.gradle +++ b/ShimmerBluetoothManager/build.gradle @@ -27,7 +27,7 @@ publishing { groupId = 'com.shimmerresearch' // Replace with your package's group/organization name artifactId = 'shimmerbluetoothmanager' // Replace with the name of your package - version = '0.11.8_beta' // Replace with your package version + version = project.findProperty('releaseVersion') ?: 'local' // set by the Release Java API workflow (-PreleaseVersion) // Jar publication //( diff --git a/ShimmerDriver/build.gradle b/ShimmerDriver/build.gradle index 47840827c..84d17c6ea 100644 --- a/ShimmerDriver/build.gradle +++ b/ShimmerDriver/build.gradle @@ -49,7 +49,7 @@ publishing { groupId = 'com.shimmerresearch' // Replace with your package's group/organization name artifactId = 'shimmerdriver' // Replace with the name of your package - version = '0.11.8_beta' // Replace with your package version + version = project.findProperty('releaseVersion') ?: 'local' // set by the Release Java API workflow (-PreleaseVersion) // Jar publication //( diff --git a/ShimmerDriverPC/build.gradle b/ShimmerDriverPC/build.gradle index dd821701a..3b4ad7258 100644 --- a/ShimmerDriverPC/build.gradle +++ b/ShimmerDriverPC/build.gradle @@ -44,7 +44,7 @@ publishing { groupId = 'com.shimmerresearch' // Replace with your package's group/organization name artifactId = 'shimmerdriverpc' // Replace with the name of your package - version = '0.11.8_beta' // Replace with your package version + version = project.findProperty('releaseVersion') ?: 'local' // set by the Release Java API workflow (-PreleaseVersion) // Jar publication //( From 17515618d414b9e7f12cd8660b37c4ff5ee0c25d Mon Sep 17 00:00:00 2001 From: Mas Azalya Date: Fri, 16 Oct 2026 12:14:40 +0800 Subject: [PATCH 5/9] DEV-1115 Fix publish of shimmerdriverpc and refuse a 'local' publish publish failed on shimmerdriverpc with "multiple artifacts with the identical extension and classifier ('jar', 'null')": the Shadow plugin adds ShimmerJavaClass.jar (empty classifier) to components.java, and Gradle 8.14 (DEV-1013) rejects the clash. The PR dry run skips publish, so the first real release would have failed there after publishing the other two. Skip the shadow variant, which publishes the plain jar with its dependencies in the POM, as 0.11.7_beta was. Without -PreleaseVersion the version is 'local', and a hand-run `gradlew publish` would push that to GitHub Packages, where it can never be overwritten. Publishing to a remote repository now refuses 'local'; publishToMavenLocal is unaffected. Add job timeouts so a hung Gradle daemon cannot hold a runner for the default 6 hours. Checked locally (JDK 11): publishToMavenLocal -PreleaseVersion=0.0.0_test now succeeds, all three POMs and their cross-dependencies read 0.0.0_test, and shimmerdriverpc is the 140 KB thin jar. Publishing to a file repository without -PreleaseVersion fails for all three. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 4 ++++ ShimmerBluetoothManager/build.gradle | 11 +++++++++++ ShimmerDriver/build.gradle | 11 +++++++++++ ShimmerDriverPC/build.gradle | 16 ++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a34d69d8a..903707753 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -56,6 +56,7 @@ concurrency: jobs: build: runs-on: ubuntu-latest + timeout-minutes: 30 # a hung Gradle daemon otherwise holds the runner for 6 hours permissions: contents: read packages: write @@ -166,6 +167,7 @@ jobs: 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: @@ -211,6 +213,7 @@ jobs: needs: [build, 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: @@ -248,6 +251,7 @@ jobs: 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 }} diff --git a/ShimmerBluetoothManager/build.gradle b/ShimmerBluetoothManager/build.gradle index c4961ecda..6bf3cb637 100644 --- a/ShimmerBluetoothManager/build.gradle +++ b/ShimmerBluetoothManager/build.gradle @@ -68,3 +68,14 @@ dependencies { // 'test.useTestNG()' to your build script. testImplementation 'junit:junit:4.12' } + +// Without -PreleaseVersion the version is 'local', and GitHub Packages never lets a version be +// overwritten. Releases go through the Release Java API workflow; publishToMavenLocal is unaffected. +tasks.withType(PublishToMavenRepository).configureEach { + doFirst { + if (publication.version == 'local') { + throw new GradleException("Refusing to publish ${publication.artifactId} as version 'local'. " + + "Release with the Release Java API workflow, or pass -PreleaseVersion.") + } + } +} diff --git a/ShimmerDriver/build.gradle b/ShimmerDriver/build.gradle index 84d17c6ea..8d62a7215 100644 --- a/ShimmerDriver/build.gradle +++ b/ShimmerDriver/build.gradle @@ -173,3 +173,14 @@ tasks.withType(Test).configureEach { } } + +// Without -PreleaseVersion the version is 'local', and GitHub Packages never lets a version be +// overwritten. Releases go through the Release Java API workflow; publishToMavenLocal is unaffected. +tasks.withType(PublishToMavenRepository).configureEach { + doFirst { + if (publication.version == 'local') { + throw new GradleException("Refusing to publish ${publication.artifactId} as version 'local'. " + + "Release with the Release Java API workflow, or pass -PreleaseVersion.") + } + } +} diff --git a/ShimmerDriverPC/build.gradle b/ShimmerDriverPC/build.gradle index 3b4ad7258..623db5df3 100644 --- a/ShimmerDriverPC/build.gradle +++ b/ShimmerDriverPC/build.gradle @@ -41,6 +41,11 @@ publishing { publications { mavenJava(MavenPublication) { from components.java + // The Shadow plugin adds ShimmerJavaClass.jar (no classifier) to components.java, where it + // collides with the plain jar and fails publish on Gradle 8. Publish the plain jar with its + // dependencies in the POM, as releases up to 0.11.7_beta did; the fat jar goes to MATLAB + // and the GitHub Release instead. + components.java.withVariantsFromConfiguration(configurations.shadowRuntimeElements) { skip() } groupId = 'com.shimmerresearch' // Replace with your package's group/organization name artifactId = 'shimmerdriverpc' // Replace with the name of your package @@ -132,3 +137,14 @@ shadowJar { mergeServiceFiles() // Merges service files (if any) } + +// Without -PreleaseVersion the version is 'local', and GitHub Packages never lets a version be +// overwritten. Releases go through the Release Java API workflow; publishToMavenLocal is unaffected. +tasks.withType(PublishToMavenRepository).configureEach { + doFirst { + if (publication.version == 'local') { + throw new GradleException("Refusing to publish ${publication.artifactId} as version 'local'. " + + "Release with the Release Java API workflow, or pass -PreleaseVersion.") + } + } +} From 77aaa3b9236b2449f09c1e6e5c3819d9d24bd9d0 Mon Sep 17 00:00:00 2001 From: JongChern Date: Sun, 18 Oct 2026 13:26:11 +0800 Subject: [PATCH 6/9] DEV-1115 Keep the packages:write token out of .git/config actions/checkout persists github.token in .git/config by default, so the Gradle build in the build job, and any plugin or dependency it runs, could read a token with packages:write. Neither build nor matlab-jar needs git credentials after checkout, so turn persistence off there. update-matlab keeps it, because its git push uses it. Raised in review on #324. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 903707753..2437a14d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -76,6 +76,10 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # tags, to refuse a version that is already released + # Keep this job's packages:write 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: publish gets the token explicitly, and gh uses GH_TOKEN. + persist-credentials: false - name: Choose the version id: version @@ -172,6 +176,8 @@ jobs: contents: read steps: - uses: actions/checkout@v4 + with: + persist-credentials: false # the Gradle build needs no git credentials - name: Set up JDK 11 uses: actions/setup-java@v4 @@ -266,6 +272,8 @@ jobs: 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@v4 with: repository: ${{ env.MATLAB_REPO }} From 9a4055690d58462905cde64464ff817625245baa Mon Sep 17 00:00:00 2001 From: JongChern Date: Sun, 18 Oct 2026 13:31:13 +0800 Subject: [PATCH 7/9] DEV-1115 Publish from a dispatch-only job; build job read-only The build job ran on PRs with packages:write. Any code in a job can recover that job's token from the runner, so a PR dry run should not hold a write token at all. The build job is now read-only, and a new publish job, which runs only on a real release, is the one place with packages:write. It publishes and uploads the jars it published, so the GitHub Release carries the same files as GitHub Packages. The release job now waits for it. Raised in review on #324. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 49 +++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2437a14d9..487853510 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,10 +11,11 @@ # # One run does, in order, and creates nothing public until the build and tests have passed: # build picks the version; fails if API_v is already tagged; tests ShimmerDriver and builds -# ShimmerDriverPC exactly as gradle.yml does; then publishes shimmerdriver, +# 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) +# 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 on the commit it built and creates the GitHub Release, with @@ -57,9 +58,10 @@ 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 - packages: write env: DRY_RUN: ${{ github.event_name != 'workflow_dispatch' || inputs.dry_run }} outputs: @@ -76,9 +78,8 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # tags, to refuse a version that is already released - # Keep this job's packages:write 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: publish gets the token explicitly, and gh uses GH_TOKEN. + # 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 @@ -140,21 +141,43 @@ jobs: 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@v4 + with: + persist-credentials: false # publish gets its token explicitly, below + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + 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). The build files read the credentials from USERNAME and TOKEN. + # 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 - if: env.DRY_RUN != 'true' working-directory: ShimmerDriverPC env: USERNAME: ${{ github.actor }} TOKEN: ${{ github.token }} - VERSION: ${{ steps.version.outputs.version }} run: ./gradlew publish -PreleaseVersion="$VERSION" - - name: Collect the release jars - env: - VERSION: ${{ steps.version.outputs.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" @@ -216,7 +239,7 @@ jobs: if-no-files-found: error release: - needs: [build, matlab-jar] + needs: [build, publish, matlab-jar] if: github.event_name == 'workflow_dispatch' && !inputs.dry_run runs-on: ubuntu-latest timeout-minutes: 10 From b819f4c6075bef8b0ae93e8e191dce7f65de90fc Mon Sep 17 00:00:00 2001 From: JongChern Date: Sun, 18 Oct 2026 13:38:07 +0800 Subject: [PATCH 8/9] DEV-1115 Check every class in the MATLAB jar is Java 8 The check sampled three of our own classes, but ShimmerJavaClass.jar also shades every dependency, and one built for a later Java would break MATLAB on Java 8 just the same. Check every class instead (about 32,500, read once with Python in ~2 s), skipping module-info and META-INF/versions entries, which Java 8 never loads, and still require the main class to be present. Tested on a fresh -PmatlabJava8 build (32,510 classes, all Java 8 or older, passes), and on jars missing the main class or carrying a Java 11 dependency class (both fail, naming the class). Raised in review on #324. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 44 ++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 487853510..b21194945 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -215,19 +215,41 @@ jobs: working-directory: ShimmerDriverPC run: ./gradlew shadowJar -PmatlabJava8 - - name: Check the jar is Java 8 bytecode + # 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 - for c in com/shimmerresearch/tools/matlab/ShimmerJavaClass.class \ - com/shimmerresearch/driver/ShimmerObject.class \ - com/shimmerresearch/managers/bluetoothManager/ShimmerBluetoothManager.class; do - major=$(unzip -p "$jar" "$c" | head -c 8 | od -An -tu1 | awk '{print $7 * 256 + $8}') - echo "$c: class file major version $major" - if [ "$major" != 52 ]; then - echo "::error::$c is class version $major, not 52 (Java 8); MATLAB on Java 8 cannot load it." - exit 1 - fi - done + 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 From 7663cdd06dcaf620a065b668eea90b28c7f2b959 Mon Sep 17 00:00:00 2001 From: JongChern Date: Sun, 18 Oct 2026 14:40:19 +0800 Subject: [PATCH 9/9] DEV-1115 Pin the actions/* steps to commit SHAs Matches ShimmerAndroidAPI#124, which pinned checkout and setup-java in review. Each pin is the commit its v4 tag points at today (checkout v4.4.0, setup-java v4.9.1, upload-artifact v4.6.2, download-artifact v4.3.0), so nothing that runs changes; setup-gradle was already pinned. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b21194945..83c66e2f8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -75,7 +75,7 @@ jobs: echo "::error::A release must run on master, not ${GITHUB_REF_NAME}. Tick dry_run to try another branch." exit 1 - - uses: actions/checkout@v4 + - 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 @@ -122,7 +122,7 @@ jobs: echo "Releasing $VERSION as $TAG (notes since ${PREVIOUS_TAG:-the first commit})" - name: Set up JDK 11 - uses: actions/setup-java@v4 + uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1 with: java-version: '11' distribution: 'temurin' @@ -152,12 +152,12 @@ jobs: env: VERSION: ${{ needs.build.outputs.version }} steps: - - uses: actions/checkout@v4 + - 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@v4 + uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1 with: java-version: '11' distribution: 'temurin' @@ -185,7 +185,7 @@ jobs: cp ShimmerDriverPC/build/libs/ShimmerDriverPC.jar "release-assets/shimmerdriverpc-$VERSION.jar" ls -l release-assets - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: release-jars path: release-assets/ @@ -198,12 +198,12 @@ jobs: permissions: contents: read steps: - - uses: actions/checkout@v4 + - 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@v4 + uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1 with: java-version: '11' distribution: 'temurin' @@ -254,7 +254,7 @@ jobs: cp "$jar" matlab-jar/ShimmerJavaClass.jar ls -l matlab-jar - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: matlab-jar path: matlab-jar/ @@ -273,12 +273,12 @@ jobs: TAG: ${{ needs.build.outputs.tag }} PREVIOUS_TAG: ${{ needs.build.outputs.previous_tag }} steps: - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: name: release-jars path: release-assets - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: name: matlab-jar path: matlab-jar @@ -319,13 +319,13 @@ jobs: # Credentials stay persisted here on purpose: the git push below uses them. Nothing else runs # in this job. - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: repository: ${{ env.MATLAB_REPO }} token: ${{ secrets.MATLAB_REPO_TOKEN }} path: matlab - - uses: actions/download-artifact@v4 + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: name: matlab-jar path: matlab-jar