ci(workflows): 在构建后清理 unpacked 目录以减少产物大小

- 为 Windows、macOS 和 Linux 构建作业添加清理步骤,移除 `dist/*unpacked*` 目录
- 在 dir 构建作业中,将 unpacked 目录压缩为 zip 文件后再清理原目录
- 在发布 Release 前,从 artifacts 目录中递归清理所有 unpacked 目录
This commit is contained in:
Fox_block
2026-01-23 13:17:16 +08:00
parent d979e332db
commit 6403795839
+35
View File
@@ -83,6 +83,15 @@ jobs:
- name: 构建(Windows - name: 构建(Windows
run: pnpm build:win run: pnpm build:win
- name: 清理 unpacked 目录
shell: pwsh
run: |
if (Test-Path dist) {
Get-ChildItem -Path dist -Directory -ErrorAction SilentlyContinue |
Where-Object { $_.Name -like '*unpacked*' } |
ForEach-Object { Remove-Item -Recurse -Force $_.FullName }
}
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
with: with:
name: dist-win name: dist-win
@@ -112,6 +121,9 @@ jobs:
- name: 构建(macOS - name: 构建(macOS
run: pnpm -s build:mac run: pnpm -s build:mac
- name: 清理 unpacked 目录
run: rm -rf dist/*unpacked*
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
with: with:
name: dist-mac name: dist-mac
@@ -141,6 +153,9 @@ jobs:
- name: 构建(Linux - name: 构建(Linux
run: pnpm -s build:linux run: pnpm -s build:linux
- name: 清理 unpacked 目录
run: rm -rf dist/*unpacked*
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
with: with:
name: dist-linux name: dist-linux
@@ -170,6 +185,20 @@ jobs:
- name: 构建(dir - name: 构建(dir
run: pnpm -s build:unpack run: pnpm -s build:unpack
- name: 打包并移除 unpacked 目录
shell: pwsh
run: |
if (Test-Path dist) {
$dirs = Get-ChildItem -Path dist -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -like '*unpacked*' }
foreach ($d in $dirs) {
$zipBase = ($d.Name -replace 'unpacked', 'dir')
$zipPath = Join-Path dist "$zipBase.zip"
if (Test-Path $zipPath) { Remove-Item -Force $zipPath }
Compress-Archive -Path (Join-Path $d.FullName '*') -DestinationPath $zipPath -Force
Remove-Item -Recurse -Force $d.FullName
}
}
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
with: with:
name: dist-unpack name: dist-unpack
@@ -184,6 +213,12 @@ jobs:
with: with:
path: artifacts path: artifacts
- name: 清理 unpacked 目录
run: |
if [ -d artifacts ]; then
find artifacts -type d -name '*unpacked*' -prune -exec rm -rf {} +
fi
- name: 发布 Release - name: 发布 Release
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
with: with: