Repository navigation
362 lines (336 loc) · 15 KB
/
Copy pathrelease.yml
File metadata and controls
362 lines (336 loc) · 15 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
356
357
358
359
360
361
362
name: Release
on:
push:
branches:
- main
- '*.x'
workflow_dispatch:
inputs:
publish_tag:
description: 'Existing tag to (re)publish, e.g. 10.1.2. Leave empty for a normal release run.'
required: false
default: ''
publish-targets:
description: >-
Leave as-is. central is a manual escape hatch for a release that has to
go out when the Stream repository cannot take it.
required: false
type: choice
options:
- streamRepo
- streamRepo,central
- central
default: streamRepo
permissions:
contents: read
env:
# A push has no inputs: releases go to the Stream repository.
PUBLISH_TARGETS: ${{ inputs.publish-targets || 'streamRepo' }}
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false
jobs:
# Reversible half: keep the Release PR current. Stands down only while a release is
# already pending, because until that one is tagged there is no release commit to stop
# the walk at and it would propose the same commits again in a second Release PR.
release-pr:
name: Release PR
needs: detect
# Gate on the explicit value. If detect fails or is skipped the output is empty, and
# anything short of a definite "nothing pending" has to hold this job back, or it
# proposes a second Release PR on top of one that may still be untagged.
if: needs.detect.outputs.pending == 'false'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
issues: write
pull-requests: write
steps:
- uses: googleapis/release-please-action@v4
with:
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
target-branch: ${{ github.ref_name }}
skip-github-release: true
# The tag, the GitHub Release and the Maven Central push are irreversible, so they run only on the push that merged the Release PR: `ready` requires the pending release's merge commit to be this run's commit. A release from the default branch has no test run, because the Release PR adds only the version bump and changelog to already-tested code; a hotfix release from `N.x` runs the unit lane first, because hotfix commits are pushed without a PR.
detect:
name: Detect pending release
if: >-
(github.event_name == 'push' || inputs.publish_tag == '') &&
(github.ref_name == 'main' || endsWith(github.ref_name, '.x'))
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
# write, not read: a stuck release is announced on its own Release PR, because
# nothing else reaches a person without them opening the run first.
pull-requests: write
issues: read
outputs:
pending: ${{ steps.find.outputs.pending }}
ready: ${{ steps.find.outputs.ready }}
steps:
- name: Find a merged Release PR waiting to be tagged
id: find
env:
GH_TOKEN: ${{ github.token }}
BASE: ${{ github.ref_name }}
HEAD_SHA: ${{ github.sha }}
run: |
pending=false
ready=false
lookup_failed=false
# Query the label directly, and page: release-please applies the label when it
# opens the Release PR, not when it merges, so every Release PR closed without
# merging keeps it forever and holds a slot in this listing. One page would
# eventually stop containing the genuinely pending release, which reads as
# "nothing to release" and passes. merged_at comes back in the listing, so
# filtering on it here keeps the per-PR lookups below to real candidates.
# --paginate makes this N requests, so guard it too, and remember that a failure
# here means "unknown", never "nothing to release".
if ! nums="$(gh api --paginate "repos/${GITHUB_REPOSITORY}/issues" \
-X GET -f state=closed -f labels='autorelease: pending' -f per_page=100 \
--jq '.[] | select(.pull_request.merged_at != null) | .number')"; then
echo "::warning::Could not list pending releases."
nums=""
lookup_failed=true
fi
# The base branch is not in that listing, so each candidate still needs a
# lookup: a hotfix branch can hold its own pending release, and taking the
# newest label match would drop this branch's release until the other clears.
num=""
sha=""
for n in $nums; do
# Under `bash -e` an unguarded assignment from a non-2xx would abort the
# step, which would fail detect and skip release-pr with it.
if ! sha="$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${n}" \
--jq 'select(.merged_at != null and .base.ref == env.BASE) | .merge_commit_sha // empty')"; then
echo "::warning::Could not read PR #${n}; skipping it."
sha=""
lookup_failed=true
continue
fi
if [ -n "$sha" ]; then
num="$n"
break
fi
done
if [ -z "$sha" ] && [ "$lookup_failed" = true ]; then
# Unknown is not the same as nothing. Releasing on a guess is how a second
# Release PR lands on top of one that was never tagged.
pending=true
echo "::warning::Could not determine whether a release is pending on ${BASE}; standing down."
elif [ -z "$sha" ]; then
echo "No pending release on ${BASE}."
elif [ "$sha" != "$HEAD_SHA" ]; then
# Reached when an earlier release run failed after the Release PR merged.
# Finishing it from a later push would retry a deterministic failure (a refused major tag, a broken build) on every push, so stand down and say why.
pending=true
echo "::warning::Release PR #${num} is still pending at ${sha}, which is not this run's commit ${HEAD_SHA}. Re-run the workflow run for ${sha} to finish that release."
{
echo "### Release stuck"
echo
echo "Release PR #${num} merged at \`${sha}\` and was never tagged, so no Release PR will be opened or refreshed until it clears."
echo
echo "Re-run the \`Release\` run for \`${sha}\`. If that commit is genuinely broken, remove the \`autorelease: pending\` label from #${num} by hand and release forward."
} >> "$GITHUB_STEP_SUMMARY"
# A warning annotation and a step summary are both only visible to someone who
# already opened the run. Tell the Release PR's subscribers once per stuck sha.
marker="<!-- release-stuck:${sha} -->"
seen="$(gh api "repos/${GITHUB_REPOSITORY}/issues/${num}/comments" --paginate --jq '.[].body' || echo "")"
if ! printf '%s' "$seen" | grep -qF "$marker"; then
{
echo "$marker"
echo "This release is stuck: #${num} merged at \`${sha}\` and was never tagged, so no Release PR is opened or refreshed until it clears."
echo
echo "Re-run the \`Release\` run for \`${sha}\`. If that commit is genuinely broken, remove the \`autorelease: pending\` label here by hand and release forward."
} > "${RUNNER_TEMP}/release-stuck.md"
gh pr comment "$num" --repo "$GITHUB_REPOSITORY" --body-file "${RUNNER_TEMP}/release-stuck.md" \
|| echo "::warning::Could not comment on #${num}."
fi
else
pending=true
ready=true
echo "Pending release #${num} will be tagged at ${sha}."
fi
{
echo "pending=${pending}"
echo "ready=${ready}"
} >> "$GITHUB_OUTPUT"
tests:
name: Tests (hotfix only)
needs: detect
if: needs.detect.outputs.ready == 'true' && github.ref_name != github.event.repository.default_branch
uses: ./.github/workflows/run_tests.yml
# Irreversible half.
release:
name: 🚀 Tag and release
needs: [detect, tests]
if: >-
${{ !cancelled() && needs.detect.result == 'success' && needs.detect.outputs.ready == 'true'
&& (needs.tests.result == 'success' || needs.tests.result == 'skipped') }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
issues: write
pull-requests: write
outputs:
release_created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: googleapis/release-please-action@v4
id: release
with:
config-file: release-please-config.json
manifest-file: .release-please-manifest.json
target-branch: ${{ github.ref_name }}
skip-github-pull-request: true
# Chained rather than triggered on the release event, because a GitHub Release created
# with GITHUB_TOKEN starts no new workflow run. Also reachable on its own through
# workflow_dispatch with publish_tag, which is the recovery path once GitHub has
# retired the original run and "Re-run failed jobs" is gone.
publish:
name: 📦 Publish
needs: release
if: >-
!cancelled() &&
(inputs.publish_tag != '' || needs.release.outputs.release_created == 'true')
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
outputs:
tag: ${{ steps.target.outputs.tag }}
steps:
- name: Resolve tag
id: target
env:
PUBLISH_TAG: ${{ inputs.publish_tag }}
RELEASE_TAG: ${{ needs.release.outputs.tag_name }}
run: |
tag="${PUBLISH_TAG:-$RELEASE_TAG}"
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v5.0.1
with:
ref: ${{ steps.target.outputs.tag }}
# The Gradle build runs project code, and nothing here writes to the
# repository, so do not leave GITHUB_TOKEN in .git/config.
persist-credentials: false
- name: Setup JDK 17
uses: actions/setup-java@v5.1.0
with:
distribution: 'corretto'
java-version: '17'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
# An env var rather than -P, so a value with a space cannot split into a second argument.
- name: Select publish targets
run: echo "ORG_GRADLE_PROJECT_streamPublishTargets=$PUBLISH_TARGETS" >> "$GITHUB_ENV"
# Stages a signed Maven-2 tree under build/staged-repo for the upload job.
- name: Stage for the Stream repository
if: ${{ contains(env.PUBLISH_TARGETS, 'streamRepo') }}
env:
STREAM_API_KEY: ${{ vars.STREAM_API_KEY }}
STREAM_API_SECRET: ${{ secrets.STREAM_API_SECRET }}
GPG_KEY_CONTENTS: ${{ secrets.GPG_KEY_CONTENTS }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: |
./gradlew publishMavenPublicationToStreamRepoStagingRepository --no-daemon --max-workers 1
- name: Publish to Maven Central
if: ${{ contains(env.PUBLISH_TARGETS, 'central') }}
env:
STREAM_API_KEY: ${{ vars.STREAM_API_KEY }}
STREAM_API_SECRET: ${{ secrets.STREAM_API_SECRET }}
GPG_KEY_CONTENTS: ${{ secrets.GPG_KEY_CONTENTS }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
SONATYPE_STAGING_PROFILE_ID: ${{ vars.SONATYPE_STAGING_PROFILE_ID }}
run: |
./gradlew publishToSonatype --no-daemon --max-workers 1 closeAndReleaseSonatypeStagingRepository
# Handed to a job that has never seen the signing key -- the reason Gradle stages to a
# directory instead of writing to the bucket itself.
- name: Hand the staged tree to the upload job
if: ${{ contains(env.PUBLISH_TARGETS, 'streamRepo') }}
uses: actions/upload-artifact@v4
with:
name: stream-repo-staged
path: build/staged-repo
retention-days: 1
if-no-files-found: error
# Separate job: secrets are injected per job, so this one holds the R2 credential and never the
# signing key, and the publish job holds the signing key and never the R2 credential.
upload:
name: ☁️ Upload to the Stream repository
needs: publish
if: ${{ !cancelled() && needs.publish.result == 'success' && contains(inputs.publish-targets || 'streamRepo', 'streamRepo') }}
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
steps:
- name: Download the staged tree
uses: actions/download-artifact@v4
with:
name: stream-repo-staged
path: build/staged-repo
- name: Publish to the Stream repository
uses: GetStream/stream-build-conventions-android/.github/actions/publish-to-stream-repo@v1.0.1
with:
staged-directory: build/staged-repo
channel: releases
endpoint: ${{ secrets.STREAM_REPO_ENDPOINT }}
bucket: ${{ secrets.STREAM_REPO_BUCKET }}
access-key-id: ${{ secrets.STREAM_REPO_ACCESS_KEY_ID }}
secret-access-key: ${{ secrets.STREAM_REPO_SECRET_ACCESS_KEY }}
# release-please created the GitHub Release before publishing, so the card is added to it
# once the artifact is actually resolvable from the Stream repository.
release-notes-header:
name: 📝 Add the Stream repository card to the release
needs: [publish, upload]
if: ${{ !cancelled() && needs.upload.result == 'success' && (inputs.publish-targets || 'streamRepo') == 'streamRepo' }}
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
steps:
- name: Prepend the card
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.publish.outputs.tag }}
run: |
set -euo pipefail
gh release view "$TAG" -R "$GITHUB_REPOSITORY" --json body -q .body > notes.md
# A re-run, or a re-publish through publish_tag, must not stack a second card.
if grep -q "stream-io-repo.com" notes.md; then
echo "The card is already there."
exit 0
fi
cat > card.md <<EOF
> [!IMPORTANT]
> **\`io.getstream:stream-sdk-java:$TAG\` is published to the Stream Maven repository, not Maven Central.**
>
> Gradle (\`build.gradle.kts\`):
> \`\`\`kotlin
> repositories {
> mavenCentral()
> maven("https://stream-io-repo.com")
> }
> \`\`\`
>
> Maven (\`pom.xml\`):
> \`\`\`xml
> <repositories>
> <repository>
> <id>stream</id>
> <url>https://stream-io-repo.com</url>
> </repository>
> </repositories>
> \`\`\`
EOF
cat card.md notes.md > body.md
gh release edit "$TAG" -R "$GITHUB_REPOSITORY" --notes-file body.md