Repository navigation
DEV-1115 One-click Android API release workflow #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5a0e3d0
DEV-1115 Add one-click Release Android API workflow
JongChern 57d1e04
DEV-1115 Refuse a version already released under the older tag spelling
JongChern f340b34
DEV-1115 Let a dry run continue past an already-released version
JongChern 7a39619
DEV-1115 Make the Gradle wrapper executable
JongChern 6da0ad4
DEV-1115 Pick the version and the driver in the Run form
JongChern 59a50a6
DEV-1115 Refuse a 'local' publish and time out a hung build
MAzalya d87514a
Merge pull request #126 from ShimmerResearch/DEV-1115_release_workflo…
JongChern 2b40f35
DEV-1115 Publish from a dispatch-only job; build job read-only
JongChern 2144673
DEV-1115 Build the examples against the chosen driver; pin actions
JongChern 7e2c478
DEV-1115 Exclude JNA from the driver on Android
MAzalya 62c30e6
DEV-1115 Tell AAR consumers to exclude JNA in the release notes
MAzalya 41c14f3
Merge pull request #127 from ShimmerResearch/DEV-1115_exclude_jna
JongChern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,305 @@ | ||
| # One-click release of the Android API: GitHub Packages + a GitHub Release. | ||
| # | ||
| # How to release | ||
| # Actions -> "Release Android API" -> Run workflow (on master). Both boxes can stay blank: | ||
| # - version blank = next patch after the last Android release | ||
| # (AndroidAPI_v3.2.9Beta -> 3.2.10_beta), or type one | ||
| # - driver_version the Shimmer-Java-Android-API release (shimmerdriver and | ||
| # shimmerbluetoothmanager) to build against. Blank = the newest API_v release | ||
| # | ||
| # Neither version is committed, so master's protection does not get in the way. The library's | ||
| # build files read -PreleaseVersion and -PdriverVersion, which this workflow passes. Without them a | ||
| # local build is versioned 'local' and uses the default driver in ShimmerAndroidInstrumentDriver/ | ||
| # build.gradle. The AndroidAPI_v tag plus the driver version named in its release notes rebuild the | ||
| # same .aar. | ||
| # | ||
| # One run does, in order, and creates nothing public until the library has built: | ||
| # build picks both versions; fails if this version is already tagged (in this or the older | ||
| # v3.2.xBeta form) or the driver version has no API_v release; builds the release .aar | ||
| # and every example app against that driver. Read-only (it reads the driver package): | ||
| # it runs on PRs too. | ||
| # publish real releases only, and the only job with packages:write. Builds the .aar the same way, | ||
| # publishes it to GitHub Packages, and keeps the .aar it published for the release | ||
| # release tags AndroidAPI_v<version> on the commit it built and creates the GitHub Release, with | ||
| # the driver version, notes since the previous Android API release, and the .aar | ||
| # | ||
| # If only the release job fails, "Re-run failed jobs" re-runs just that job. | ||
| # | ||
| # The driver is read from Shimmer-Java-Android-API's GitHub Packages with this repo's GITHUB_TOKEN. | ||
| # If that is ever refused (401/403 resolving com.shimmerresearch:shimmerdriver), add a classic token | ||
| # with read:packages as the PACKAGES_READ_TOKEN secret and it is used instead. | ||
| # | ||
| # dry_run builds without publishing, from any branch. The workflow also dry-runs on any PR that | ||
| # changes this file, building against master's default driver. | ||
|
|
||
| name: Release Android API | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: 'Version, e.g. 3.3.0_beta. Blank = next patch after the last release' | ||
| type: string | ||
| required: false | ||
| driver_version: | ||
| description: 'Java API (driver) version to build against, e.g. 0.11.9_beta. Blank = newest release' | ||
| type: string | ||
| required: false | ||
| dry_run: | ||
| description: 'Build only; publish nothing' | ||
| type: boolean | ||
| default: false | ||
| pull_request: | ||
| paths: | ||
| - '.github/workflows/release.yml' | ||
|
|
||
| concurrency: | ||
| group: release-android-api | ||
| 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 | ||
| # Read-only on purpose: this job also runs on PRs, and any code in a job can recover that | ||
| # job's token. packages:read is for resolving the driver; only the publish job, which runs | ||
| # on real releases alone, can write packages. | ||
| 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 }} | ||
| tag: ${{ steps.version.outputs.tag }} | ||
| previous_tag: ${{ steps.version.outputs.previous_tag }} | ||
| driver: ${{ steps.version.outputs.driver }} | ||
| 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 (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 and the driver | ||
| id: version | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| REQUESTED_VERSION: ${{ inputs.version }} | ||
| REQUESTED_DRIVER: ${{ inputs.driver_version }} | ||
| run: | | ||
| # Earlier releases were tagged v3.2.xBeta, so match those too. | ||
| PREVIOUS_TAG=$(gh release list --repo "$GITHUB_REPOSITORY" --limit 200 --json tagName,createdAt \ | ||
| --jq '[.[] | select(.tagName | test("^(AndroidAPI_)?v[0-9]"))] | sort_by(.createdAt) | last | .tagName // ""') | ||
| if [ -n "$REQUESTED_VERSION" ]; then | ||
| VERSION=$REQUESTED_VERSION | ||
| else | ||
| # Next patch after the last release, keeping its suffix. The older 3.2.9Beta spelling | ||
| # counts as 3.2.9_beta, so AndroidAPI_v3.2.9Beta -> 3.2.10_beta. | ||
| last=${PREVIOUS_TAG#AndroidAPI_v}; last=${last#v}; last=${last/%Beta/_beta} | ||
| 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 3.2.10_beta." | ||
| exit 1 | ||
| fi | ||
| TAG="AndroidAPI_v$VERSION" | ||
| # Check the older spellings too, or a version could be released twice under two tags. | ||
| legacy=${VERSION/_beta/Beta} | ||
| for t in "$TAG" "AndroidAPI_v$legacy" "v$legacy"; do | ||
|
Comment on lines
+127
to
+128
|
||
| if git rev-parse -q --verify "refs/tags/$t" >/dev/null; then | ||
| if [ "$DRY_RUN" = true ]; then | ||
| echo "::warning::$VERSION is already released as $t, so a real release would stop here. Dry run continues." | ||
| break | ||
| fi | ||
| echo "::error::$VERSION is already released as $t. Leave the version blank for the next one, or type another." | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| # Driver: typed, else the newest Java API release. A PR dry run uses master's default. | ||
| default_driver=$(sed -nE "s/.*findProperty\('driverVersion'\) \?: '([^']+)'.*/\1/p" build.gradle) | ||
| newest=$(gh release list --repo "$GITHUB_REPOSITORY_OWNER/Shimmer-Java-Android-API" --limit 200 --json tagName,createdAt \ | ||
| --jq '[.[] | select(.tagName | startswith("API_v"))] | sort_by(.createdAt) | last | .tagName // "" | ltrimstr("API_v")') | ||
| if [ -n "$REQUESTED_DRIVER" ]; then | ||
| DRIVER=$REQUESTED_DRIVER | ||
| elif [ "$GITHUB_EVENT_NAME" = workflow_dispatch ]; then | ||
| DRIVER=$newest | ||
| else | ||
| DRIVER=$default_driver | ||
| fi | ||
| if [ -z "$DRIVER" ]; then | ||
| echo "::error::No driver version: none typed, and none found. Type one in the driver_version box." | ||
| exit 1 | ||
| fi | ||
| if ! gh release view "API_v$DRIVER" --repo "$GITHUB_REPOSITORY_OWNER/Shimmer-Java-Android-API" >/dev/null 2>&1; then | ||
| echo "::error::Shimmer-Java-Android-API has no release API_v$DRIVER. Pick a released driver version." | ||
| exit 1 | ||
| fi | ||
| if [ -n "$newest" ] && [ "$DRIVER" != "$newest" ]; then | ||
| echo "::warning::Building against driver $DRIVER, but the newest Java API release is $newest." | ||
| fi | ||
|
|
||
| { | ||
| echo "version=$VERSION" | ||
| echo "tag=$TAG" | ||
| echo "previous_tag=$PREVIOUS_TAG" | ||
| echo "driver=$DRIVER" | ||
| } >> "$GITHUB_OUTPUT" | ||
| echo "Releasing $VERSION as $TAG against driver $DRIVER (master's default: ${default_driver:-none}; notes since ${PREVIOUS_TAG:-the first commit})" | ||
|
|
||
| # 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 | ||
|
|
||
| # gradle.properties is gitignored here, so android.useAndroidX (needed for the androidx | ||
| # dependencies) and the daemon heap are passed on the command line. The default 512 MB heap | ||
| # runs out dexing the examples (see ci.yml); both steps pass the same value so they share | ||
| # one daemon. | ||
| - name: Build the release .aar | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| DRIVER: ${{ steps.version.outputs.driver }} | ||
| run: | | ||
| ./gradlew :ShimmerAndroidInstrumentDriver:assembleRelease -Pandroid.useAndroidX=true \ | ||
| -PreleaseVersion="$VERSION" -PdriverVersion="$DRIVER" \ | ||
| -Dorg.gradle.jvmargs="-Xmx4g -XX:MaxMetaspaceSize=1g" | ||
|
|
||
| # ci.yml builds the examples against master's default driver. A release can pick another, | ||
| # so build every example against the one this release ships with, before anything is | ||
| # published. --continue reports every failing module, and the step still fails. | ||
| - name: Build every example against the chosen driver | ||
| env: | ||
| DRIVER: ${{ steps.version.outputs.driver }} | ||
| run: | | ||
| ./gradlew assembleDebug --continue -Pandroid.useAndroidX=true -PdriverVersion="$DRIVER" \ | ||
| -Dorg.gradle.jvmargs="-Xmx4g -XX:MaxMetaspaceSize=1g" | ||
|
|
||
| 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 # also covers reading the driver package | ||
| env: | ||
| VERSION: ${{ needs.build.outputs.version }} | ||
| DRIVER: ${{ needs.build.outputs.driver }} | ||
| # Read by the repositories in the root build.gradle to resolve the driver. | ||
| USERNAME: ${{ github.actor }} | ||
| TOKEN: ${{ secrets.PACKAGES_READ_TOKEN || github.token }} | ||
| steps: | ||
| - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 | ||
| with: | ||
| persist-credentials: false # publish gets its token explicitly, below | ||
|
|
||
| # 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 | ||
|
|
||
| # Run assembleRelease first: the publication's artifact is the built .aar file, and publish | ||
| # does not build it itself. | ||
| - name: Build the release .aar | ||
| run: | | ||
| ./gradlew :ShimmerAndroidInstrumentDriver:assembleRelease -Pandroid.useAndroidX=true \ | ||
| -PreleaseVersion="$VERSION" -PdriverVersion="$DRIVER" | ||
|
|
||
| # The library's publishing block reads GITHUB_ACTOR and GITHUB_TOKEN. | ||
| - name: Publish to GitHub Packages | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
| run: | | ||
| ./gradlew :ShimmerAndroidInstrumentDriver:publish -Pandroid.useAndroidX=true \ | ||
| -PreleaseVersion="$VERSION" -PdriverVersion="$DRIVER" | ||
|
|
||
| # The .aar just published, so the GitHub Release carries the same file as GitHub Packages. | ||
| - name: Collect the published .aar | ||
| run: | | ||
| mkdir -p ../release-assets | ||
| cp ShimmerAndroidInstrumentDriver/build/outputs/aar/ShimmerAndroidInstrumentDriver-release.aar \ | ||
| "../release-assets/shimmerandroidinstrumentdriver-$VERSION.aar" | ||
| ls -l ../release-assets | ||
|
|
||
| - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
| with: | ||
| name: release-assets | ||
| path: release-assets/ | ||
| if-no-files-found: error | ||
|
|
||
| release: | ||
| needs: [build, publish] | ||
| 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 }} | ||
| DRIVER: ${{ needs.build.outputs.driver }} | ||
| steps: | ||
| - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 | ||
| with: | ||
| name: release-assets | ||
| path: release-assets | ||
|
|
||
| # The .aar's POM lists no dependencies, so the notes say which driver to pair it with. | ||
| - name: Create the tag and GitHub 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 | ||
| driver_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY_OWNER/Shimmer-Java-Android-API/releases/tag/API_v$DRIVER" | ||
| { | ||
| echo "Built against \`com.shimmerresearch:shimmerdriver\` and \`com.shimmerresearch:shimmerbluetoothmanager\` **$DRIVER** ([API_v$DRIVER]($driver_url)). Add both, at that version, to your app's dependencies." | ||
| echo | ||
| # The driver's JNA is desktop-only; its two jars clash on META-INF/AL2.0 in an Android app. | ||
| echo "Exclude \`net.java.dev.jna\` from both, or the app fails packaging with \"2 files found with path 'META-INF/AL2.0'\". The exclusions this library builds with are in [ShimmerAndroidInstrumentDriver/build.gradle]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/blob/$TAG/ShimmerAndroidInstrumentDriver/build.gradle)." | ||
| 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 | ||
| { | ||
| echo "### Released Android API $VERSION" | ||
| echo "- Release: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$TAG" | ||
| echo "- Package: com.shimmerresearch:shimmerandroidinstrumentdriver:$VERSION" | ||
| echo "- Built against driver $DRIVER" | ||
| } >> "$GITHUB_STEP_SUMMARY" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.