-
-
Notifications
You must be signed in to change notification settings - Fork 396
Expand file tree
/
Copy pathbuild-linux.mjs
More file actions
80 lines (69 loc) · 2.56 KB
/
Copy pathbuild-linux.mjs
File metadata and controls
80 lines (69 loc) · 2.56 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
import { existsSync, readdirSync, readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { spawnSync } from 'node:child_process'
const root = process.cwd()
const releaseDir = resolve(root, 'release')
function run(args) {
console.info(`\n> pnpm exec electron-builder ${args.join(' ')}`)
const result = spawnSync('pnpm', ['exec', 'electron-builder', ...args], {
cwd: root,
stdio: 'inherit',
shell: false
})
if (result.status !== 0) {
process.exit(result.status || 1)
}
}
function readArEntries(file) {
const data = readFileSync(file)
if (data.subarray(0, 8).toString() !== '!<arch>\n') {
throw new Error(`${file} is not an ar archive`)
}
const entries = []
let offset = 8
while (offset + 60 <= data.length) {
const header = data.subarray(offset, offset + 60)
const name = header.subarray(0, 16).toString().trim()
const sizeText = header.subarray(48, 58).toString().trim()
const end = header.subarray(58, 60).toString()
const size = Number.parseInt(sizeText, 10)
if (end !== '`\n' || !Number.isFinite(size)) {
throw new Error(`${file} has an invalid ar header`)
}
if (name.startsWith('#1/')) {
throw new Error(`${file} uses BSD ar extended names; Debian packages require GNU ar format`)
}
entries.push(name.replace(/\/$/, ''))
offset += 60 + size + (size % 2)
}
return entries
}
function validateDebArtifacts() {
if (!existsSync(releaseDir)) {
throw new Error('release directory was not created')
}
const debs = readdirSync(releaseDir)
.filter((name) => name.endsWith('.deb'))
.map((name) => resolve(releaseDir, name))
if (debs.length === 0) {
throw new Error('no .deb artifacts were created')
}
for (const deb of debs) {
const entries = readArEntries(deb)
const hasDebianBinary = entries.includes('debian-binary')
const hasControl = entries.some((entry) => entry.startsWith('control.tar'))
const hasData = entries.some((entry) => entry.startsWith('data.tar'))
if (!hasDebianBinary || !hasControl || !hasData) {
throw new Error(`${deb} is not a valid Debian package: ${entries.join(', ')}`)
}
}
}
if (process.platform !== 'linux') {
run(['--linux', 'AppImage', '--x64', '--arm64'])
console.warn('\nSkipping Linux deb and pacman targets on non-Linux host.')
console.warn('electron-builder/fpm can produce invalid .deb archives on macOS because BSD ar is not GNU ar.')
console.warn('Run this script on Linux or use the Ubuntu release workflow to build .deb artifacts.')
process.exit(0)
}
run(['--linux'])
validateDebArtifacts()