Skip to content

Commit 2e03156

Browse files
authored
ZAPP-1183 (#1444)
* added clean script to build release packages * script can be used in CI and locally * modified instructions to build binaries locally * modified release workflow to use build-release-package.js script
1 parent ce55106 commit 2e03156

File tree

4 files changed

+166
-26
lines changed

4 files changed

+166
-26
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,9 @@ jobs:
210210
- name: Build & Release for Windows / Mac universal binary on macOS
211211
if: startsWith(matrix.os, 'macos')
212212
run: |
213-
npm run pack:win
214-
npm run pkg:win
215-
ls ./dist/
216-
npm run pack:cli:win
213+
node src-script/build-release-package.js --platform w
217214
218-
npm run pack:mac
219-
npm run pkg:mac
220-
ls ./dist/
221-
npm run pack:cli:mac
215+
node src-script/build-release-package.js --platform m
222216
223217
env:
224218
GH_TOKEN: ${{ secrets.github_token }}
@@ -230,10 +224,7 @@ jobs:
230224
- name: Build & Release for Linux
231225
if: startsWith(matrix.os, 'ubuntu')
232226
run: |
233-
npm run pack:linux
234-
npm run pkg:linux
235-
ls ./dist/
236-
npm run pack:cli:linux
227+
node src-script/build-release-package.js --platform l
237228
238229
mv dist/zap-linux-amd64.deb dist/zap-linux-x64.deb
239230
mv dist/zap-linux-x86_64.rpm dist/zap-linux-x64.rpm

docs/development-instructions.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,26 +99,27 @@ npm run apidoc
9999

100100
See [Configuring quasar.conf.js](https://quasar.dev/quasar-cli/quasar-conf-js).
101101

102+
**Building Release Packages locally**
103+
102104
**Build & Release for Windows / Mac universal binary on macOS:**
103105

104-
```npm run pack:win
105-
npm run pkg:win
106-
ls ./dist/
107-
npm run pack:cli:win
106+
```
107+
npm run dist:win \\ Windows
108108
109-
npm run pack:mac
110-
npm run pkg:mac
111-
ls ./dist/
112-
npm run pack:cli:mac
109+
npm run dist:mac \\ Mac
113110
```
114111

115112
**Build & Release for Linux:**
116113

117-
```npm run pack:linux
118-
npm run pkg:linux
119-
ls ./dist/
120-
npm run pack:cli:linux
114+
```
115+
npm run dist:linux
116+
```
117+
118+
Running the following will detect and build for the os user's machine is on.
119+
120+
```
121+
npm run dist
121122
122-
mv dist/zap-linux-amd64.deb dist/zap-linux-x64.deb
123-
mv dist/zap-linux-x86_64.rpm dist/zap-linux-x64.rpm
124123
```
124+
125+
All release packages built will be found at `dist/release` and any other files from the build process will be found at `dist`.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@
114114
"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 .",
115115
"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 .",
116116
"pkg:mac": "npx pkg -t node18-macos-x64 --output dist/zap-macos --compress GZip --options max-old-space-size=4096 .",
117+
"dist": "node src-script/build-release-package.js --output dist/release",
118+
"dist:mac": "node src-script/build-release-package.js --platform m --output dist/release",
119+
"dist:win": "node src-script/build-release-package.js --platform w --output dist/release",
120+
"dist:linux": "node src-script/build-release-package.js --platform l --output dist/release",
121+
"dist:all": "node src-script/build-release-package.js --platform mwl --output dist/release",
117122
"mattersdk": "node src-script/zap-start.js regenerateSdk --sdk ~/git/matter/scripts/tools/sdk.json",
118123
"metasdk": "node src-script/zap-start.js regenerateSdk --sdk test/resource/meta/sdk.json",
119124
"zip": "node ./src-script/7zip-bin-wrapper.js"
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/usr/bin/env node
2+
/**
3+
*
4+
* Copyright (c) 2023 Silicon Labs
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
const scriptUtil = require('./script-util.js')
20+
const os = require('os')
21+
const path = require('path')
22+
const fs = require('fs')
23+
const yargs = require('yargs/yargs')
24+
const { hideBin } = require('yargs/helpers')
25+
26+
/**
27+
*
28+
* @param {*} osName
29+
* @param {*} outputPath
30+
*/
31+
async function buildForOS(osName, outputPath) {
32+
switch (osName) {
33+
case 'm':
34+
console.log(`Building for Mac... Output: ${outputPath}`)
35+
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:mac']) // Building electron app
36+
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
38+
if (outputPath) {
39+
await scriptUtil.executeCmd({}, 'mv', [
40+
'./dist/zap-mac-x64.zip',
41+
path.join(outputPath, 'zap-mac-x64.zip')
42+
])
43+
await scriptUtil.executeCmd({}, 'mv', [
44+
'./dist/zap-mac-arm64.zip',
45+
path.join(outputPath, 'zap-mac-arm64.zip')
46+
])
47+
}
48+
break
49+
50+
case 'w':
51+
console.log(`Building for Windows... Output: ${outputPath}`)
52+
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:win']) // Building electron app
53+
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
55+
if (outputPath) {
56+
await scriptUtil.executeCmd({}, 'mv', [
57+
'dist/zap-win-x64.zip',
58+
path.join(outputPath, 'zap-win-x64.zip')
59+
])
60+
await scriptUtil.executeCmd({}, 'mv', [
61+
'dist/zap-win-arm64.zip',
62+
path.join(outputPath, 'zap-win-arm64.zip')
63+
])
64+
}
65+
break
66+
67+
case 'l':
68+
console.log(`Building for Linux... Output: ${outputPath}`)
69+
await scriptUtil.executeCmd({}, 'npm', ['run', 'pack:linux']) // Building electron app
70+
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
72+
if (outputPath) {
73+
await scriptUtil.executeCmd({}, 'mv', [
74+
'dist/zap-linux-x64.zip',
75+
path.join(outputPath, 'zap-linux-x64.zip')
76+
])
77+
await scriptUtil.executeCmd({}, 'mv', [
78+
'dist/zap-linux-arm64.zip',
79+
path.join(outputPath, 'zap-linux-arm64.zip')
80+
])
81+
await scriptUtil.executeCmd({}, 'mv', [
82+
'dist/zap-linux-amd64.deb',
83+
path.join(outputPath, 'zap-linux-amd64.deb')
84+
])
85+
await scriptUtil.executeCmd({}, 'mv', [
86+
'dist/zap-linux-x64_64.rpm',
87+
path.join(outputPath, 'zap-linux-x64_64.rpm')
88+
])
89+
}
90+
break
91+
92+
default:
93+
console.error(`Error: Unsupported platform: ${osName}`)
94+
process.exit(1)
95+
}
96+
}
97+
98+
const argv = yargs(hideBin(process.argv))
99+
.option('platform', {
100+
alias: 'p',
101+
type: 'string',
102+
description: 'Specify the platform(s) to build for (m, w, l)'
103+
})
104+
.option('output', {
105+
alias: 'o',
106+
type: 'string',
107+
description: 'Specify the output directory for the build files'
108+
})
109+
.help()
110+
.strict().argv
111+
112+
let targets = argv.platform
113+
let outputPath = argv.output
114+
115+
if (outputPath && !fs.existsSync(outputPath)) {
116+
fs.mkdirSync(outputPath, { recursive: true })
117+
console.log(`Created output directory: ${outputPath}`)
118+
}
119+
120+
if (!targets) {
121+
const currentPlatform = os.platform()
122+
switch (currentPlatform) {
123+
case 'darwin':
124+
targets = 'm' // Mac
125+
break
126+
case 'win32':
127+
targets = 'w' // Windows
128+
break
129+
case 'linux':
130+
targets = 'l' // Linux
131+
break
132+
default:
133+
console.error(`Error: Unsupported platform: ${currentPlatform}`)
134+
process.exit(1)
135+
}
136+
console.log(`No target specified. Defaulting to current system: ${targets}`)
137+
}
138+
139+
const targetPlatforms = targets.split('')
140+
141+
targetPlatforms.forEach(async (target) => {
142+
await buildForOS(target, outputPath)
143+
})

0 commit comments

Comments
 (0)