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
345 changes: 345 additions & 0 deletions .github/workflows/release-shimmercapture.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,345 @@
# One-click release of the ShimmerCapture app (the shimmerServiceExample module): a signed APK on a
# GitHub pre-release, and optionally a draft release in Google Play. It automates the Confluence page
# "ShimmerCapture Android Release (shimmerServiceExample)", which did the same by hand in Android
# Studio.
#
# How to release (the full guide is ShimmerAndroidInstrumentDriver/shimmerServiceExample/RELEASING.md)
# 1. In a PR, as before, raise versionCode and versionName in shimmerServiceExample/build.gradle,
# and leave MainActivity.appReleaseType at PUBLIC. Merge it.
# 2. Actions -> "Release ShimmerCapture" -> Run workflow (on master). The version is the
# versionName in build.gradle, tagged ShimmerCapture_v<versionName>.
# 3. With google_play ticked, the APK goes to Play Console's Production track as a draft. In Play
# Console, open that release, check it, and "Send changes for review", as on the Confluence page.
#
# Unlike the Android API's release.yml, the version is committed rather than typed: Play needs a
# versionCode higher than every one before it, and build.gradle is the only record of the last one.
#
# 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.
# 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.
# play google_play only: uploads the same APK to Play's Production track as a draft.
#
# If a later job fails, "Re-run failed jobs" re-runs just that job.
#
# Secrets (repository Settings -> Secrets and variables -> Actions)
# SHIMMERCAPTURE_KEYSTORE_BASE64 the upload keystore (.jks) used in Android Studio, base64:
# [Convert]::ToBase64String([IO.File]::ReadAllBytes("x.jks"))
# SHIMMERCAPTURE_KEYSTORE_PASSWORD its store password
# SHIMMERCAPTURE_KEY_ALIAS the key alias
# SHIMMERCAPTURE_KEY_PASSWORD the key password
# GOOGLE_PLAY_SERVICE_ACCOUNT_JSON google_play only: JSON key of a Google Cloud service account
# invited in Play Console (Users and permissions) with "Release
# to production" on ShimmerCapture
# A real release refuses to run without the keystore. A dry run builds unsigned if it is missing,
# and a PR run always builds unsigned.
#
# The driver is read from Shimmer-Java-Android-API's GitHub Packages, as in release.yml: this repo's
# 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.

name: Release ShimmerCapture

on:
workflow_dispatch:
inputs:
google_play:
description: 'Also upload to Google Play Production as a draft, to send for review in Play Console'
type: boolean
default: false
whats_new:
description: 'Google Play release notes (en-US, 500 characters max). Blank = "Bug fixes and improvements."'
type: string
required: false
dry_run:
description: 'Build only; publish nothing'
type: boolean
default: false
pull_request:
paths:
- '.github/workflows/release-shimmercapture.yml'

concurrency:
group: release-shimmercapture
cancel-in-progress: false

defaults:
run:
working-directory: ShimmerAndroidInstrumentDriver

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30 # a hung Gradle daemon otherwise holds the runner for 6 hours
permissions:
contents: read
packages: read
env:
DRY_RUN: ${{ github.event_name != 'workflow_dispatch' || inputs.dry_run }}
# Read by the repositories in the root build.gradle to resolve the driver.
USERNAME: ${{ github.actor }}
TOKEN: ${{ secrets.PACKAGES_READ_TOKEN || github.token }}
outputs:
version: ${{ steps.version.outputs.version }}
version_code: ${{ steps.version.outputs.version_code }}
tag: ${{ steps.version.outputs.tag }}
previous_tag: ${{ steps.version.outputs.previous_tag }}
driver: ${{ steps.version.outputs.driver }}
apk: ${{ steps.collect.outputs.apk }}
steps:
- name: Release from master only
if: env.DRY_RUN != 'true' && github.ref != 'refs/heads/master'
working-directory: .
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 could read it.
persist-credentials: false

