Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 80 additions & 6 deletions .github/workflows/release-shimmercapture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
#
# One run does, in order, and creates nothing public until the APK has built and is signed:
# build reads the version; fails if it is already tagged, if versionCode did not go up since the
# last ShimmerCapture release, or if the app is not set to PUBLIC; builds the signed
# release APK. Read-only (no keystore without it): it also runs, unsigned, on PRs.
# last ShimmerCapture release, or if the app is not set to PUBLIC; lists the PRs since
# that release in the run summary, to write whats_new from; builds the signed release
# APK. Read-only (no keystore without it): it also runs, unsigned, on PRs.
# release tags ShimmerCapture_v<version> on the commit it built and creates the GitHub
# pre-release with the APK and notes since the previous ShimmerCapture release.
# Pre-release, so the Android API release stays "Latest", as before.
Expand All @@ -41,7 +42,8 @@
# GITHUB_TOKEN, or PACKAGES_READ_TOKEN if that is ever refused.
#
# dry_run builds the signed APK (unsigned without the keystore) and keeps it as a workflow artifact,
# from any branch, and publishes nothing. The workflow also dry-runs on any PR that changes this file.
# from any branch, and publishes nothing. Its summary lists the changes for whats_new. The workflow
# also dry-runs on any PR that changes this file.

name: Release ShimmerCapture

Expand Down Expand Up @@ -79,6 +81,7 @@ jobs:
permissions:
contents: read
packages: read
pull-requests: read # PR titles, for the changes list in the run summary
env:
DRY_RUN: ${{ github.event_name != 'workflow_dispatch' || inputs.dry_run }}
# Read by the repositories in the root build.gradle to resolve the driver.
Expand Down Expand Up @@ -119,8 +122,22 @@ jobs:
fi
TAG="ShimmerCapture_v$VERSION"

PREVIOUS_TAG=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 200 --json tagName,createdAt \
--jq '[.[] | select(.tagName | startswith("ShimmerCapture_v"))] | sort_by(.createdAt) | last | .tagName // ""')
# The newest published ShimmerCapture release whose tag still exists. A draft, or a release
# whose tag was deleted, has no tag to compare against: the versionCode check below and
# the changes list would then silently compare against nothing.
# An assignment, so -e stops the step if gh fails: inside "for … in $(…)" a failure is ignored,
# and the versionCode check would be skipped.
releases=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 200 --json tagName,createdAt,isDraft \
--jq '[.[] | select((.tagName | startswith("ShimmerCapture_v")) and (.isDraft | not))]
| sort_by(.createdAt) | reverse | .[].tagName')
PREVIOUS_TAG=
for t in $releases; do
if git rev-parse -q --verify "refs/tags/$t" >/dev/null; then
PREVIOUS_TAG=$t
break
fi
echo "::warning::The $t release has no tag, so it is skipped as the previous release."
done

fail() {
if [ "$DRY_RUN" = true ]; then
Expand Down Expand Up @@ -159,6 +176,51 @@ jobs:
} >> "$GITHUB_OUTPUT"
echo "Releasing ShimmerCapture $VERSION (versionCode $VERSION_CODE) as $TAG against driver ${DRIVER:-unknown}; notes since ${PREVIOUS_TAG:-the first commit}"

