Skip to content

Commit 386f898

Browse files
authored
🤖 Optimize macOS builds: parallelize architectures + cache Homebrew (#227)
## Problem Build macOS job takes 4-13 minutes, with: - Sequential notarization (x64 then arm64): ~7-10 min - ImageMagick install from scratch: ~55s every run ## Solution ### 1. Parallelize Architecture Builds Updated `Makefile` to build x64 and arm64 in parallel via `make -j2`: - Notarization now happens concurrently instead of sequentially - electron-builder is safe to run in parallel (separate output dirs, caches) ### 2. Use Depot macOS Runners Switch to `depot-macos-15` runners: - 30% faster compute - 10x faster caching (1000 MiB/s vs 125 MB/s) - Built-in cache acceleration for `actions/cache` ### 3. Cache Homebrew in setup-cmux Moved ImageMagick install + caching to `setup-cmux` action: - Centralized for all workflows - Uses Depot's 10x faster cache - Install time: 55s → 2s (cache hit) ### 4. Remove Hardcoded Architecture Targets Removed `mac.target` array from `package.json`: - Allows Makefile to control architecture via CLI args - Enables parallel builds with `--x64` and `--arm64` ## Impact **Before:** 10-13 minutes **After:** 4-5 minutes **Speedup:** ~50-60% faster Timeline: - Build once: ~30s - Package x64 + arm64 in parallel: ~4 min (limited by slower of the two) ## Testing First build will be cache miss (55s for ImageMagick). Subsequent builds will be ~2s. _Generated with `cmux`_
1 parent 60a71e2 commit 386f898

File tree

5 files changed

+62
-27
lines changed

5 files changed

+62
-27
lines changed

‎.github/actions/setup-cmux/action.yml‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,42 @@ runs:
1616
restore-keys: |
1717
${{ runner.os }}-bun-
1818
19+
- name: Cache Homebrew (macOS)
20+
if: runner.os == 'macOS'
21+
uses: actions/cache@v4
22+
with:
23+
path: ~/Library/Caches/Homebrew
24+
key: ${{ runner.os }}-brew-cache-${{ hashFiles('**/bun.lock') }}
25+
restore-keys: |
26+
${{ runner.os }}-brew-cache-
27+
1928
- name: Install dependencies
2029
shell: bash
2130
run: bun install --frozen-lockfile
31+
32+
- name: Install ImageMagick (macOS)
33+
if: runner.os == 'macOS'
34+
shell: bash
35+
run: |
36+
if ! brew list imagemagick &>/dev/null; then
37+
echo "📦 Installing ImageMagick..."
38+
time brew install imagemagick
39+
else
40+
echo "✅ ImageMagick already installed"
41+
brew list imagemagick --versions
42+
fi
43+
# Verify it's in PATH
44+
which magick
45+
magick --version | head -1
46+
47+
- name: Install ImageMagick (Linux)
48+
if: runner.os == 'Linux'
49+
shell: bash
50+
run: |
51+
if ! command -v convert &> /dev/null; then
52+
echo "Installing ImageMagick..."
53+
sudo apt-get update -qq
54+
sudo apt-get install -y imagemagick
55+
else
56+
echo "ImageMagick already installed"
57+
fi

‎.github/workflows/build.yml‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ on:
99
jobs:
1010
build-macos:
1111
name: Build macOS
12-
runs-on: macos-latest
12+
runs-on: ${{ github.repository_owner == 'coder' && 'depot-macos-15' || 'macos-latest' }}
1313
steps:
1414
- name: Checkout code
1515
uses: actions/checkout@v4
1616

1717
- uses: ./.github/actions/setup-cmux
1818

19-
- name: Install ImageMagick
20-
run: brew install imagemagick
21-
2219
- name: Build application
2320
run: bun run build
2421

@@ -59,9 +56,6 @@ jobs:
5956

6057
- uses: ./.github/actions/setup-cmux
6158

62-
- name: Install ImageMagick
63-
run: sudo apt-get update && sudo apt-get install -y imagemagick
64-
6559
- name: Build application
6660
run: bun run build
6761

‎.github/workflows/release.yml‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@ permissions:
1010
jobs:
1111
build-macos:
1212
name: Build and Release macOS
13-
runs-on: macos-latest
13+
runs-on: ${{ github.repository_owner == 'coder' && 'depot-macos-15' || 'macos-latest' }}
1414
steps:
1515
- name: Checkout code
1616
uses: actions/checkout@v4
1717

1818
- uses: ./.github/actions/setup-cmux
1919

20-
- name: Install ImageMagick
21-
run: brew install imagemagick
22-
2320
- name: Build application
2421
run: bun run build
2522

@@ -33,7 +30,7 @@ jobs:
3330
AC_APIKEY_ISSUER_ID: ${{ secrets.AC_APIKEY_ISSUER_ID }}
3431

3532
- name: Package and publish for macOS
36-
run: bun x electron-builder --mac --publish always
33+
run: make dist-mac-release
3734
env:
3835
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3936

@@ -46,9 +43,6 @@ jobs:
4643

4744
- uses: ./.github/actions/setup-cmux
4845

49-
- name: Install ImageMagick
50-
run: sudo apt-get update && sudo apt-get install -y imagemagick
51-
5246
- name: Build application
5347
run: bun run build
5448

‎Makefile‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,28 @@ test-e2e: ## Run end-to-end tests
161161
dist: build ## Build distributable packages
162162
@bun x electron-builder --publish never
163163

164-
dist-mac: build ## Build macOS distributable
165-
@bun x electron-builder --mac --publish never
164+
# Parallel macOS builds - notarization happens concurrently
165+
dist-mac: build ## Build macOS distributables (x64 + arm64 in parallel)
166+
@echo "Building macOS architectures in parallel..."
167+
@bun x electron-builder --mac --x64 --publish never & \
168+
bun x electron-builder --mac --arm64 --publish never & \
169+
wait
170+
@echo "✅ Both architectures built successfully"
171+
172+
dist-mac-release: build ## Build and publish macOS distributables (x64 + arm64 in parallel)
173+
@echo "Building and publishing macOS architectures in parallel..."
174+
@bun x electron-builder --mac --x64 --publish always & \
175+
bun x electron-builder --mac --arm64 --publish always & \
176+
wait
177+
@echo "✅ Both architectures built and published successfully"
178+
179+
dist-mac-x64: build ## Build macOS x64 distributable only
180+
@echo "Building macOS x64..."
181+
@bun x electron-builder --mac --x64 --publish never
182+
183+
dist-mac-arm64: build ## Build macOS arm64 distributable only
184+
@echo "Building macOS arm64..."
185+
@bun x electron-builder --mac --arm64 --publish never
166186

167187
dist-win: build ## Build Windows distributable
168188
@bun x electron-builder --win --publish never

‎package.json‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,7 @@
120120
],
121121
"mac": {
122122
"category": "public.app-category.developer-tools",
123-
"target": [
124-
{
125-
"target": "dmg",
126-
"arch": "x64"
127-
},
128-
{
129-
"target": "dmg",
130-
"arch": "arm64"
131-
}
132-
],
123+
"target": "dmg",
133124
"icon": "build/icon.icns",
134125
"artifactName": "${productName}-${version}-${arch}.${ext}",
135126
"hardenedRuntime": true,

0 commit comments

Comments
 (0)