- name: Check the version and the release type
id: version
env:
GH_TOKEN: ${{ github.token }}
run: |
gradle_file=shimmerServiceExample/build.gradle
VERSION=$(sed -nE 's/^\s*versionName\s+"([^"]+)".*/\1/p' "$gradle_file")
VERSION_CODE=$(sed -nE 's/^\s*versionCode\s+([0-9]+).*/\1/p' "$gradle_file")
if [ -z "$VERSION" ] || [ -z "$VERSION_CODE" ]; then
echo "::error::Cannot read versionName and versionCode from $gradle_file."
exit 1
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 // ""')
fail() {
if [ "$DRY_RUN" = true ]; then
echo "::warning::$1 A real release would stop here. Dry run continues."
else
echo "::error::$1"
exit 1
fi
}
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
fail "$VERSION is already released as $TAG. Raise versionName and versionCode in $gradle_file first."
fi
# Play refuses a versionCode it has seen, so check it went up since the last release.
if [ -n "$PREVIOUS_TAG" ]; then
previous_code=$(git show "refs/tags/$PREVIOUS_TAG:ShimmerAndroidInstrumentDriver/$gradle_file" 2>/dev/null \
| sed -nE 's/^\s*versionCode\s+([0-9]+).*/\1/p')
if [ -n "$previous_code" ] && [ "$VERSION_CODE" -le "$previous_code" ]; then
fail "versionCode $VERSION_CODE is not higher than $previous_code in $PREVIOUS_TAG. Raise it in $gradle_file."
fi
fi
# The Confluence procedure's first step: a Play release must be the PUBLIC build.
release_type=$(sed -nE 's/.*appReleaseType\s*=\s*APP_RELEASE_TYPE\.([A-Z_]+).*/\1/p' \
shimmerServiceExample/src/main/java/com/shimmerresearch/shimmercapture/MainActivity.java)
if [ "$release_type" != PUBLIC ]; then
fail "MainActivity.appReleaseType is ${release_type:-not found}, not PUBLIC."
fi
DRIVER=$(sed -nE "s/.*findProperty\('driverVersion'\) \?: '([^']+)'.*/\1/p" build.gradle)
{
echo "version=$VERSION"
echo "version_code=$VERSION_CODE"
echo "tag=$TAG"
echo "previous_tag=$PREVIOUS_TAG"
echo "driver=$DRIVER"
} >> "$GITHUB_OUTPUT"
echo "Releasing ShimmerCapture $VERSION (versionCode $VERSION_CODE) as $TAG against driver ${DRIVER:-unknown}; notes since ${PREVIOUS_TAG:-the first commit}"
# 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.
- name: Set up the signing keystore
id: keystore
env:
KEYSTORE_BASE64: ${{ github.event_name == 'workflow_dispatch' && secrets.SHIMMERCAPTURE_KEYSTORE_BASE64 || '' }}
run: |
if [ -z "$KEYSTORE_BASE64" ]; then
if [ "$DRY_RUN" = true ]; then
echo "::warning::No SHIMMERCAPTURE_KEYSTORE_BASE64 secret, so this dry run builds an unsigned APK."
echo "signed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "::error::No SHIMMERCAPTURE_KEYSTORE_BASE64 secret. See the secrets list at the top of this workflow."
exit 1
fi
keystore="$RUNNER_TEMP/shimmercapture-upload.jks"
printf '%s' "$KEYSTORE_BASE64" | base64 -d > "$keystore"
echo "signed=true" >> "$GITHUB_OUTPUT"
echo "path=$keystore" >> "$GITHUB_OUTPUT"
# AGP 8 needs JDK 17.
- name: Set up JDK 17
uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4.9.1
with:
java-version: '17'
distribution: 'temurin'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@ec92e829475ac0c2315ea8f9eced72db85bb337a # v3.0.0