# The material for the Play release notes (whats_new), so a dry run shows it before the real
# run. The GitHub release's generated notes need write access this job does not have, so the
# PRs are found from the merge commits ("Merge pull request #N …") since the last
# ShimmerCapture tag, including PRs merged into a branch that later reached master. This repo
# merges with merge commits; a squash-merged PR would not be listed.
- name: List the changes since the last release
continue-on-error: true # only informs; never blocks a release
working-directory: .
env:
GH_TOKEN: ${{ github.token }}
PREVIOUS_TAG: ${{ steps.version.outputs.previous_tag }}
VERSION: ${{ steps.version.outputs.version }}
run: |
set -o pipefail # a failing git log must not read as "no PRs"
summary() { echo "$1" >> "$GITHUB_STEP_SUMMARY"; }
summary "### Changes in ShimmerCapture $VERSION since ${PREVIOUS_TAG:-the first commit}"
summary ""
range=${PREVIOUS_TAG:+refs/tags/$PREVIOUS_TAG..}HEAD
if ! numbers=$(git log --reverse --format=%s "$range" \
| sed -nE 's/^Merge pull request #([0-9]+) .*/\1/p' | awk '!seen[$0]++'); then
echo "::warning::Could not list the commits in $range."
summary "Could not list the changes: \`git log $range\` failed. See this step's log."
exit 1
fi
if [ -z "$numbers" ]; then
summary "No PRs merged since ${PREVIOUS_TAG:-the first commit}."
exit 0
fi
# Every title in one GraphQL request, rather than one REST call per PR.
query="query(\$owner: String!, \$name: String!) { repository(owner: \$owner, name: \$name) {"
for n in $numbers; do query+=" pr$n: pullRequest(number: $n) { number title }"; done
query+=" } }"
# jq runs separately: when any PR in the query can't be resolved, gh exits 1 and prints the
# raw response without applying --jq, though every other title in it is there.
resp=$(gh api graphql -f query="$query" -F owner="${GITHUB_REPOSITORY%/*}" \
-F name="${GITHUB_REPOSITORY#*/}") || echo "::warning::Some PR titles could not be read."
titles=$(jq -r '.data.repository // {} | .[] | select(.) | "\(.number)\t\(.title)"' <<<"$resp") \
|| titles=
summary "Pick the ones users notice for the Play release notes (whats_new, 500 characters max)."
summary ""
for n in $numbers; do
title=$(awk -F'\t' -v n="$n" '$1 == n { print $2; exit }' <<<"$titles")
summary "* ${title:-(title not found)} (#$n)"
done

# Decoded before building so a missing keystore fails in seconds. The keystore is written
# outside the checkout, and the step that uses it deletes it. Never on a PR: the build runs the
# PR's own Gradle scripts, which could read it.
Expand Down Expand Up @@ -222,6 +284,10 @@ jobs:
VERSION: ${{ steps.version.outputs.version }}
VERSION_CODE: ${{ steps.version.outputs.version_code }}
SIGNED: ${{ steps.keystore.outputs.signed }}
# SHA-256 of the certificate every ShimmerCapture release on Google Play is signed with
# (CN=Shimmer). The app is not enrolled in Play App Signing, so Play accepts only APKs signed
# by this key. Change it only if the app's signing key itself changes.
RELEASE_CERT_SHA256: 5f353cb90d2452e2d83309837a57b72950003e1470d873899a573e2441123e19
run: |
out=shimmerServiceExample/build/outputs/apk/release
ls -l "$out"
Expand All @@ -242,8 +308,16 @@ jobs:
echo "::error::The APK does not carry versionName $VERSION and versionCode $VERSION_CODE."
exit 1
fi
# Before anything is tagged or uploaded: a wrong or replaced keystore secret would otherwise
# be caught only by Play, after the tag and GitHub release are public.
if [ "$SIGNED" = true ]; then
"$build_tools/apksigner" verify --print-certs "../release-assets/$name"
certs=$("$build_tools/apksigner" verify --print-certs "../release-assets/$name")
echo "$certs"
if ! grep -qi "certificate SHA-256 digest: $RELEASE_CERT_SHA256" <<<"$certs"; then
echo "::error::The APK is not signed with the ShimmerCapture release key (SHA-256 $RELEASE_CERT_SHA256). Check the SHIMMERCAPTURE_KEYSTORE_* secrets."
exit 1
fi
echo "Signed with the ShimmerCapture release key."
fi
echo "apk=$name" >> "$GITHUB_OUTPUT"

Expand Down
50 changes: 45 additions & 5 deletions ShimmerAndroidInstrumentDriver/shimmerServiceExample/RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,61 @@ Then, as before the workflow existed:

## 2. Optional: a dry run

To check the signing and the version before publishing anything:
To check the signing and the version, and to get the list of changes for the release notes, before
publishing anything:

1. **Actions** → **Release ShimmerCapture** → **Run workflow**.
2. Branch `master`, tick **dry_run**, then **Run workflow**.

A dry run does everything up to the signed APK and stops. Open the run to check:

- The run's **summary** page lists the PRs merged since the last ShimmerCapture release, found from
the merge commits between that release's tag and the commit being built. Write the Play release
notes from it (see *Writing whats_new* below).
- **build** → *Collect and check the APK* prints the APK's `versionCode` and `versionName`, and
`Signer #1 certificate SHA-256 digest`. That digest must match Play Console → ShimmerCapture →
*Test and release* → *App integrity* → **Upload key certificate**. If it doesn't, Play rejects the
upload.
**checks its signing certificate**: the run fails, before anything is tagged or uploaded, unless
the APK is signed with the key every ShimmerCapture release has used (`CN=Shimmer`, SHA-256
`5f353cb9…41123e19`, in the workflow as `RELEASE_CERT_SHA256`).

