Skip to content

Commit 9bceb53

Browse files
committed
fix: build task on ci
1 parent 1e62420 commit 9bceb53

File tree

3 files changed

+131
-48
lines changed

3 files changed

+131
-48
lines changed

.github/workflows/release.yml

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,81 @@ on:
66
types: [closed]
77

88
jobs:
9-
release:
9+
build-windows:
10+
runs-on: windows-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
- name: Install dependencies
15+
run: |
16+
npm add -g pnpm
17+
pnpm install
18+
- name: Build Windows
19+
run: pnpm build
20+
- name: Compress Windows Artifact
21+
run: Compress-Archive -Path dist/Git_Commit_Analytics_win.exe -DestinationPath Git_Commit_Analytics_win.zip
22+
- name: Upload Windows Artifact
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: windows-build
26+
path: Git_Commit_Analytics_win.zip
27+
28+
build-mac:
1029
runs-on: ubuntu-latest
1130
steps:
1231
- name: Checkout
1332
uses: actions/checkout@v4
14-
- name: Install and build
33+
- name: Install dependencies
1534
run: |
1635
npm add -g pnpm
1736
pnpm install
18-
pnpm build
19-
- name: Compress
37+
- name: Build macOS
38+
run: pnpm build
39+
- name: Compress macOS Artifact
40+
run: zip --junk-paths Git_Commit_Analytics_mac.zip dist/Git_Commit_Analytics_mac
41+
- name: Upload macOS Artifact
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: mac-build
45+
path: Git_Commit_Analytics_mac.zip
46+
47+
assets:
48+
runs-on: ubuntu-latest
49+
needs: [build-windows, build-mac]
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v4
53+
- name: Download Windows Artifact
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: windows-build
57+
path: dist/
58+
- name: Download macOS Artifact
59+
uses: actions/download-artifact@v4
60+
with:
61+
name: mac-build
62+
path: dist/
63+
- name: Prepare Assets
2064
run: |
21-
zip --junk-paths Git_Commit_Analytics_win dist/Git_Commit_Analytics_win.exe
22-
zip --junk-paths Git_Commit_Analytics_mac dist/Git_Commit_Analytics_mac
65+
ls -lah dist/
66+
- name: Upload Final Assets
67+
uses: actions/upload-artifact@v4
68+
with:
69+
name: final-assets
70+
path: dist/
71+
72+
release:
73+
runs-on: ubuntu-latest
74+
needs: [assets]
75+
steps:
76+
- name: Checkout
77+
uses: actions/checkout@v4
78+
- name: Download Final Assets
79+
uses: actions/download-artifact@v4
80+
with:
81+
name: final-assets
82+
path: dist/
2383
- name: Release
24-
id: create_release
2584
env:
2685
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
2786
run: pnpm exec semantic-release

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"source.fixAll.eslint": "always",
66
"source.fixAll.prettier": "always"
77
},
8-
"cSpell.words": ["codesign", "postject", "taze"]
8+
"cSpell.words": ["codesign", "postject", "signtool", "taze"]
99
}

scripts/build.js

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,70 @@ import { execSync } from 'node:child_process'
22
import { existsSync, mkdirSync } from 'node:fs'
33
import { join } from 'node:path'
44