# The android.injected.signing.* properties are what Android Studio's "Generate Signed App
# Bundle / APK" passes, so this signs exactly as the manual procedure did, with no signing
# config in build.gradle. Actions masks the secrets in the log. gradle.properties is gitignored
# here, so android.useAndroidX and the daemon heap are passed on the command line, as in ci.yml.
- name: Build the release APK
env:
SIGNED: ${{ steps.keystore.outputs.signed }}
KEYSTORE: ${{ steps.keystore.outputs.path }}
KEYSTORE_PASSWORD: ${{ secrets.SHIMMERCAPTURE_KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.SHIMMERCAPTURE_KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.SHIMMERCAPTURE_KEY_PASSWORD }}
run: |
signing=()
if [ "$SIGNED" = true ]; then
trap 'rm -f "$KEYSTORE"' EXIT
signing=(
-Pandroid.injected.signing.store.file="$KEYSTORE"
-Pandroid.injected.signing.store.password="$KEYSTORE_PASSWORD"
-Pandroid.injected.signing.key.alias="$KEY_ALIAS"
-Pandroid.injected.signing.key.password="$KEY_PASSWORD"
)
fi
./gradlew :shimmerServiceExample:assembleRelease -Pandroid.useAndroidX=true "${signing[@]}" \
-Dorg.gradle.jvmargs="-Xmx4g -XX:MaxMetaspaceSize=1g"
- name: Collect and check the APK
id: collect
env:
VERSION: ${{ steps.version.outputs.version }}
VERSION_CODE: ${{ steps.version.outputs.version_code }}
SIGNED: ${{ steps.keystore.outputs.signed }}
run: |
out=shimmerServiceExample/build/outputs/apk/release
ls -l "$out"
if [ "$SIGNED" = true ]; then
built="$out/shimmerServiceExample-release.apk"
name="ShimmerCapture_v$VERSION.apk"
else
built="$out/shimmerServiceExample-release-unsigned.apk"
name="ShimmerCapture_v$VERSION-unsigned.apk"
fi
mkdir -p ../release-assets
cp "$built" "../release-assets/$name"
build_tools=$(ls -d "$ANDROID_HOME"/build-tools/* | sort -V | tail -1)
badging=$("$build_tools/aapt2" dump badging "../release-assets/$name" | head -1)
echo "$badging"
if ! grep -q "versionCode='$VERSION_CODE'" <<<"$badging" || ! grep -q "versionName='$VERSION'" <<<"$badging"; then
echo "::error::The APK does not carry versionName $VERSION and versionCode $VERSION_CODE."
exit 1
fi
if [ "$SIGNED" = true ]; then
"$build_tools/apksigner" verify --print-certs "../release-assets/$name"
fi
echo "apk=$name" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: shimmercapture-apk
path: release-assets/
if-no-files-found: error

release:
needs: build
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 }}
VERSION_CODE: ${{ needs.build.outputs.version_code }}
TAG: ${{ needs.build.outputs.tag }}
PREVIOUS_TAG: ${{ needs.build.outputs.previous_tag }}
DRIVER: ${{ needs.build.outputs.driver }}
steps:
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: shimmercapture-apk
path: release-assets

# Generated notes cover every PR since the last ShimmerCapture tag, not only the app's: the app
# ships the library and the driver too.
- name: Create the tag and GitHub pre-release
working-directory: .
run: |
args=(-f tag_name="$TAG" -f target_commitish="$GITHUB_SHA")
if [ -n "$PREVIOUS_TAG" ]; then args+=(-f previous_tag_name="$PREVIOUS_TAG"); fi
{
echo "ShimmerCapture $VERSION (versionCode $VERSION_CODE), built from \`shimmerServiceExample\` against Shimmer Java API driver ${DRIVER:-(unknown)}."
echo
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 "$TAG" \
--notes-file notes.md \
--prerelease
{
echo "### Released ShimmerCapture $VERSION"
echo "- Release: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$TAG"
echo "- versionCode $VERSION_CODE, driver ${DRIVER:-unknown}"
} >> "$GITHUB_STEP_SUMMARY"
play:
needs: [build, release]
if: github.event_name == 'workflow_dispatch' && !inputs.dry_run && inputs.google_play
runs-on: ubuntu-latest
timeout-minutes: 15
permissions: {}
steps:
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: shimmercapture-apk
path: release-assets

- name: Write the release notes
working-directory: .
env:
WHATS_NEW: ${{ inputs.whats_new }}
HAS_ACCOUNT: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON != '' }}
run: |
if [ "$HAS_ACCOUNT" != true ]; then
echo "::error::No GOOGLE_PLAY_SERVICE_ACCOUNT_JSON secret. The GitHub release is done; upload $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases to Play Console by hand, or add the secret and re-run this job."
exit 1
fi
mkdir -p whatsnew
printf '%s\n' "${WHATS_NEW:-Bug fixes and improvements.}" > whatsnew/whatsnew-en-US
if [ "$(wc -m < whatsnew/whatsnew-en-US)" -gt 500 ]; then
echo "::error::Google Play allows 500 characters of release notes."
exit 1
fi
# A draft, so a person still checks the release in Play Console and sends it for review, as in
# the manual procedure.
- name: Upload to Google Play (Production, draft)
uses: r0adkll/upload-google-play@e738b9dd8f2476ea806d921b64aacd24f34515a5 # v1.1.5
with:
serviceAccountJsonPlainText: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }}
packageName: com.shimmersensing.shimmerconnect
releaseFiles: release-assets/${{ needs.build.outputs.apk }}
releaseName: ${{ needs.build.outputs.version }}
track: production
status: draft
whatsNewDirectory: whatsnew

- name: Summary
working-directory: .
run: |
echo "### Uploaded to Google Play as a draft on Production. In Play Console: Test and release -> Production -> review the release -> Send changes for review." >> "$GITHUB_STEP_SUMMARY"
5 changes: 4 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ rather than queueing.
`.github/workflows/ci.yml` runs on every PR into master and every push to it. It builds the library
and every example (`assembleDebug`), then runs the library's unit tests, against the default driver.
No check is required to merge yet, so look at the result. `release.yml` is the dispatch-only Release
Android API workflow; it dry-runs on any PR that changes it.
Android API workflow; it dry-runs on any PR that changes it. `release-shimmercapture.yml` does the
same for the ShimmerCapture app (`shimmerServiceExample`): a signed APK, a GitHub pre-release and a
draft Google Play release. Its version comes from that module's `build.gradle`, so each release
starts with an uprev PR; `shimmerServiceExample/RELEASING.md` is the step-by-step guide.

## Modules

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ This ShimmerSeriviceExample allows user to
- Erase data in Verisense device
- Disable logging in Verisense device
- Data sync Verisense device

## Releasing

This app is published to Google Play as ShimmerCapture. [RELEASING.md](RELEASING.md) has every step, from raising the version to sending the release for review.
Loading
Loading