-
Notifications
You must be signed in to change notification settings - Fork 0
432 lines (368 loc) · 16.4 KB
/
Copy pathrelease.yml
File metadata and controls
432 lines (368 loc) · 16.4 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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
name: Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: Release version without the leading v
required: true
repository:
description: GitHub repository that will host the release assets
required: false
notarization_submission_id:
description: Apple notarization submission ID to finalize
required: false
notarization_run_id:
description: Release workflow run ID that uploaded the notarization artifact
required: false
permissions:
actions: read
contents: write
jobs:
guard-published-release:
if: github.event_name == 'release'
runs-on: ubuntu-latest
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_REPOSITORY: ${{ github.repository }}
steps:
- name: Verify release has archives
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
version="${RELEASE_TAG#v}"
archive_name="comux-${version}.zip"
cask_name="comux.rb"
assets_path="$RUNNER_TEMP/comux-release-assets.txt"
gh release view "$RELEASE_TAG" \
--repo "$RELEASE_REPOSITORY" \
--json assets \
--jq '.assets[].name' > "$assets_path"
has_asset() {
local asset_name="$1"
grep -Fx "$asset_name" "$assets_path" >/dev/null
}
missing=()
has_asset "$archive_name" || missing+=("$archive_name")
has_asset "$cask_name" || missing+=("$cask_name")
if [[ "${#missing[@]}" -gt 0 ]]; then
echo "::error::Public release $RELEASE_TAG is missing required archive assets: ${missing[*]}"
echo "Use the workflow_dispatch draft-first flow, wait for Apple notarization to be accepted, then finalize the same release before publishing."
exit 1
fi
package-macos:
if: github.event_name == 'workflow_dispatch'
runs-on: macos-15
env:
RELEASE_VERSION: ${{ inputs.version }}
RELEASE_REPOSITORY: ${{ inputs.repository != '' && inputs.repository || github.repository }}
APPLE_CERTIFICATE_CONFIGURED: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 != '' && 'true' || 'false' }}
FINALIZE_NOTARIZATION: ${{ inputs.notarization_submission_id != '' && 'true' || 'false' }}
NOTARIZATION_SUBMISSION_ID: ${{ inputs.notarization_submission_id }}
NOTARIZATION_RUN_ID: ${{ inputs.notarization_run_id }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Select Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "16.4"
- name: Install packaging tools
shell: bash
run: |
set -euo pipefail
brew install xcodegen
- name: Resolve release metadata
id: meta
shell: bash
run: |
set -euo pipefail
version="${RELEASE_VERSION#v}"
if [[ -z "$version" ]]; then
echo "Missing release version." >&2
exit 1
fi
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=v$version" >> "$GITHUB_OUTPUT"
echo "notarization_artifact=comux-notarization-$version" >> "$GITHUB_OUTPUT"
- name: Verify draft release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
tag="${{ steps.meta.outputs.tag }}"
is_draft="$(gh release view "$tag" \
--repo "$RELEASE_REPOSITORY" \
--json isDraft \
--jq '.isDraft' \
2>/dev/null || true)"
if [[ -z "$is_draft" ]]; then
echo "::error::Missing draft release $tag. Create a draft release, write the release notes, then rerun this workflow."
exit 1
fi
if [[ "$is_draft" != "true" && "$FINALIZE_NOTARIZATION" != "true" ]]; then
echo "::error::Release $tag is already public. Start releases from workflow_dispatch so the release stays draft until archives are uploaded."
echo "If you are repairing an existing public release after notarization, rerun this workflow with notarization_submission_id and notarization_run_id."
exit 1
fi
release_notes="$(gh release view "$tag" \
--repo "$RELEASE_REPOSITORY" \
--json body \
--jq '.body')"
changes_header_line="$(grep -n -m1 -Fx "## What's Changed" <<<"$release_notes" | cut -d: -f1 || true)"
if [[ -z "$changes_header_line" ]]; then
echo "::error::Release $tag must contain an exact ## What's Changed heading."
exit 1
fi
changes_section="$(tail -n "+$((changes_header_line + 1))" <<<"$release_notes" | sed '/^## /q')"
if ! grep -Eq '^- .+' <<<"$changes_section"; then
echo "::error::Release $tag needs at least one user-facing bullet under ## What's Changed."
exit 1
fi
- name: Resolve prebuilt release assets
id: prebuilt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
EVENT_NAME: ${{ github.event_name }}
shell: bash
run: |
set -euo pipefail
archive_name="comux-${{ steps.meta.outputs.version }}.zip"
cask_name="comux.rb"
cask_path="$RUNNER_TEMP/$cask_name"
has_asset() {
local asset_name="$1"
grep -Fx "$asset_name" "$RUNNER_TEMP/comux-release-assets.txt" >/dev/null
}
: > "$RUNNER_TEMP/comux-release-assets.txt"
has_prebuilt=false
for attempt in {1..12}; do
gh release view "${{ steps.meta.outputs.tag }}" \
--repo "$RELEASE_REPOSITORY" \
--json assets \
--jq '.assets[].name' > "$RUNNER_TEMP/comux-release-assets.txt" || true
if has_asset "$archive_name" && has_asset "$cask_name"; then
has_prebuilt=true
break
fi
if [[ "$EVENT_NAME" != "release" ]]; then
break
fi
sleep 5
done
if [[ "$has_prebuilt" == "true" ]]; then
gh release download "${{ steps.meta.outputs.tag }}" \
--repo "$RELEASE_REPOSITORY" \
--pattern "$cask_name" \
--dir "$RUNNER_TEMP" \
--clobber
echo "Using prebuilt release assets: $archive_name, $cask_name"
else
echo "No complete prebuilt release asset set found; building in CI."
fi
echo "has_prebuilt=$has_prebuilt" >> "$GITHUB_OUTPUT"
echo "cask=$cask_path" >> "$GITHUB_OUTPUT"
- name: Import Developer ID certificate
if: env.APPLE_CERTIFICATE_CONFIGURED == 'true' && steps.prebuilt.outputs.has_prebuilt != 'true' && env.FINALIZE_NOTARIZATION != 'true'
env:
APPLE_DEVELOPER_CERTIFICATE_P12_BASE64: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }}
APPLE_DEVELOPER_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }}
KEYCHAIN_PASSWORD: ${{ secrets.APPLE_KEYCHAIN_PASSWORD }}
shell: bash
run: |
set -euo pipefail
keychain_path="$RUNNER_TEMP/comux-signing.keychain-db"
certificate_path="$RUNNER_TEMP/developer-id.p12"
echo "$APPLE_DEVELOPER_CERTIFICATE_P12_BASE64" | base64 --decode > "$certificate_path"
security create-keychain -p "$KEYCHAIN_PASSWORD" "$keychain_path"
security set-keychain-settings -lut 21600 "$keychain_path"
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$keychain_path"
security import "$certificate_path" \
-P "$APPLE_DEVELOPER_CERTIFICATE_PASSWORD" \
-A \
-k "$keychain_path"
security list-keychains -d user -s "$keychain_path"
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" "$keychain_path"
- name: Download notarized app candidate
if: env.FINALIZE_NOTARIZATION == 'true' && env.NOTARIZATION_RUN_ID != '' && steps.prebuilt.outputs.has_prebuilt != 'true'
uses: actions/download-artifact@v4
with:
name: ${{ steps.meta.outputs.notarization_artifact }}
path: ${{ runner.temp }}/comux-notarization
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
run-id: ${{ env.NOTARIZATION_RUN_ID }}
- name: Restore notarized app candidate
if: env.FINALIZE_NOTARIZATION == 'true' && steps.prebuilt.outputs.has_prebuilt != 'true'
shell: bash
run: |
set -euo pipefail
if [[ -z "${NOTARIZATION_RUN_ID:-}" ]]; then
echo "notarization_run_id is required when finalizing notarization." >&2
exit 1
fi
app_archive="$RUNNER_TEMP/comux-notarization/comux-app.zip"
if [[ ! -f "$app_archive" ]]; then
echo "Missing notarization artifact app archive: $app_archive" >&2
exit 1
fi
mkdir -p .build/apple
rm -rf .build/apple/comux.app
ditto -x -k "$app_archive" .build/apple
if [[ ! -d .build/apple/comux.app ]]; then
echo "Notarization artifact did not contain comux.app." >&2
exit 1
fi
- name: Build macOS app archive and cask
if: steps.prebuilt.outputs.has_prebuilt != 'true'
id: package
env:
APPLE_CODE_SIGN_IDENTITY: ${{ vars.APPLE_CODE_SIGN_IDENTITY }}
COMUX_NOTARY_APPLE_ID: ${{ secrets.APPLE_NOTARY_APPLE_ID }}
COMUX_NOTARY_TEAM_ID: ${{ secrets.APPLE_NOTARY_TEAM_ID }}
COMUX_NOTARY_PASSWORD: ${{ secrets.APPLE_NOTARY_PASSWORD }}
shell: bash
run: |
set -euo pipefail
output_file="$(mktemp)"
trap 'rm -f "$output_file"' EXIT
args=(
--version "${{ steps.meta.outputs.version }}" \
--repo "${RELEASE_REPOSITORY}"
)
if [[ "$FINALIZE_NOTARIZATION" == "true" ]]; then
args+=(--finalize-notarization "$NOTARIZATION_SUBMISSION_ID")
elif [[ "$APPLE_CERTIFICATE_CONFIGURED" == "true" ]]; then
if [[ -n "${APPLE_CODE_SIGN_IDENTITY:-}" ]]; then
export COMUX_CODE_SIGN_IDENTITY="$APPLE_CODE_SIGN_IDENTITY"
else
export COMUX_CODE_SIGN_IDENTITY="$(
security find-identity -v -p codesigning \
| sed -n 's/.*"\(Developer ID Application:[^"]*\)".*/\1/p' \
| head -n1
)"
fi
if [[ -z "${COMUX_CODE_SIGN_IDENTITY:-}" ]]; then
echo "No Developer ID Application signing identity found." >&2
security find-identity -v -p codesigning >&2
exit 1
fi
fi
if [[ "$FINALIZE_NOTARIZATION" != "true" && "$APPLE_CERTIFICATE_CONFIGURED" == "true" && -n "${COMUX_NOTARY_APPLE_ID:-}" && -n "${COMUX_NOTARY_TEAM_ID:-}" && -n "${COMUX_NOTARY_PASSWORD:-}" ]]; then
args+=(--submit-notarization)
fi
./scripts/brew.sh "${args[@]}" | tee "$output_file"
while IFS= read -r line; do
case "$line" in
archive=*|sha256=*|cask=*|notary_submission_id=*|notary_status=*|notary_state=*)
echo "$line" >> "$GITHUB_OUTPUT"
;;
esac
done < "$output_file"
- name: Prepare notarization artifact
if: steps.package.outputs.notary_submission_id != '' && steps.package.outputs.archive == ''
id: notarization_artifact
shell: bash
run: |
set -euo pipefail
app_archive="$RUNNER_TEMP/comux-app.zip"
state_path="$RUNNER_TEMP/comux-notarization.txt"
ditto --norsrc -c -k --keepParent ".build/apple/comux.app" "$app_archive"
cat > "$state_path" <<EOF
VERSION=${{ steps.meta.outputs.version }}
REPOSITORY=${RELEASE_REPOSITORY}
SUBMISSION_ID=${{ steps.package.outputs.notary_submission_id }}
STATUS=${{ steps.package.outputs.notary_status }}
RUN_ID=${{ github.run_id }}
EOF
echo "app_archive=$app_archive" >> "$GITHUB_OUTPUT"
echo "state=$state_path" >> "$GITHUB_OUTPUT"
- name: Upload notarization artifact
if: steps.notarization_artifact.outputs.app_archive != ''
uses: actions/upload-artifact@v4
with:
name: ${{ steps.meta.outputs.notarization_artifact }}
retention-days: 14
path: |
${{ steps.notarization_artifact.outputs.app_archive }}
${{ steps.notarization_artifact.outputs.state }}
- name: Report pending notarization
if: steps.package.outputs.notary_submission_id != '' && steps.package.outputs.archive == ''
shell: bash
run: |
set -euo pipefail
{
echo "## Apple notarization pending"
echo
echo "Submission ID: \`${{ steps.package.outputs.notary_submission_id }}\`"
echo "Status: \`${{ steps.package.outputs.notary_status }}\`"
echo
echo "After Apple reports \`Accepted\`, finalize this release with:"
echo
echo "\`\`\`bash"
echo "gh workflow run Release -f version=${{ steps.meta.outputs.version }} -f notarization_submission_id=${{ steps.package.outputs.notary_submission_id }} -f notarization_run_id=${{ github.run_id }}"
echo "\`\`\`"
echo
echo "The GitHub release remains a draft until finalization uploads \`comux-${{ steps.meta.outputs.version }}.zip\` and \`comux.rb\`."
} >> "$GITHUB_STEP_SUMMARY"
- name: Upload release assets
if: steps.prebuilt.outputs.has_prebuilt != 'true' && steps.package.outputs.archive != '' && steps.package.outputs.cask != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
gh release upload "${{ steps.meta.outputs.tag }}" \
"${{ steps.package.outputs.archive }}" \
"${{ steps.package.outputs.cask }}" \
--clobber
- name: Publish draft release
if: steps.prebuilt.outputs.has_prebuilt == 'true' || (steps.package.outputs.archive != '' && steps.package.outputs.cask != '')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
set -euo pipefail
gh release edit "${{ steps.meta.outputs.tag }}" \
--repo "$RELEASE_REPOSITORY" \
--draft=false \
--latest
- name: Upload workflow artifacts
if: steps.prebuilt.outputs.has_prebuilt != 'true' && steps.package.outputs.archive != '' && steps.package.outputs.cask != ''
uses: actions/upload-artifact@v4
with:
name: comux-release-${{ steps.meta.outputs.version }}
path: |
${{ steps.package.outputs.archive }}
${{ steps.package.outputs.cask }}
- name: Publish cask to tap
if: vars.HOMEBREW_TAP_REPOSITORY != '' && (steps.prebuilt.outputs.has_prebuilt == 'true' || steps.package.outputs.cask != '')
env:
HOMEBREW_TAP_REPOSITORY: ${{ vars.HOMEBREW_TAP_REPOSITORY }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
CASK_PATH: ${{ steps.prebuilt.outputs.has_prebuilt == 'true' && steps.prebuilt.outputs.cask || steps.package.outputs.cask }}
shell: bash
run: |
set -euo pipefail
if [[ -z "${HOMEBREW_TAP_TOKEN:-}" ]]; then
echo "HOMEBREW_TAP_TOKEN is not configured; skipping tap update."
exit 0
fi
tap_dir="$(mktemp -d)"
trap 'rm -rf "$tap_dir"' EXIT
git clone "https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/${HOMEBREW_TAP_REPOSITORY}.git" "$tap_dir"
mkdir -p "$tap_dir/Casks"
cp "$CASK_PATH" "$tap_dir/Casks/comux.rb"
git -C "$tap_dir" config user.name "github-actions[bot]"
git -C "$tap_dir" config user.email "41898282+github-actions[bot]@users.noreply.github.com"
if git -C "$tap_dir" diff --quiet -- Casks/comux.rb; then
echo "Tap is already up to date."
exit 0
fi
git -C "$tap_dir" add Casks/comux.rb
git -C "$tap_dir" commit -m "chore: update comux to v${{ steps.meta.outputs.version }}"
git -C "$tap_dir" push origin HEAD