forked from productdevbook/port-killer
-
Notifications
You must be signed in to change notification settings - Fork 0
450 lines (377 loc) · 16 KB
/
Copy pathrelease.yml
File metadata and controls
450 lines (377 loc) · 16 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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
name: Release
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run (skip upload to release)'
required: false
default: 'false'
type: boolean
version:
description: 'Version to test (e.g., v3.2.0-test)'
required: false
default: 'v0.0.0-test'
type: string
workflow_call:
inputs:
is_pr_build:
description: 'Is this a PR build?'
type: boolean
default: false
pr_number:
description: 'PR number for artifact naming'
type: string
default: ''
version_override:
description: 'Version override (e.g., 0.0.0-pr123)'
type: string
default: ''
ref:
description: 'Git ref to checkout (branch name)'
type: string
default: ''
permissions:
contents: write
env:
# Use input version for workflow_dispatch, otherwise use tag
RELEASE_VERSION: ${{ inputs.version_override || inputs.version || github.ref_name }}
jobs:
create-release:
name: Create Release
runs-on: ubuntu-latest
# Skip for PR builds and dry runs
if: ${{ !inputs.dry_run && !inputs.is_pr_build }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Create GitHub Release with Changelog
run: npx changelogithub
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-macos:
name: Build macOS
needs: create-release
if: ${{ always() && (needs.create-release.result == 'success' || needs.create-release.result == 'skipped') }}
runs-on: macos-latest
defaults:
run:
working-directory: platforms/macos
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || '' }}
fetch-depth: 0
- name: Setup Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- name: Import Code Signing Certificate
env:
CERTIFICATE_BASE64: ${{ secrets.DEVELOPER_ID_CERTIFICATE_BASE64 }}
CERTIFICATE_PASSWORD: ${{ secrets.DEVELOPER_ID_CERTIFICATE_PASSWORD }}
KEYCHAIN_PASSWORD: ${{ github.run_id }}
run: |
# Create temporary keychain
KEYCHAIN_PATH=$RUNNER_TEMP/signing.keychain-db
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
# Import certificate
CERTIFICATE_PATH=$RUNNER_TEMP/certificate.p12
echo -n "$CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH
security import $CERTIFICATE_PATH -P "$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
- name: Update version in Info.plist
run: |
VERSION="${RELEASE_VERSION#v}" # Remove 'v' prefix (v1.2.4 -> 1.2.4)
BUILD_NUMBER=$(git rev-list --count HEAD)
# Update version strings using PlistBuddy
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${VERSION}" Resources/Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${BUILD_NUMBER}" Resources/Info.plist
echo "Updated version to ${VERSION} (build ${BUILD_NUMBER})"
- name: Build app bundle
run: ./scripts/build-app.sh
- name: Sign app with Developer ID
env:
DEVELOPER_ID_NAME: ${{ secrets.DEVELOPER_ID_NAME }}
run: |
APP_PATH=".build/apple/Products/Release/PortKiller.app"
FRAMEWORKS_PATH="$APP_PATH/Contents/Frameworks"
SPARKLE="$FRAMEWORKS_PATH/Sparkle.framework/Versions/B"
# Sign Sparkle framework components (inside out, bottom-up)
# Note: XPC services removed in build-app.sh for non-sandboxed apps
if [ -d "$FRAMEWORKS_PATH/Sparkle.framework" ]; then
echo "Signing Sparkle framework components..."
# Autoupdate binary
codesign --force --options runtime --timestamp \
--sign "$DEVELOPER_ID_NAME" \
"$SPARKLE/Autoupdate"
# Updater app
codesign --force --options runtime --timestamp \
--sign "$DEVELOPER_ID_NAME" \
"$SPARKLE/Updater.app"
# Main framework
codesign --force --options runtime --timestamp \
--sign "$DEVELOPER_ID_NAME" \
"$FRAMEWORKS_PATH/Sparkle.framework"
fi
# Sign main app
codesign --force --options runtime --timestamp \
--sign "$DEVELOPER_ID_NAME" \
"$APP_PATH"
# Verify signatures
codesign --verify --deep --strict --verbose=2 "$APP_PATH"
- name: Notarize app
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
run: |
APP_PATH=".build/apple/Products/Release/PortKiller.app"
# Create ZIP for notarization
ditto -c -k --keepParent "$APP_PATH" "PortKiller.zip"
# Submit for notarization and capture output
SUBMIT_OUTPUT=$(xcrun notarytool submit "PortKiller.zip" \
--apple-id "$APPLE_ID" \
--password "$APPLE_ID_PASSWORD" \
--team-id "$APPLE_TEAM_ID" \
--wait 2>&1) || true
echo "$SUBMIT_OUTPUT"
# Extract submission ID and get detailed log if failed
SUBMISSION_ID=$(echo "$SUBMIT_OUTPUT" | grep -o 'id: [a-f0-9-]*' | head -1 | cut -d' ' -f2)
if echo "$SUBMIT_OUTPUT" | grep -q "Invalid"; then
echo "=== NOTARIZATION FAILED - Getting detailed log ==="
xcrun notarytool log "$SUBMISSION_ID" \
--apple-id "$APPLE_ID" \
--password "$APPLE_ID_PASSWORD" \
--team-id "$APPLE_TEAM_ID"
exit 1
fi
# Staple the notarization ticket
xcrun stapler staple "$APP_PATH"
# Cleanup
rm "PortKiller.zip"
- name: Create DMG
run: |
APP_NAME="PortKiller"
VERSION="${RELEASE_VERSION}"
# Use different naming for PR builds
if [ "${{ inputs.is_pr_build }}" = "true" ]; then
DMG_NAME="${APP_NAME}-pr${{ inputs.pr_number }}-macos.dmg"
else
DMG_NAME="${APP_NAME}-${VERSION}-macos.dmg"
fi
# Create temporary directory for DMG contents
mkdir -p dmg_contents
# Use ditto to preserve symlinks and extended attributes
ditto .build/apple/Products/Release/PortKiller.app dmg_contents/PortKiller.app
# Create Applications symlink
ln -s /Applications dmg_contents/Applications
# Create DMG
hdiutil create -volname "$APP_NAME" \
-srcfolder dmg_contents \
-ov -format UDZO \
"$DMG_NAME"
# Cleanup
rm -rf dmg_contents
echo "DMG_NAME=$DMG_NAME" >> $GITHUB_ENV
- name: Sign DMG
env:
DEVELOPER_ID_NAME: ${{ secrets.DEVELOPER_ID_NAME }}
run: |
codesign --force --sign "$DEVELOPER_ID_NAME" --timestamp "$DMG_NAME"
- name: Notarize DMG
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
run: |
# Notarize DMG
SUBMIT_OUTPUT=$(xcrun notarytool submit "$DMG_NAME" \
--apple-id "$APPLE_ID" \
--password "$APPLE_ID_PASSWORD" \
--team-id "$APPLE_TEAM_ID" \
--wait 2>&1) || true
echo "Notarization Output: $SUBMIT_OUTPUT"
if echo "$SUBMIT_OUTPUT" | grep -q "Accepted"; then
xcrun stapler staple "$DMG_NAME" || echo "Stapling failed but continuing..."
fi
- name: Generate Sparkle EdDSA signature
if: ${{ !inputs.is_pr_build }}
env:
SPARKLE_PRIVATE_KEY: ${{ secrets.SPARKLE_PRIVATE_KEY }}
run: |
# Download Sparkle tools
curl -L -o sparkle.tar.xz "https://github.com/sparkle-project/Sparkle/releases/download/2.8.1/Sparkle-2.8.1.tar.xz"
mkdir -p sparkle_tools
tar -xf sparkle.tar.xz -C sparkle_tools
echo "$SPARKLE_PRIVATE_KEY" > /tmp/sparkle_private_key
# Generate signature
SIGN_OUTPUT=$(sparkle_tools/bin/sign_update "$DMG_NAME" -f /tmp/sparkle_private_key)
SIGNATURE=$(echo "$SIGN_OUTPUT" | grep -o 'edSignature="[^"]*"' | sed 's/edSignature="//;s/"$//')
echo "SPARKLE_SIGNATURE=$SIGNATURE" >> $GITHUB_ENV
rm /tmp/sparkle_private_key
- name: Upload DMG to Release
if: ${{ !inputs.dry_run && !inputs.is_pr_build }}
working-directory: platforms/macos
run: |
gh release upload ${{ env.RELEASE_VERSION }} "$DMG_NAME" --clobber
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifact (PR build)
if: ${{ inputs.is_pr_build }}
uses: actions/upload-artifact@v4
with:
name: PortKiller-PR${{ inputs.pr_number }}
path: platforms/macos/${{ env.DMG_NAME }}
retention-days: 7
- name: Dry run summary
if: ${{ inputs.dry_run && !inputs.is_pr_build }}
run: |
echo "🧪 DRY RUN - Build completed successfully!"
echo "📦 DMG created: $DMG_NAME"
echo "📏 DMG size: $(stat -f%z "$DMG_NAME") bytes"
echo "🔏 Sparkle signature: $SPARKLE_SIGNATURE"
echo ""
echo "In a real release, this DMG would be uploaded to:"
echo " https://github.com/productdevbook/port-killer/releases/download/${RELEASE_VERSION}/${DMG_NAME}"
- name: Update appcast.xml
if: ${{ !inputs.dry_run && !inputs.is_pr_build }}
run: |
VERSION="${RELEASE_VERSION#v}" # Remove 'v' prefix (v1.2.7 -> 1.2.7)
BUILD_NUMBER=$(git rev-list --count HEAD) # Same as CFBundleVersion in app
DMG_SIZE=$(stat -f%z "$DMG_NAME")
DMG_URL="https://github.com/productdevbook/port-killer/releases/download/${RELEASE_VERSION}/${DMG_NAME}"
echo "Version: $VERSION, Build: $BUILD_NUMBER"
# Create or update appcast.xml
cat > 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>PortKiller Updates</title>
<link>https://github.com/productdevbook/port-killer</link>
<description>Most recent updates to PortKiller</description>
<language>en</language>
<item>
<title>Version VERSIONPLACEHOLDER</title>
<pubDate>DATEPLACEHOLDER</pubDate>
<sparkle:version>BUILDPLACEHOLDER</sparkle:version>
<sparkle:shortVersionString>VERSIONPLACEHOLDER</sparkle:shortVersionString>
<sparkle:minimumSystemVersion>15.0</sparkle:minimumSystemVersion>
<enclosure
url="URLPLACEHOLDER"
length="SIZEPLACEHOLDER"
type="application/octet-stream"
sparkle:edSignature="SIGPLACEHOLDER" />
</item>
</channel>
</rss>
APPCAST_EOF
# Replace placeholders
sed -i '' "s|BUILDPLACEHOLDER|${BUILD_NUMBER}|g" appcast.xml
sed -i '' "s|VERSIONPLACEHOLDER|${VERSION}|g" appcast.xml
sed -i '' "s|DATEPLACEHOLDER|$(date -R)|g" appcast.xml
sed -i '' "s|URLPLACEHOLDER|${DMG_URL}|g" appcast.xml
sed -i '' "s|SIZEPLACEHOLDER|${DMG_SIZE}|g" appcast.xml
sed -i '' "s|SIGPLACEHOLDER|${SPARKLE_SIGNATURE}|g" appcast.xml
- name: Commit appcast.xml
if: ${{ !inputs.dry_run && !inputs.is_pr_build }}
working-directory: ${{ github.workspace }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout main
# Move appcast.xml to root level (SUFeedURL points to main/appcast.xml)
mv platforms/macos/appcast.xml appcast.xml
git add appcast.xml
git commit -m "chore: update appcast.xml for ${RELEASE_VERSION}" || echo "No changes to commit"
git push origin main
- name: Update Homebrew Tap
if: ${{ !inputs.dry_run && !inputs.is_pr_build }}
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
run: |
VERSION="${RELEASE_VERSION#v}"
# Get SHA256 of the Universal DMG
SHA256=$(shasum -a 256 "$DMG_NAME" | cut -d' ' -f1)
# Clone homebrew-tap repo
git clone https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/productdevbook/homebrew-tap.git /tmp/homebrew-tap
cd /tmp/homebrew-tap
# Update cask formula
cat > Casks/portkiller.rb << EOF
cask "portkiller" do
version "${VERSION}"
sha256 "${SHA256}"
url "https://github.com/productdevbook/port-killer/releases/download/v#{version}/PortKiller-v#{version}-macos.dmg"
name "PortKiller"
desc "Menu bar app to find and kill processes running on open ports"
homepage "https://github.com/productdevbook/port-killer"
depends_on macos: :sequoia
app "PortKiller.app"
zap trash: [
"~/Library/Preferences/com.productdevbook.PortKiller.plist",
"~/Library/Caches/com.productdevbook.PortKiller",
]
end
EOF
# Commit and push
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Casks/portkiller.rb
git commit -m "Update portkiller to ${VERSION}"
git push
build-windows:
name: Build Windows
needs: create-release
# Skip for PR builds (macOS only)
if: ${{ always() && !inputs.is_pr_build && (needs.create-release.result == 'success' || needs.create-release.result == 'skipped') }}
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0.x'
- name: Restore dependencies
run: dotnet restore platforms/windows/PortKiller/PortKiller.csproj
- name: Build and publish x64
run: |
dotnet publish platforms/windows/PortKiller/PortKiller.csproj `
-c Release `
-r win-x64 `
--self-contained false `
-o publish/win-x64
- name: Build and publish arm64
run: |
dotnet publish platforms/windows/PortKiller/PortKiller.csproj `
-c Release `
-r win-arm64 `
--self-contained false `
-o publish/win-arm64
- name: Create ZIP archives
run: |
$version = "${{ env.RELEASE_VERSION }}"
# Create x64 ZIP
Compress-Archive -Path publish/win-x64/* -DestinationPath "PortKiller-${version}-windows-x64.zip"
# Create arm64 ZIP
Compress-Archive -Path publish/win-arm64/* -DestinationPath "PortKiller-${version}-windows-arm64.zip"
- name: Upload to Release
if: ${{ !inputs.dry_run }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$version = "${{ env.RELEASE_VERSION }}"
gh release upload $version "PortKiller-${version}-windows-x64.zip" --clobber
gh release upload $version "PortKiller-${version}-windows-arm64.zip" --clobber