5+
const WIN_OUTPUT_NAME = 'Git_Commit_Analytics_win.exe'
6+
const MAC_OUTPUT_NAME = 'Git_Commit_Analytics_mac'
7+
const SEA_BLOB = 'sea-prep.blob'
8+
const OUTPUT_DIR = 'dist'
9+
10+
const NODE_PATH = process.execPath // Node.js executable file path
11+
12+
async function buildWin() {
13+
const OUTPUT_PATH = join(OUTPUT_DIR, WIN_OUTPUT_NAME)
14+
15+
try {
16+
console.log(`📦 Creating standalone executable for Windows...`)
17+
18+
execSync(
19+
`node -e "require('fs').copyFileSync(process.execPath, ${OUTPUT_PATH})" `,
20+
)
21+
22+
execSync(`signtool remove /s ${OUTPUT_PATH}`)
23+
24+
execSync(
25+
[
26+
`npx postject ${OUTPUT_PATH} NODE_SEA_BLOB ${SEA_BLOB}`,
27+
'--sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
28+
].join(' '),
29+
)
30+
31+
execSync(`codesign --sign - ${OUTPUT_PATH}`)
32+
return true
33+
} catch (error) {
34+
console.error('❌ Failed to create executable for Windows:', error)
35+
return false
36+
}
37+
}
38+
39+
async function buildMac() {
40+
const OUTPUT_PATH = join(OUTPUT_DIR, MAC_OUTPUT_NAME)
41+
42+
try {
43+
console.log(`📦 Creating standalone executable for macOS...`)
44+
45+
execSync(`cp ${NODE_PATH} ${OUTPUT_PATH}`)
46+
47+
execSync(`codesign --remove-signature ${OUTPUT_PATH}`)
48+
49+
execSync(
50+
[
51+
`npx postject ${OUTPUT_PATH} NODE_SEA_BLOB ${SEA_BLOB}`,
52+
'--sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
53+
'--macho-segment-name NODE_SEA',
54+
].join(' '),
55+
)
56+
57+
execSync(`codesign --sign - ${OUTPUT_PATH}`)
58+
return true
59+
} catch (error) {
60+
console.error('❌ Failed to create executable for macOS:', error)
61+
return false
62+
}
63+
}
64+
565
// https://nodejs.org/api/single-executable-applications.html
666
async function build() {
7-
const WIN_OUTPUT_NAME = 'Git_Commit_Analytics_win.exe'
8-
const MAC_OUTPUT_NAME = 'Git_Commit_Analytics_mac'
9-
const SEA_BLOB = 'sea-prep.blob'
10-
const OUTPUT_DIR = 'dist'
11-
1267
const PLATFORM = process.platform // 'win32' | 'darwin' | 'linux'
1368
const IS_WIN = PLATFORM === 'win32'
14-
const IS_MAC = PLATFORM === 'darwin'
15-
16-
const OUTPUT_NAME = IS_WIN ? WIN_OUTPUT_NAME : MAC_OUTPUT_NAME
17-
const OUTPUT_PATH = join(OUTPUT_DIR, OUTPUT_NAME)
18-
const NODE_PATH = process.execPath // Node.js executable file path
1969

2070
if (!existsSync(OUTPUT_DIR)) {
2171
mkdirSync(OUTPUT_DIR, { recursive: true })
@@ -36,40 +86,14 @@ async function build() {
3686
process.exit(1)
3787
}
3888

39-
console.log(`📦 Creating standalone executable for ${PLATFORM}...`)
89+
const buildTask = IS_WIN ? buildWin : buildMac
4090

41-
try {
42-
if (IS_WIN) {
43-
execSync(
44-
`cmd /c "copy /b ${NODE_PATH} + ${SEA_BLOB} ${OUTPUT_PATH} && exit /b"`,
45-
{
46-
stdio: 'inherit',
47-
shell: true,
48-
},
49-
)
50-
} else {
51-
execSync(`cp ${NODE_PATH} ${OUTPUT_PATH}`)
52-
53-
if (IS_MAC) {
54-
execSync(`codesign --remove-signature ${OUTPUT_PATH}`)
55-
56-
execSync(
57-
[
58-
`npx postject ${OUTPUT_PATH} NODE_SEA_BLOB ${SEA_BLOB}`,
59-
'--sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2',
60-
'--macho-segment-name NODE_SEA',
61-
].join(' '),
62-
)
63-
64-
execSync(`codesign --sign - ${OUTPUT_PATH}`)
65-
}
66-
}
67-
} catch (error) {
68-
console.error('❌ Failed to create executable:', error)
91+
const isSuccess = await buildTask()
92+
if (!isSuccess) {
6993
process.exit(1)
7094
}
7195

72-
console.log(`✅ Build complete: ${OUTPUT_PATH}`)
96+
console.log(`✅ Build complete!`)
7397
}
7498

7599
build().catch(console.error)

0 commit comments

Comments
 (0)