ShimmerCapture is **not** enrolled in Play App Signing, so Play has no separate upload key: it
accepts an update only if it is signed by the same key as the APKs already published. If the check
fails, the `SHIMMERCAPTURE_KEYSTORE_*` secrets hold a different keystore. To compare with Play
itself, download the current APK from Play Console → ShimmerCapture → *Test and release* →
*App bundle explorer* → its version code → *Downloads*, and run `apksigner verify --print-certs` on
it. Do not choose any option on *Protected with Play* → *Manage Play app signing* as part of a
release: enrolling cannot be undone.
- The APK itself is on the run page under **Artifacts** (`shimmercapture-apk`), to install on a test
device.

A dry run can be started from any branch, so it is also the way to try an uprev before merging it.

### Writing whats_new

The GitHub release gets its notes automatically: every PR since the last release. The Play release
notes (`whats_new`) are for users, at most 500 characters, so they are written by hand from that
list. Most PRs (CI, HIL tests, docs, release tooling) do not change the app: keep the ones users
notice, in plain words, one bullet each. For example, 1.3.4's:

```
• Connecting over Bluetooth LE no longer freezes the app while the link is set up
• A device is shown as ready only once it has fully connected
• More reliable streaming: fixes for device replies and acknowledgements that could be lost or misread
• Fixed a crash when a device disconnected while a command was being sent
• Updated Shimmer device library (0.11.12)
```

Without a dry run, GitHub's own notes preview is one command away. It creates nothing; put in the
version being released and the last one:

```bash
gh api repos/ShimmerResearch/ShimmerAndroidAPI/releases/generate-notes -f tag_name=ShimmerCapture_v1.3.5 -f target_commitish=master -f previous_tag_name=ShimmerCapture_v1.3.4 --jq .body

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the preview uses target_commitish=master, but the release job passes $GITHUB_SHA. If a PR merges between the preview and the run, the whats_new written from the preview can describe a PR that is not in the APK. Worth a note that this is master as of now, or showing a SHA instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted in 736f5e2. Under the preview command, RELEASING.md now says both lists are of master as it is when you look, that a PR merged before the run is in the APK but not in your notes, and to look again just before running.

```

Both lists are of `master` as it is when you look. If a PR merges before the release run, it is in
the APK but not in your notes: look again just before running. The two lists also find PRs
differently (merge commits, against GitHub's own commit-to-PR links), so they can differ, e.g. for
a squash-merged PR.

## 3. Run the release

1. **Actions** → **Release ShimmerCapture** → **Run workflow**.
Expand All @@ -74,7 +113,7 @@ A dry run can be started from any branch, so it is also the way to try an uprev
|---|---|
| Use workflow from | `master` (a release refuses any other branch) |
| google_play | ticked, to put a draft release in Google Play. Unticked = GitHub release only |
| whats_new | the Play release notes, in English, at most 500 characters. Blank = "Bug fixes and improvements." Copying the previous release's notes and editing them works well |
| whats_new | the Play release notes, in English, at most 500 characters. Blank = "Bug fixes and improvements." See *Writing whats_new* above |
| dry_run | unticked |

3. **Run workflow**, and wait for the three jobs, about 10 minutes:
Expand Down Expand Up @@ -122,6 +161,7 @@ already created is not created twice.
| `versionCode N is not higher than M` | `versionName` was raised but `versionCode` wasn't. Raise it in a new uprev PR |
| `MainActivity.appReleaseType is …, not PUBLIC` | Set it back to `PUBLIC` in a PR |
| `No SHIMMERCAPTURE_KEYSTORE_BASE64 secret` | The signing secrets are missing. See *Secrets* below |
| `The APK is not signed with the ShimmerCapture release key` | The keystore secret holds a different key from the one Play knows. Nothing was published. Replace `SHIMMERCAPTURE_KEYSTORE_BASE64` (and its passwords and alias) with the original keystore, see *Secrets* below |
| `The APK does not carry versionName …` | The build didn't pick up `build.gradle`'s values. Check for a version override in Gradle files |
| **play**: `No GOOGLE_PLAY_SERVICE_ACCOUNT_JSON secret` | The Play secret is missing. The GitHub release is done; upload by hand (step 4), or add the secret and re-run the job |
| **play**: `The caller does not have permission` | The service account lacks access to ShimmerCapture in Play Console, or was just added: new permissions can take a day. Re-run the play job later |
Expand Down
Loading