-
Notifications
You must be signed in to change notification settings - Fork 12
190 lines (173 loc) · 6.69 KB
/
build_macos.yml
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
name: "macOS Build"
on:
workflow_call:
secrets:
APPLE_ID:
required: true
APPLE_PASSWORD:
required: true
APPLE_TEAM_ID:
required: true
APPLE_CERTIFICATE:
required: true
APPLE_CERTIFICATE_PASSWORD:
required: true
KEYCHAIN_PASSWORD:
required: true
push:
branches:
- master
paths:
- 'src-tauri/**'
- 'src/**'
- 'static/**'
- 'package.json'
- 'bun.lockb'
- 'svelte.config.js'
- 'tailwind.config.js'
- 'vite.config.js'
- '.github/workflows/build_macos.yml'
pull_request:
paths:
- 'src-tauri/**'
- 'src/**'
- 'static/**'
- 'package.json'
- 'bun.lockb'
- 'svelte.config.js'
- 'tailwind.config.js'
- 'vite.config.js'
- '.github/workflows/build_macos.yml'
jobs:
setup:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Get version from Cargo.toml
id: get-version
run: |
VERSION=$(grep '^version[[:space:]]*=[[:space:]]*"' src-tauri/Cargo.toml | sed 's/^version[[:space:]]*=[[:space:]]*"\(.*\)"/\1/')
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
build-macos:
needs: setup
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
include:
- arch: "aarch64"
target: "aarch64-apple-darwin"
- arch: "x86_64"
target: "x86_64-apple-darwin"
env:
VERSION: ${{ needs.setup.outputs.version }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
CARGO_INCREMENTAL: 0 # Disable incremental compilation for CI
RUST_BACKTRACE: 1 # Better error reporting
MACOSX_DEPLOYMENT_TARGET: "10.15" # Set minimum macOS version
steps:
- uses: actions/checkout@v4
- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.39
- name: Cache frontend dependencies
uses: actions/cache@v4
id: cache-frontend-deps
with:
path: |
~/.bun/install/cache
node_modules
key: frontend-deps-macos-${{ matrix.arch }}-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
frontend-deps-macos-${{ matrix.arch }}-
- name: Install frontend dependencies
if: steps.cache-frontend-deps.outputs.cache-hit != 'true'
run: bun install
- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: rust-deps-macos-${{ matrix.arch }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
rust-deps-macos-${{ matrix.arch }}-
- name: Add Rust build cache
uses: Swatinem/rust-cache@v2
with:
workspaces: "src-tauri -> target"
key: macos-${{ matrix.arch }}-rust-${{ hashFiles('**/Cargo.lock') }}
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-apple-darwin,x86_64-apple-darwin
- name: Import Apple Developer Certificate
id: import_apple_certificate
env:
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }}
run: |
echo $APPLE_CERTIFICATE | base64 --decode > certificate.p12
security create-keychain -p "$KEYCHAIN_PASSWORD" build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p "$KEYCHAIN_PASSWORD" build.keychain
security import certificate.p12 -k build.keychain -P "$APPLE_CERTIFICATE_PASSWORD" -T /usr/bin/codesign
security set-keychain-settings -t 3600 -l build.keychain
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$KEYCHAIN_PASSWORD" build.keychain
security list-keychains -s build.keychain
- name: Verify Certificate
id: verify_apple_certificate
run: |
security find-identity -v -p codesigning build.keychain
CERT_INFO=$(security find-identity -v -p codesigning build.keychain | grep "Developer ID Application")
CERT_ID=$(echo "$CERT_INFO" | awk -F'"' '{print $2}')
echo "cert_id=$CERT_ID" >> "$GITHUB_OUTPUT"
echo "Apple Developer Certificate imported."
- name: Build macOS Desktop App
uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
APPLE_SIGNING_IDENTITY: 'Developer ID Application'
with:
args: --target ${{ matrix.target }}
- name: Generate macOS artifact hashes
run: |
cd src-tauri/target/${{ matrix.arch }}-apple-darwin/release/bundle
cd macos
find . -type f -name "*.app" -exec sh -c '
FILE="$1"
shasum -a 256 "$FILE" | sed "s| .*| whitenoise-${VERSION}-macos-${{ matrix.arch }}.app|" > "${FILE}.sha256"
' sh {} \;
find . -type f -name "*.app.tar.gz" -exec sh -c '
FILE="$1"
shasum -a 256 "$FILE" | sed "s| .*| whitenoise-${VERSION}-macos-${{ matrix.arch }}.app.tar.gz|" > "${FILE}.sha256"
' sh {} \;
cd ../dmg
find . -type f -name "*.dmg" -exec sh -c '
FILE="$1"
shasum -a 256 "$FILE" | sed "s| .*| whitenoise-${VERSION}-macos-${{ matrix.arch }}.dmg|" > "${FILE}.sha256"
' sh {} \;
- name: Prepare macOS artifacts
run: |
mkdir -p desktop-artifacts
find src-tauri/target/${{ matrix.arch }}-apple-darwin/release/bundle/dmg -name "*.dmg" -exec sh -c '
cp "$1" desktop-artifacts/whitenoise-${VERSION}-macos-${{ matrix.arch }}.dmg
cp "${1}.sha256" desktop-artifacts/whitenoise-${VERSION}-macos-${{ matrix.arch }}.dmg.sha256
' sh {} \;
find src-tauri/target/${{ matrix.arch }}-apple-darwin/release/bundle/macos -name "*.app.tar.gz" -exec sh -c '
cp "$1" desktop-artifacts/whitenoise-${VERSION}-macos-${{ matrix.arch }}.app.tar.gz
cp "${1}.sha256" desktop-artifacts/whitenoise-${VERSION}-macos-${{ matrix.arch }}.app.tar.gz.sha256
' sh {} \;
- name: Upload macOS artifacts
uses: actions/upload-artifact@v4
with:
name: macos-${{ matrix.arch }}
path: desktop-artifacts/*