Skip to content

Commit f38af4c

Browse files
committed
ci: release on tag
1 parent 6eb161c commit f38af4c

4 files changed

Lines changed: 180 additions & 9 deletions

File tree

.github/workflows/release.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Release (Windows)
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build-windows-installer:
13+
runs-on: windows-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Derive version from tag
19+
shell: pwsh
20+
run: |
21+
$tag = "${{ github.ref_name }}"
22+
$version = $tag -replace '^v', ''
23+
if ([string]::IsNullOrWhiteSpace($version)) {
24+
throw "Invalid tag: '$tag' (expected like v1.0.0)"
25+
}
26+
"TAG_NAME=$tag" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
27+
"VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
28+
29+
- name: Setup Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: "20"
33+
cache: "npm"
34+
cache-dependency-path: |
35+
frontend/package-lock.json
36+
desktop/package-lock.json
37+
38+
- name: Setup Python
39+
uses: actions/setup-python@v5
40+
with:
41+
python-version-file: ".python-version"
42+
43+
- name: Install uv
44+
shell: pwsh
45+
run: |
46+
python -m pip install --upgrade pip
47+
python -m pip install uv
48+
49+
- name: Install frontend deps
50+
working-directory: frontend
51+
run: npm ci
52+
53+
- name: Install desktop deps
54+
working-directory: desktop
55+
run: npm ci
56+
57+
- name: Set desktop app version (electron-builder)
58+
working-directory: desktop
59+
shell: pwsh
60+
run: |
61+
npm version $env:VERSION --no-git-tag-version
62+
63+
- name: Build Windows installer
64+
working-directory: desktop
65+
run: npm run dist
66+
67+
- name: Create GitHub Release and upload installer
68+
uses: softprops/action-gh-release@v2
69+
env:
70+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
with:
72+
tag_name: ${{ env.TAG_NAME }}
73+
name: ${{ env.TAG_NAME }}
74+
generate_release_notes: true
75+
files: |
76+
desktop/dist/*Setup*.exe
77+
desktop/dist/*Setup*.exe.blockmap
78+

desktop/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"build": {
1515
"appId": "com.lifearchive.wechatdataanalysis",
1616
"productName": "WeChatDataAnalysis",
17-
"icon": "resources/icon.ico",
17+
"icon": "build/icon.ico",
1818
"asar": true,
1919
"directories": {
2020
"output": "dist"
@@ -34,15 +34,18 @@
3434
}
3535
],
3636
"win": {
37-
"icon": "resources/icon.ico",
37+
"icon": "build/icon.ico",
3838
"target": [
3939
"nsis"
4040
]
4141
},
4242
"nsis": {
43-
"installerIcon": "resources/icon.ico",
44-
"uninstallerIcon": "resources/icon.ico",
45-
"installerHeaderIcon": "resources/icon.ico"
43+
"oneClick": false,
44+
"allowToChangeInstallationDirectory": true,
45+
"include": "scripts/installer-custom.nsh",
46+
"installerIcon": "build/installerIcon.ico",
47+
"uninstallerIcon": "build/uninstallerIcon.ico",
48+
"installerHeaderIcon": "build/installerHeaderIcon.ico"
4649
}
4750
},
4851
"devDependencies": {

desktop/scripts/build-icon.cjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ const { PNG } = require("pngjs");
66

77
const repoRoot = path.resolve(__dirname, "..", "..");
88
const srcPng = path.join(repoRoot, "frontend", "public", "logo.png");
9-
const dstIco = path.join(repoRoot, "desktop", "resources", "icon.ico");
9+
// Write the generated ICO to the locations electron-builder expects for app+installer icons.
10+
// Also keep a copy in desktop/resources for convenience.
11+
const dstIcos = [
12+
path.join(repoRoot, "desktop", "resources", "icon.ico"),
13+
path.join(repoRoot, "desktop", "build", "icon.ico"),
14+
path.join(repoRoot, "desktop", "build", "installerIcon.ico"),
15+
path.join(repoRoot, "desktop", "build", "uninstallerIcon.ico"),
16+
path.join(repoRoot, "desktop", "build", "installerHeaderIcon.ico"),
17+
];
1018

1119
async function main() {
1220
if (!fs.existsSync(srcPng)) {
@@ -35,11 +43,13 @@ async function main() {
3543
fs.writeFileSync(tmpPng, PNG.sync.write(square));
3644

3745
const buf = await pngToIco(tmpPng);
38-
fs.mkdirSync(path.dirname(dstIco), { recursive: true });
39-
fs.writeFileSync(dstIco, buf);
46+
for (const dstIco of dstIcos) {
47+
fs.mkdirSync(path.dirname(dstIco), { recursive: true });
48+
fs.writeFileSync(dstIco, buf);
49+
}
4050

4151
// eslint-disable-next-line no-console
42-
console.log(`Generated icon: ${dstIco}`);
52+
console.log(`Generated icon(s):\n${dstIcos.map((p) => `- ${p}`).join("\n")}`);
4353
}
4454

4555
main().catch((err) => {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
; This file is included for both installer and uninstaller builds.
2+
; Guard installer-only pages/functions to avoid "function not referenced" warnings
3+
; when electron-builder compiles the standalone uninstaller.
4+
!ifndef BUILD_UNINSTALLER
5+
!include nsDialogs.nsh
6+
!include LogicLib.nsh
7+
8+
; Directory page is a "parent folder" picker. When users browse to a new folder,
9+
; NSIS will set $INSTDIR to exactly what they pick (without app sub-folder),
10+
; and electron-builder later appends "\${APP_FILENAME}" before installation.
11+
; Make this explicit on the directory page to reduce confusion.
12+
!define /ifndef MUI_DIRECTORYPAGE_TEXT_TOP "请选择安装位置(将自动创建并使用“${APP_FILENAME}”子文件夹)。"
13+
!define /ifndef MUI_DIRECTORYPAGE_TEXT_DESTINATION "安装位置:"
14+
15+
Var WDA_InstallDirPage
16+
17+
!macro customPageAfterChangeDir
18+
; Add a confirmation page after the directory picker so users clearly see
19+
; the final install location (includes the app sub-folder).
20+
!ifdef allowToChangeInstallationDirectory
21+
Page custom WDA_InstallDirPageCreate WDA_InstallDirPageLeave
22+
!endif
23+
!macroend
24+
25+
Function WDA_EnsureAppSubDir
26+
; Normalize $INSTDIR to always end with "\${APP_FILENAME}" (avoid cluttering a parent folder).
27+
StrCpy $0 "$INSTDIR"
28+
29+
; Trim trailing "\" (except for drive root like "C:\").
30+
StrLen $1 "$0"
31+
${If} $1 > 3
32+
StrCpy $2 "$0" 1 -1
33+
${If} $2 == "\"
34+
IntOp $1 $1 - 1
35+
StrCpy $0 "$0" $1
36+
${EndIf}
37+
${EndIf}
38+
39+
; If already ends with APP_FILENAME, keep it.
40+
StrLen $3 "$0"
41+
StrLen $4 "${APP_FILENAME}"
42+
${If} $3 >= $4
43+
IntOp $5 $3 - $4
44+
StrCpy $6 "$0" $4 $5
45+
${If} $6 == "${APP_FILENAME}"
46+
StrCpy $INSTDIR "$0"
47+
Return
48+
${EndIf}
49+
${EndIf}
50+
51+
; Otherwise append the app folder name.
52+
StrCpy $INSTDIR "$0\${APP_FILENAME}"
53+
FunctionEnd
54+
55+
Function WDA_InstallDirPageCreate
56+
Call WDA_EnsureAppSubDir
57+
58+
nsDialogs::Create 1018
59+
Pop $WDA_InstallDirPage
60+
61+
${If} $WDA_InstallDirPage == error
62+
Abort
63+
${EndIf}
64+
65+
${NSD_CreateLabel} 0u 0u 100% 24u "程序将安装到:"
66+
Pop $0
67+
68+
${NSD_CreateLabel} 0u 22u 100% 24u "$INSTDIR"
69+
Pop $0
70+
71+
${NSD_CreateLabel} 0u 50u 100% 36u "为避免把文件直接安装到父目录,安装程序会自动创建“${APP_FILENAME}”子文件夹。"
72+
Pop $0
73+
74+
nsDialogs::Show
75+
FunctionEnd
76+
77+
Function WDA_InstallDirPageLeave
78+
FunctionEnd
79+
80+
!endif

0 commit comments

Comments
 (0)