-
Notifications
You must be signed in to change notification settings - Fork 78
336 lines (294 loc) · 11.5 KB
/
Copy pathci.yml
File metadata and controls
336 lines (294 loc) · 11.5 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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
should_release:
description: Build, sign, and publish a draft release
required: true
type: boolean
default: false
permissions:
contents: read
concurrency:
group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
validation:
name: Validate (${{ matrix.check.name }})
runs-on: ${{ matrix.check.runner }}
strategy:
fail-fast: false
matrix:
check:
- name: Lint
command: npm run lint
runner: ubuntu-latest
- name: Storybook
command: npm run build-storybook
runner: ubuntu-latest
- name: Tests
command: npm test
runner: windows-latest
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
cache: 'npm'
- name: Cache node_modules and native builds
uses: actions/cache@v5
id: cache-deps
with:
path: |
node_modules
.vite
**/node_modules
**/*.node
**/build/Release
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/binding.gyp', '**/node_modules/**/*.node') }}
restore-keys: |
${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-
${{ runner.os }}-node-
- name: Install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: npm ci
- name: Run ${{ matrix.check.name }}
run: ${{ matrix.check.command }}
- name: Upload coverage report
if: matrix.check.name == 'Tests'
uses: actions/upload-artifact@v7
with:
name: coverage-report
path: coverage
build:
name: build
needs: validation
if: always()
runs-on: ubuntu-latest
steps:
- name: Confirm validation passed
env:
VALIDATION_RESULT: ${{ needs.validation.result }}
run: |
if [[ "$VALIDATION_RESULT" != "success" ]]; then
echo "Validation result: $VALIDATION_RESULT" >&2
exit 1
fi
release-gate:
name: Determine release eligibility
if: github.event_name == 'push' || inputs.should_release
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.gate.outputs.should_release }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 2 # Fetch the last 2 commits to compare versions
persist-credentials: false
- name: Check release conditions
id: gate
shell: bash
env:
DISPATCH_SHOULD_RELEASE: ${{ inputs.should_release }}
run: |
set -euo pipefail
if [[ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]]; then
echo "should_release=$DISPATCH_SHOULD_RELEASE" >> "$GITHUB_OUTPUT"
exit 0
fi
currentVersion=$(node -p "require('./package.json').version")
previousVersion=$(git show HEAD^:package.json | node -e \
"let input = ''; process.stdin.on('data', chunk => input += chunk); process.stdin.on('end', () => console.log(JSON.parse(input).version));")
if [[ -z "$currentVersion" || -z "$previousVersion" ]]; then
echo "Could not determine current and previous package versions." >&2
exit 1
fi
if [[ "$currentVersion" != "$previousVersion" ]]; then
echo "should_release=true" >> "$GITHUB_OUTPUT"
echo "Version changed from $previousVersion to $currentVersion"
else
echo "should_release=false" >> "$GITHUB_OUTPUT"
fi
release:
name: Build and publish signed release
needs: [build, release-gate]
if: needs.release-gate.outputs.should_release == 'true'
runs-on: windows-latest
permissions:
actions: read
contents: write
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
cache: 'npm'
- name: Cache node_modules and native builds
uses: actions/cache@v5
id: cache-deps
with:
path: |
node_modules
.vite
**/node_modules
**/*.node
**/build/Release
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/binding.gyp', '**/node_modules/**/*.node') }}
restore-keys: |
${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}-
${{ runner.os }}-node-
- name: Install dependencies
if: steps.cache-deps.outputs.cache-hit != 'true'
run: npm ci
# --- Signed release ----------------------------------------------------
# Pushes release only when the version changes. Manual runs release only
# when the should_release workflow-dispatch input is enabled. Pull
# requests never enter this flow.
# Flow: package once -> sign the packaged application via SignPath -> make
# Squirrel artifacts once while saving a publish dry-run -> sign Setup.exe
# via SignPath -> publish from the saved dry-run.
# The dry-run manifest stores paths to out/make/... (no content hashing), so
# replacing Setup.exe is picked up by --from-dry-run. Making all Squirrel
# artifacts together keeps RELEASES and the .nupkg checksums consistent for
# auto-updates.
- name: Package unsigned Windows application
run: npx electron-forge package
env:
POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }}
- name: Archive packaged Windows application
shell: pwsh
run: |
$packageDirectory = 'out/irdashies-win32-x64'
if (-not (Test-Path -LiteralPath $packageDirectory -PathType Container)) {
throw "Packaged application not found: $packageDirectory"
}
Compress-Archive `
-Path "$packageDirectory/*" `
-DestinationPath packaged-windows-app.zip `
-CompressionLevel Optimal
- name: Upload packaged application for signing
id: upload-packaged-app
uses: actions/upload-artifact@v7
with:
name: unsigned-packaged-windows-app
if-no-files-found: error
path: packaged-windows-app.zip
- name: Sign packaged application
uses: signpath/github-action-submit-signing-request@v2
with:
api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
organization-id: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
project-slug: irdashies
signing-policy-slug: release-signing
artifact-configuration-slug: packaged-app
github-artifact-id: ${{ steps.upload-packaged-app.outputs.artifact-id }}
wait-for-completion: true
output-artifact-directory: signed-packaged-app
- name: Restore and verify signed packaged application
shell: pwsh
run: |
$signedArchive = Get-ChildItem `
-LiteralPath signed-packaged-app `
-Filter '*.zip' `
-File `
-Recurse |
Select-Object -First 1
if (-not $signedArchive) {
throw 'SignPath did not return the signed packaged application ZIP.'
}
Expand-Archive `
-LiteralPath $signedArchive.FullName `
-DestinationPath out/irdashies-win32-x64 `
-Force
$appExecutable = 'out/irdashies-win32-x64/irdashies.exe'
$signature = Get-AuthenticodeSignature -LiteralPath $appExecutable
if ($signature.Status -ne 'Valid') {
throw "Packaged application signature is $($signature.Status): $($signature.StatusMessage)"
}
Write-Output "Verified signed packaged application: $($signature.SignerCertificate.Subject)"
- name: Build Squirrel artifacts from signed application
run: node tools/publish-signed-dry-run.mjs
- name: Verify signed application in Squirrel package
shell: pwsh
run: |
if (-not (Test-Path -LiteralPath out/publish-dry-run -PathType Container)) {
throw 'Electron Forge publish dry-run state was not generated.'
}
$package = Get-ChildItem `
-Path out/make/squirrel.windows/x64 `
-Filter '*.nupkg' `
-File |
Where-Object { $_.Name -notlike '*-delta.nupkg' } |
Select-Object -First 1
if (-not $package) {
throw 'Squirrel full package was not generated.'
}
$extractDirectory = Join-Path $env:RUNNER_TEMP 'irdashies-nupkg'
New-Item -ItemType Directory -Path $extractDirectory -Force | Out-Null
$packageArchive = Join-Path $env:RUNNER_TEMP 'irdashies-nupkg.zip'
Copy-Item -LiteralPath $package.FullName -Destination $packageArchive -Force
Expand-Archive `
-LiteralPath $packageArchive `
-DestinationPath $extractDirectory `
-Force
$packagedExecutable = Get-ChildItem `
-LiteralPath $extractDirectory `
-Recurse `
-Filter 'irdashies.exe' `
-File |
Select-Object -First 1
if (-not $packagedExecutable) {
throw 'irdashies.exe was not found in the Squirrel package.'
}
$signature = Get-AuthenticodeSignature `
-LiteralPath $packagedExecutable.FullName
if ($signature.Status -ne 'Valid') {
throw "Squirrel package contains an application with signature status $($signature.Status)."
}
Write-Output "Verified signed application in $($package.Name)."
- name: Upload unsigned installer for signing
id: upload-unsigned
uses: actions/upload-artifact@v7
with:
name: unsigned-installer
if-no-files-found: error
path: out/make/squirrel.windows/x64/*Setup.exe
- name: Sign installer with SignPath
uses: signpath/github-action-submit-signing-request@v2
with:
api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
organization-id: ${{ vars.SIGNPATH_ORGANIZATION_ID }}
project-slug: irdashies
signing-policy-slug: release-signing
artifact-configuration-slug: initial
github-artifact-id: ${{ steps.upload-unsigned.outputs.artifact-id }}
wait-for-completion: true
output-artifact-directory: signed-installer
- name: Swap in the signed installer
shell: pwsh
run: |
Copy-Item signed-installer/*Setup.exe out/make/squirrel.windows/x64/ -Force
$installer = Get-ChildItem `
-Path out/make/squirrel.windows/x64 `
-Filter '*Setup.exe' `
-File |
Select-Object -First 1
$signature = Get-AuthenticodeSignature -LiteralPath $installer.FullName
if ($signature.Status -ne 'Valid') {
throw "Installer signature is $($signature.Status): $($signature.StatusMessage)"
}
Write-Output "Verified signed installer: $($signature.SignerCertificate.Subject)"
- name: Publish signed release
run: npx electron-forge publish --from-dry-run
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}