Skip to content

Commit b3c77e6

Browse files
authored
update build and release workflow (#1597)
- Clean up code and fix release.yml workflow - Add zap-cli to .deb and .rpm packages via afterPack hook in Electron Builder - Include zap-cli in .zip files via afterAllArtifactsBuild hook in Electron Builder - Package ARM64 zap-cli binary for macOS ARM64 zap release
1 parent 8043f56 commit b3c77e6

File tree

10 files changed

+295
-348
lines changed

10 files changed

+295
-348
lines changed

.github/workflows/matter.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ jobs:
8989
- name: Build & Release for Linux
9090
if: startsWith(matrix.os, 'ubuntu')
9191
run: |
92-
npm run pack:linux
93-
npm run pkg:linux
94-
ls ./dist/
95-
npm run pack:cli:linux
92+
node src-script/build-release-package.js --platform l
9693
9794
mv dist/zap-linux-amd64.deb dist/zap-linux-x64.deb
9895
mv dist/zap-linux-x86_64.rpm dist/zap-linux-x64.rpm

.github/workflows/release.yml

Lines changed: 163 additions & 181 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,11 @@
106106
"pack:win": "cross-env NODE_OPTIONS=--max-old-space-size=4096 electron-builder -w",
107107
"pack:mac": "cross-env NODE_OPTIONS=--max-old-space-size=4096 electron-builder -m",
108108
"pack:mac:native": "cross-env NODE_OPTIONS=--max-old-space-size=4096 electron-builder -m",
109-
"pack:cli:linux": "node ./src-script/pack-cli.js -p linux",
110-
"pack:cli:win": "node ./src-script/pack-cli.js -p win",
111-
"pack:cli:mac": "node ./src-script/pack-cli.js -p mac",
112109
"pkg": "npx pkg --out-path dist/ --compress GZip --options max-old-space-size=4096 .",
113110
"pkg:linux": "npx pkg -t node18-linux-x64,node18-linux-arm64 --public --no-bytecode --output dist/zap-linux --compress GZip --options max-old-space-size=4096 .",
114111
"pkg-use-local-fork": "node ../pkg/lib-es5/bin.js -t node18-linux-x64 --output dist/zap-linux --compress GZip --options max-old-space-size=4096 .",
115112
"pkg:win": "npx pkg -t node18-win-x64,node18-win-arm64 --public --no-bytecode --output dist/zap-win --compress GZip --options max-old-space-size=4096 .",
116-
"pkg:mac": "npx pkg -t node18-macos-x64 --output dist/zap-macos --compress GZip --options max-old-space-size=4096 .",
113+
"pkg:mac": "npx pkg -t node18-macos-x64,node18-macos-arm64 --output dist/zap-macos --compress GZip --options max-old-space-size=4096 .",
117114
"dist": "node src-script/build-release-package.js --output dist/release",
118115
"dist:mac": "node src-script/build-release-package.js --platform m --output dist/release",
119116
"dist:win": "node src-script/build-release-package.js --platform w --output dist/release",
@@ -225,8 +222,8 @@
225222
"build": {
226223
"appId": "zap.id",
227224
"artifactName": "${productName}-${os}-${arch}.${ext}",
228-
"afterPack": "./src-script/pack-apack-win-linux.js",
229-
"afterAllArtifactBuild": "./src-script/pack-apack-mac.js",
225+
"afterPack": "./src-script/after-pack-linux.js",
226+
"afterAllArtifactBuild": "./src-script/after-all-artifacts.js",
230227
"mac": {
231228
"category": "public.app-category.developer-tools",
232229
"darkModeSupport": true,

src-script/after-all-artifacts.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* This script runs after all artifacts are built by Electron Builder.
3+
* It adds additional files (e.g., apack.json, zap.png, zap-cli) to the final
4+
* .zip artifacts for macOS, Windows, and Linux platforms.
5+
*/
6+
const fs = require('fs')
7+
const path = require('path')
8+
const Seven = require('node-7z')
9+
const sevenBin = require('7zip-bin')
10+
const pathTo7zip = sevenBin.path7za
11+
12+
exports.default = async function (buildResult) {
13+
const zipFiles = buildResult?.artifactPaths || []
14+
15+
for (const zipPath of zipFiles) {
16+
if (!zipPath.endsWith('.zip')) continue
17+
if (
18+
!(
19+
zipPath.includes('mac') ||
20+
zipPath.includes('win') ||
21+
zipPath.includes('linux')
22+
)
23+
)
24+
continue
25+
26+
const additions = [
27+
path.join(buildResult.outDir, '../apack.json'),
28+
path.join(buildResult.outDir, '../src/assets/zap.png')
29+
]
30+
31+
// Detect platform and arch from filename
32+
const platform = zipPath.includes('mac')
33+
? 'macos'
34+
: zipPath.includes('linux')
35+
? 'linux'
36+
: zipPath.includes('win')
37+
? 'win'
38+
: null
39+
40+
const arch = zipPath.includes('arm64') ? 'arm64' : 'x64'
41+
42+
if (!platform) continue
43+
44+
// Compose zap-cli binary name
45+
const cliName =
46+
platform === 'win' ? `zap-win-${arch}.exe` : `zap-${platform}-${arch}`
47+
48+
const cliPath = path.join(buildResult.outDir, '../dist', cliName)
49+
50+
if (fs.existsSync(cliPath)) {
51+
const tempName = platform === 'win' ? 'zap-cli.exe' : 'zap-cli'
52+
const tempPath = path.join(__dirname, tempName)
53+
54+
// Copy to temp with desired name
55+
fs.copyFileSync(cliPath, tempPath)
56+
57+
additions.push(tempPath)
58+
59+
// Clean up after zip
60+
process.on('exit', () => {
61+
if (fs.existsSync(tempPath)) fs.unlinkSync(tempPath)
62+
})
63+
} else {
64+
console.warn(`⚠️ zap-cli not found for ${platform}-${arch}: ${cliPath}`)
65+
}
66+
67+
// Add files to zip
68+
for (const filePath of additions) {
69+
await new Promise((resolve, reject) => {
70+
const stream = Seven.add(zipPath, filePath, {
71+
$bin: pathTo7zip,
72+
$progress: true
73+
})
74+
stream.on('end', resolve)
75+
stream.on('error', (err) => {
76+
console.error(`❌ Error adding ${filePath}:`, err.stderr || err)
77+
reject(err)
78+
})
79+
})
80+
81+
console.log(
82+
`✅ Added ${path.basename(filePath)} to ${path.basename(zipPath)}`
83+
)
84+
}
85+
}
86+
}

src-script/after-pack-linux.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* after-pack-linux-assets.js
3+
* Adds zap-cli, apack.json, and zap.png to Linux app output before .deb/.rpm packaging.
4+
*/
5+
const scriptUtil = require('./script-util.js')
6+
const path = require('path')
7+
const fs = require('fs')
8+
9+
exports.default = async function (context) {
10+
const { electronPlatformName, appOutDir, outDir, arch } = context
11+
12+
if (electronPlatformName === 'linux') {
13+
// 1. Copy apack.json and zap.png
14+
await scriptUtil.executeCmd({}, 'npx', [
15+
'copyfiles',
16+
'-V',
17+
'-f',
18+
path.resolve(outDir, '../apack.json'),
19+
path.resolve(outDir, '../src/assets/zap.png'),
20+
appOutDir
21+
])
22+
console.log('✅ apack.json and zap.png copied to Linux appOutDir')
23+
24+
// 2. Copy zap-cli for correct arch
25+
const archName = arch === 3 ? 'arm64' : 'x64' // arch === 3 => arm64, else x64
26+
const cliSource = path.resolve(outDir, `../dist/zap-linux-${archName}`)
27+
const cliDest = path.join(appOutDir, 'zap-cli')
28+
29+
if (!fs.existsSync(cliSource)) {
30+
throw new Error(`❌ zap-cli binary not found at ${cliSource}`)
31+
}
32+
33+
fs.copyFileSync(cliSource, cliDest)
34+
fs.chmodSync(cliDest, 0o755)
35+
36+
console.log(`✅ zap-cli (${archName}) copied to ${cliDest}`)
37+
}
38+
}

src-script/build-release-package.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ async function buildForOS(osName, outputPath) {
3232
switch (osName) {
3333
case 'm':
3434
console.log(`Building for Mac... Output: ${outputPath}`)
35-
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:mac']) // Building electron app
3635
await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:mac']) // Building zap-cli
37-
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:cli:mac']) // Adding zap-cli to zip file
36+
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:mac']) // Building electron app
3837
if (outputPath) {
3938
await scriptUtil.executeCmd({}, 'mv', [
4039
'./dist/zap-mac-x64.zip',
@@ -49,9 +48,8 @@ async function buildForOS(osName, outputPath) {
4948

5049
case 'w':
5150
console.log(`Building for Windows... Output: ${outputPath}`)
52-
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:win']) // Building electron app
5351
await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:win']) // Building zap-cli
54-
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:cli:win']) // Adding zap-cli to zip file
52+
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:win']) // Building electron app
5553
if (outputPath) {
5654
await scriptUtil.executeCmd({}, 'mv', [
5755
'dist/zap-win-x64.zip',
@@ -66,9 +64,8 @@ async function buildForOS(osName, outputPath) {
6664

6765
case 'l':
6866
console.log(`Building for Linux... Output: ${outputPath}`)
69-
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:linux']) // Building electron app
7067
await scriptUtil.executeCmd({}, 'npm', ['run', 'pkg:linux']) // Building zap-cli
71-
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:cli:linux']) // Adding zap-cli to zip file
68+
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:linux']) // Building electron app
7269
if (outputPath) {
7370
await scriptUtil.executeCmd({}, 'mv', [
7471
'dist/zap-linux-x64.zip',

src-script/install-packages-ubuntu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# to get source build to compile via npm install or npm ci
55
#
66
apt-get update
7-
apt-get install -y --fix-missing libpixman-1-dev libcairo-dev libsdl-pango-dev libjpeg-dev libgif-dev
7+
apt-get install -y --fix-missing libpixman-1-dev libcairo-dev libsdl-pango-dev libjpeg-dev libgif-dev rpm

src-script/pack-apack-mac.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

src-script/pack-apack-win-linux.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

src-script/pack-cli.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)