Skip to content

Commit 263fcf5

Browse files
committed
Add support for unsigned PR builds in GHA
1 parent 2f75261 commit 263fcf5

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: CI
2-
on: push
2+
on:
3+
- push
4+
- pull_request
35
jobs:
46
build:
57
name: Build & test
@@ -43,13 +45,18 @@ jobs:
4345
- run: npm ci
4446

4547
# The API key in APPLE_API_KEY is a PEM cert that must be read from disk:
46-
- run: echo "$APPLE_API_KEY" > ./apple-api-key.p8
47-
if: startsWith(matrix.os, 'macos-')
48+
- name: Prepare Apple API key
49+
run: echo "$APPLE_API_KEY" > ./apple-api-key.p8
50+
if: github.event_name == 'push' && startsWith(matrix.os, 'macos-')
4851
env:
4952
APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
5053

51-
- run: npm run build
54+
# On push we do signed builds, on PRs we do unsigned builds only (next step)
55+
- name: Run signed build
56+
if: github.event_name == 'push'
57+
run: npm run build
5258
env:
59+
ENABLE_SIGNING: true
5360
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5461
# For Mac notarization:
5562
APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
@@ -64,6 +71,14 @@ jobs:
6471
# Workaround - see FPM install step above
6572
USE_SYSTEM_FPM: ${{ matrix.platform == 'linux' && matrix.arch == 'arm64' }}
6673

74+
- name: Run unsigned build
75+
if: github.event_name != 'push'
76+
run: npm run build
77+
env:
78+
ENABLE_SIGNING: false
79+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
80+
USE_SYSTEM_FPM: ${{ matrix.platform == 'linux' && matrix.arch == 'arm64' }}
81+
6782
- uses: actions/upload-artifact@v4
6883
with:
6984
name: ${{ matrix.platform }}-${{ matrix.arch }}-distributables

electron-builder.config.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This config just re-exposes the config from package.json, but
2+
// disables code signing & notarization for PR builds where it won't work.
3+
4+
const packageJson = require('./package.json');
5+
6+
const unsignedMode = process.env.ENABLE_SIGNING !== 'true';
7+
8+
const config = packageJson.build;
9+
10+
if (unsignedMode) {
11+
console.log('\nBuilding in UNSIGNED mode\n');
12+
13+
// Make it abundantly clear in the output that the builds aren't signed, so
14+
// we don't accidentally distribute them. Different app & file names throughout.
15+
config.productName = packageJson.name + ' - dev build';
16+
config.extraMetadata.name += '-dev';
17+
config.extraMetadata.productName += '-dev';
18+
19+
config.artifactName = config.artifactName.replace('${ext}', 'dev.${ext}');
20+
for (let field in config) {
21+
if (config[field]?.artifactName) {
22+
config[field].artifactName =
23+
config[field].artifactName.replace('${ext}', 'dev.${ext}');
24+
}
25+
}
26+
27+
config.mac.forceCodeSigning = false;
28+
config.mac.notarize = false;
29+
config.win.forceCodeSigning = false;
30+
process.env.CSC_IDENTITY_AUTO_DISCOVERY = 'false';
31+
} else {
32+
console.log('\nBuilding in SIGNED mode\n');
33+
}
34+
35+
module.exports = config;

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"build": "npm run build:src && npm run build:electron",
1313
"build:src": "tsc",
1414
"postbuild:src": "tsx ./strip-preload-map.ts",
15-
"build:electron": "npm run server:setup && electron-builder build",
15+
"build:electron": "npm run server:setup && electron-builder build --config electron-builder.config.js",
1616
"build:dir-only": "npm run server:setup && electron-builder --dir",
1717
"start": "npm run server:setup && npm run start:app",
1818
"start:dev": "tsx ./skip-server.ts && cross-env HTK_DEV=true APP_URL='http://localhost:8080' npm run start:app",
@@ -77,7 +77,7 @@
7777
},
7878
"nsis": {
7979
"installerIcon": "./src/icons/icon.ico",
80-
"artifactName": "HttpToolkit-${version}.exe",
80+
"artifactName": "HttpToolkit-${version}.${ext}",
8181
"deleteAppDataOnUninstall": true,
8282
"oneClick": false,
8383
"allowToChangeInstallationDirectory": true,

0 commit comments

Comments
 (0)