Repository navigation
355 lines (332 loc) · 17.1 KB
/
Copy pathrelease.yml
File metadata and controls
355 lines (332 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# 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.
#
# Hardware test gate: before releasing, run tools/hil/run-android-hil.ps1 -Report on the bench at the
# commit being released (see tools/hil/README.md). It posts the commit status
# "android-hil (driver X)". A real release refuses to build unless that status passed for this commit
# and this driver, or hil_waiver gives a Jira key (the waiver goes into the release notes). Dry runs
# only warn. The release notes say what the hardware test found.
#
# 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
hil_waiver:
description: 'Jira key to release without a passing hardware test (HIL), e.g. DEV-1234. Blank = require one'
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
statuses: read # the hardware test result the bench posts on the commit
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 }}
hil: ${{ steps.hil.outputs.hil }}
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
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})"
# Before any building, so a missing hardware test fails the release in seconds.
- name: Check the hardware test (HIL) result
id: hil
working-directory: .
env:
GH_TOKEN: ${{ github.token }}
DRIVER: ${{ steps.version.outputs.driver }}
WAIVER: ${{ inputs.hil_waiver }}
run: |
context="android-hil (driver $DRIVER)"
if [ -n "$WAIVER" ] && ! [[ "$WAIVER" =~ ^[A-Z][A-Z0-9]+-[0-9]+$ ]]; then
echo "::error::hil_waiver must be a Jira key such as DEV-1234, not '$WAIVER'."
exit 1
fi
# Newest first: the latest result for this context on this exact commit decides.
line=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/statuses" --paginate \
--jq '.[] | [.context, .state, .description] | @tsv' | awk -F'\t' -v c="$context" '$1 == c { print; exit }')
state=$(printf '%s' "$line" | cut -f2)
description=$(printf '%s' "$line" | cut -f3)
if [ "$state" = success ]; then
echo "Hardware test passed on $GITHUB_SHA with driver $DRIVER: $description"
echo "hil=Tested on hardware before release (driver $DRIVER): $description." >> "$GITHUB_OUTPUT"
elif [ -n "$WAIVER" ]; then
echo "::warning::No passing '$context' on $GITHUB_SHA (found: ${state:-none}); released under waiver $WAIVER."
echo "hil=Released without a passing hardware test (HIL), waived under $WAIVER." >> "$GITHUB_OUTPUT"
elif [ "$DRY_RUN" = true ]; then
echo "::warning::No passing '$context' on $GITHUB_SHA (found: ${state:-none}). A real release would stop here."
else
echo "::error::No passing '$context' on $GITHUB_SHA (found: ${state:-none}${description:+: $description}). On the bench, at this commit, run: tools/hil/run-android-hil.ps1 -Report -DriverVersion $DRIVER. Then run this workflow again, or give a Jira key in hil_waiver."
exit 1
fi
# 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 }}
HIL: ${{ needs.build.outputs.hil }}
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
if [ -n "$HIL" ]; then
echo "$HIL"
echo
fi
gh api "repos/$GITHUB_REPOSITORY/releases/generate-notes" "${args[@]}" --jq .body
} > notes.md
gh release create "$TAG" release-assets/* \
--repo "$GITHUB_REPOSITORY" \
--target "$GITHUB_SHA" \
--title "$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"
echo "- ${HIL:-No hardware test result}"
} >> "$GITHUB_STEP_SUMMARY"