Repository navigation
399 lines (348 loc) · 13.9 KB
/
Copy pathrelease.yml
File metadata and controls
399 lines (348 loc) · 13.9 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
name: Release
on:
workflow_dispatch:
inputs:
version_bump:
description: Version bump type
required: true
default: patch
type: choice
options:
- patch
- minor
- major
push:
tags:
- 'v*'
concurrency:
group: release
cancel-in-progress: false
permissions: {}
env:
XCODE_PROJECT: "BrowserClutch.xcodeproj"
XCODE_SCHEME: "BrowserClutch"
APP_NAME: "BrowserClutch"
jobs:
checks:
name: Checks
runs-on: macos-15
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Lint
run: |
brew install swiftlint
swiftlint --strict
- name: Test
run: |
xcodebuild test \
-project BrowserClutch.xcodeproj \
-scheme BrowserClutch \
-destination 'platform=macOS'
create-tag:
name: Create Tag
needs: checks
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
outputs:
version: ${{ steps.bump.outputs.version }}
tag: ${{ steps.bump.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Verify main branch
run: |
if [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "::error::Release must be run from main branch, not ${{ github.ref }}"
exit 1
fi
- name: Read current version and bump
id: bump
run: |
CURRENT=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "0.0.0")
echo "Current version: $CURRENT"
IFS='.' read -r MAJOR MINOR PATCH <<< "$CURRENT"
case "${{ inputs.version_bump }}" in
major)
MAJOR=$((MAJOR + 1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR + 1))
PATCH=0
;;
patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.bump.outputs.tag }}" -m "Release ${{ steps.bump.outputs.tag }}"
git push origin "${{ steps.bump.outputs.tag }}"
build-and-release:
name: Build, Sign & Release
needs: [checks, create-tag]
if: always() && needs.checks.result == 'success' && (needs.create-tag.result == 'success' || needs.create-tag.result == 'skipped')
runs-on: macos-15
environment: release
permissions:
contents: write
env:
RELEASE_TAG: ${{ needs.create-tag.outputs.tag || github.ref_name }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ env.RELEASE_TAG }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get version from tag
id: version
run: |
VERSION=${RELEASE_TAG#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
BUILD=$((MAJOR * 10000 + MINOR * 100 + PATCH))
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $VERSION" BrowserClutch/Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD" BrowserClutch/Info.plist
- name: Get previous tag
id: prev_tag
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT
echo "Previous tag: $PREV_TAG"
- name: Import Apple certificate
env:
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
run: |
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db
KEYCHAIN_PASSWORD=$(openssl rand -base64 32)
security create-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security set-keychain-settings -lut 21600 "$KEYCHAIN_PATH"
security unlock-keychain -p "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
echo "$APPLE_CERTIFICATE" | base64 --decode > $RUNNER_TEMP/certificate.p12
security import $RUNNER_TEMP/certificate.p12 \
-P "$APPLE_CERTIFICATE_PASSWORD" \
-A -t cert -f pkcs12 \
-k "$KEYCHAIN_PATH"
security set-key-partition-list -S apple-tool:,apple: \
-k "$KEYCHAIN_PASSWORD" "$KEYCHAIN_PATH"
security list-keychain -d user -s "$KEYCHAIN_PATH" $(security list-keychain -d user | tr -d '"')
rm $RUNNER_TEMP/certificate.p12
# Verify identity is available
security find-identity -v -p codesigning "$KEYCHAIN_PATH"
- name: Build archive
env:
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
run: |
xcodebuild -project "$XCODE_PROJECT" \
-scheme "$XCODE_SCHEME" \
-configuration Release \
-archivePath build/$APP_NAME.xcarchive \
CODE_SIGN_IDENTITY="$APPLE_SIGNING_IDENTITY" \
DEVELOPMENT_TEAM="$APPLE_TEAM_ID" \
CODE_SIGN_STYLE="Manual" \
OTHER_CODE_SIGN_FLAGS="--options=runtime" \
archive
- name: Export app
env:
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
run: |
cat > ExportOptions.plist << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>destination</key>
<string>export</string>
<key>method</key>
<string>developer-id</string>
<key>signingStyle</key>
<string>manual</string>
<key>signingCertificate</key>
<string>${APPLE_SIGNING_IDENTITY}</string>
<key>teamID</key>
<string>${APPLE_TEAM_ID}</string>
</dict>
</plist>
EOF
xcodebuild -exportArchive \
-archivePath build/$APP_NAME.xcarchive \
-exportPath build \
-exportOptionsPlist ExportOptions.plist
- name: Notarize app
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
run: |
ditto -c -k --keepParent "build/$APP_NAME.app" "build/$APP_NAME.zip"
xcrun notarytool submit "build/$APP_NAME.zip" \
--apple-id "$APPLE_ID" \
--password "$APPLE_PASSWORD" \
--team-id "$APPLE_TEAM_ID" \
--wait
xcrun stapler staple "build/$APP_NAME.app"
rm "build/$APP_NAME.zip"
- name: Create Sparkle update zip
run: |
ditto -c -k --keepParent "build/$APP_NAME.app" "build/$APP_NAME-${{ steps.version.outputs.version }}.zip"
- name: Sign update with Sparkle
env:
SPARKLE_ED_PRIVATE_KEY: ${{ secrets.SPARKLE_ED_PRIVATE_KEY }}
run: |
SPARKLE_VERSION="2.8.1"
curl -sL "https://github.com/sparkle-project/Sparkle/releases/download/${SPARKLE_VERSION}/Sparkle-${SPARKLE_VERSION}.tar.xz" -o sparkle.tar.xz
mkdir -p sparkle-tools
tar -xf sparkle.tar.xz -C sparkle-tools
rm sparkle.tar.xz
# Write EdDSA key to temp file (sign_update requires -f flag, not stdin pipe)
echo "$SPARKLE_ED_PRIVATE_KEY" > "$RUNNER_TEMP/sparkle_key"
ZIP_FILE="build/$APP_NAME-${{ steps.version.outputs.version }}.zip"
SIGN_UPDATE=$(find sparkle-tools -name sign_update -type f | head -1)
SIGN_OUTPUT=$("$SIGN_UPDATE" "$ZIP_FILE" -f "$RUNNER_TEMP/sparkle_key")
rm -f "$RUNNER_TEMP/sparkle_key"
ED_SIGNATURE=$(echo "$SIGN_OUTPUT" | grep -o 'sparkle:edSignature="[^"]*"' | cut -d'"' -f2)
FILE_LENGTH=$(stat -f%z "$ZIP_FILE")
echo "ed_signature=$ED_SIGNATURE" >> $GITHUB_OUTPUT
echo "file_length=$FILE_LENGTH" >> $GITHUB_OUTPUT
id: sparkle_sign
- name: Generate appcast.xml
run: |
VERSION="${{ steps.version.outputs.version }}"
DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/download/${{ env.RELEASE_TAG }}/$APP_NAME-${VERSION}.zip"
PUB_DATE=$(date -u +"%a, %d %b %Y %H:%M:%S %z")
cat > "build/appcast.xml" << APPCAST_EOF
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Browser Clutch Updates</title>
<item>
<title>Version ${VERSION}</title>
<pubDate>${PUB_DATE}</pubDate>
<sparkle:version>${VERSION}</sparkle:version>
<sparkle:shortVersionString>${VERSION}</sparkle:shortVersionString>
<sparkle:minimumSystemVersion>14.0</sparkle:minimumSystemVersion>
<enclosure url="${DOWNLOAD_URL}"
type="application/octet-stream"
sparkle:edSignature="${{ steps.sparkle_sign.outputs.ed_signature }}"
length="${{ steps.sparkle_sign.outputs.file_length }}" />
</item>
</channel>
</rss>
APPCAST_EOF
- name: Create DMG
run: |
mkdir -p build/dmg
cp -R "build/$APP_NAME.app" build/dmg/
ln -s /Applications build/dmg/Applications
hdiutil create -volname "$APP_NAME" \
-srcfolder build/dmg \
-ov -format UDZO \
"build/$APP_NAME-${{ steps.version.outputs.version }}.dmg"
- name: Sign DMG
env:
APPLE_SIGNING_IDENTITY: ${{ secrets.APPLE_SIGNING_IDENTITY }}
run: |
codesign --force --sign "$APPLE_SIGNING_IDENTITY" \
"build/$APP_NAME-${{ steps.version.outputs.version }}.dmg"
- name: Notarize DMG
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
run: |
xcrun notarytool submit \
"build/$APP_NAME-${{ steps.version.outputs.version }}.dmg" \
--apple-id "$APPLE_ID" \
--password "$APPLE_PASSWORD" \
--team-id "$APPLE_TEAM_ID" \
--wait
xcrun stapler staple \
"build/$APP_NAME-${{ steps.version.outputs.version }}.dmg"
- name: Build Changelog
id: changelog
uses: mikepenz/release-changelog-builder-action@v6
with:
configurationJson: |
{
"categories": [
{ "title": "## ✨ Features", "labels": ["feature", "enhancement"] },
{ "title": "## 🐛 Bug Fixes", "labels": ["bug", "fix"] },
{ "title": "## 📝 Documentation", "labels": ["documentation"] },
{ "title": "## 🔧 Other", "labels": [] }
],
"template": "#{{CHANGELOG}}\n\n**Full Changelog**: #{{RELEASE_DIFF}}",
"pr_template": "- #{{TITLE}} (#{{NUMBER}})",
"empty_template": "No changes since last release."
}
fromTag: ${{ steps.prev_tag.outputs.tag }}
toTag: ${{ env.RELEASE_TAG }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ env.RELEASE_TAG }}
name: ${{ env.APP_NAME }} ${{ env.RELEASE_TAG }}
body: |
## Installation
1. Download the DMG below
2. Open it and drag ${{ env.APP_NAME }} to Applications
3. Set as default browser in System Settings → Desktop & Dock
${{ steps.changelog.outputs.changelog }}
files: |
build/${{ env.APP_NAME }}-${{ steps.version.outputs.version }}.dmg
build/${{ env.APP_NAME }}-${{ steps.version.outputs.version }}.zip
build/appcast.xml
draft: false
prerelease: false
- name: Upload artifact
uses: actions/upload-artifact@v6
if: always()
with:
name: ${{ env.APP_NAME }}-${{ steps.version.outputs.version }}
path: build/${{ env.APP_NAME }}-${{ steps.version.outputs.version }}.dmg
if-no-files-found: ignore
- name: Cleanup keychain
if: always()
run: |
security delete-keychain $RUNNER_TEMP/app-signing.keychain-db || true
cleanup:
name: Cleanup on failure
needs: [create-tag, build-and-release]
if: failure() && needs.create-tag.result == 'success'
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
steps:
- name: Delete tag and partial release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ needs.create-tag.outputs.tag }}"
RELEASE_ID=$(gh api "repos/${{ github.repository }}/releases/tags/$TAG" --jq '.id' 2>/dev/null || echo "")
if [ -n "$RELEASE_ID" ]; then
gh api -X DELETE "repos/${{ github.repository }}/releases/$RELEASE_ID" || true
fi
gh api -X DELETE "repos/${{ github.repository }}/git/refs/tags/$TAG" || true
echo "Cleaned up tag $TAG — fix the issue and retry"