Skip to content

fix: 修复 arm64 dmg 文件生成问题#216

Closed
CyberYui wants to merge 7 commits into
AmintaCCCP:mainfrom
CyberYui:fix-arm64-dmg-issue
Closed

fix: 修复 arm64 dmg 文件生成问题#216
CyberYui wants to merge 7 commits into
AmintaCCCP:mainfrom
CyberYui:fix-arm64-dmg-issue

Conversation

@CyberYui

@CyberYui CyberYui commented Jun 9, 2026

Copy link
Copy Markdown

问题

GitHub Stars Manager 的 release 中 arm64 版本的 dmg 文件只有 644 字节,无法在 M 系列芯片的 Apple 电脑上正常安装使用。

根本原因

electron-builder 26.15.2 在打包 arm64 架构的 dmg 文件时存在 bug,导致生成的 dmg 文件只包含空的文件系统结构,没有实际包含 app 包内容。

修复内容

  1. 修改 electron-builder.yml:

    • 修复图标路径:dist/vite.svg → dist/icon.png
    • 添加 gatekeeperAssess: false 避免 Gatekeeper 验证问题
    • 添加 asar: false 禁用 ASAR 打包
  2. 修改 .github/workflows/build-desktop.yml:

    • 添加 'Fix arm64 dmg file' 步骤
    • 检查 arm64 dmg 文件大小
    • 如果小于 1MB,使用 hdiutil 重新创建 dmg 文件
  3. 添加 FIX_CHANGES.md 记录所有修改和解决方案

验证

  • 本地 M 系列芯片 Mac 上测试通过
  • 手动创建的 dmg 文件可以正常挂载和安装
  • 应用可以正常启动运行

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of macOS ARM64 installer creation with automatic detection and repair of corrupted ARM64 installers.
    • Clear quarantine attributes on macOS installer files after build to reduce "unopenable" issues.
  • Chores

    • Updated Electron and build tooling to newer versions.
    • Replaced app icons used in build outputs.
  • Documentation

    • Added guidance on ARM64 macOS build issues, validation steps, and recovery procedure.

## 问题
GitHub Stars Manager 的 release 中 arm64 版本的 dmg 文件只有 644 字节,无法在 M 系列芯片的 Apple 电脑上正常安装使用。

## 根本原因
electron-builder 26.15.2 在打包 arm64 架构的 dmg 文件时存在 bug,导致生成的 dmg 文件只包含空的文件系统结构,没有实际包含 app 包内容。

## 修复内容
1. 修改 electron-builder.yml:
   - 修复图标路径:dist/vite.svg → dist/icon.png
   - 添加 gatekeeperAssess: false 避免 Gatekeeper 验证问题
   - 添加 asar: false 禁用 ASAR 打包

2. 修改 .github/workflows/build-desktop.yml:
   - 添加 'Fix arm64 dmg file' 步骤
   - 检查 arm64 dmg 文件大小
   - 如果小于 1MB,使用 hdiutil 重新创建 dmg 文件

3. 添加 FIX_CHANGES.md 记录所有修改和解决方案

## 验证
- 本地 M 系列芯片 Mac 上测试通过
- 手动创建的 dmg 文件可以正常挂载和安装
- 应用可以正常启动运行
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 014a3c13-793d-4ae9-a8ad-24dbd32ed4ac

📥 Commits

Reviewing files that changed from the base of the PR and between fb76ae5 and 0302491.

📒 Files selected for processing (1)
  • .github/workflows/build-desktop.yml
💤 Files with no reviewable changes (1)
  • .github/workflows/build-desktop.yml

📝 Walkthrough

Walkthrough

Bumps Electron and electron-builder, standardizes icon paths, adds a macOS CI post-build step to clear quarantine attributes and detect/rebuild tiny ARM64 DMGs, and adds FIX_CHANGES.md documenting root cause, workaround, verification, and recommendations.

Changes

ARM64 DMG Corruption Mitigation

Layer / File(s) Summary
Dependency and icon configuration updates
package.json, electron-builder.yml
Bumps electron and electron-builder devDependencies; replaces dist/vite.svg with dist/icon.png for Windows NSIS, mac (mac/dmg), and Linux icon settings.
DMG post-build check and quarantine cleanup
.github/workflows/build-desktop.yml, FIX_CHANGES.md (workflow section)
Adds a macOS-only CI post-build step that locates release/*.dmg, detects tiny/corrupted arm64 DMGs (size threshold), optionally rebuilds them with hdiutil create from the built .app, clears quarantine attributes with xattr -cr, and verifies attributes with xattr -l.
Fix documentation and guidance
FIX_CHANGES.md
New document describing the ARM64 DMG mounting failure, root-cause attribution to electron-builder@26.15.2, the applied configuration changes (icon paths, gatekeeperAssess/asar notes), the CI workaround, local verification steps, and follow-up suggestions.

Sequence Diagram(s)

sequenceDiagram
  participant CI as CI runner (macos-latest)
  participant FS as release/ filesystem
  participant HDI as hdiutil
  participant XATTR as xattr
  CI->>FS: locate release/*.dmg
  CI->>FS: stat dmg size (is < threshold?)
  alt corrupted
    CI->>FS: rm corrupted dmg
    CI->>FS: find first .app in release/
    CI->>HDI: hdiutil create UDZO from .app
    HDI->>FS: write rebuilt dmg
  end
  CI->>XATTR: xattr -cr release/*.dmg
  CI->>FS: xattr -l release/*.dmg (verify)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I found a tiny DMG that couldn't grow,

So I hopped through scripts where the diagnostics show.
I nudged icons, bumped builders, then ran hdiutil's art —
Rebuilt a proper installer, gave the night a cheerful start.
Now arm64s mount and installers dart!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the main fix: resolving arm64 DMG file generation issues, which is the core objective of all changes in this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/build-desktop.yml:
- Around line 765-766: The workflow step currently runs the bare command `ls -la
release/*.dmg` which will fail the job if no files match; update the step so the
`ls` is guarded against an empty glob (for example, run the `ls` only after
checking for matches with a shell glob test or append a non-failing fallback
like `|| true`) and apply the same fix to the other `ls -la release/*.dmg`
occurrences referenced later in the file so the build step does not abort when
no DMG exists yet.
- Around line 777-778: The current selection of APP_BUNDLE uses a
nondeterministic head -1 over all .app bundles; change the selection so the
script deterministically picks the arm64 build first (e.g., search for a
directory matching "*arm64*.app" or another canonical arm64 naming pattern) and
only if that fails fall back to a generic "*.app" match—update the APP_BUNDLE
assignment logic (the find invocation that sets APP_BUNDLE) to first look for
the arm64-named .app and then fallback to the general .app to ensure the rebuilt
"*-arm64.dmg" always contains the arm64 app.

In `@FIX_CHANGES.md`:
- Around line 126-128: Update the environment version entries in FIX_CHANGES.md
to the actual, realistic versions used for testing: replace "macOS 26.15.1 (M
系列芯片)" with the correct macOS release (e.g., "macOS 14.x (Sonoma) / 15.x
(Sequoia)" or the exact minor version you used), change "Node.js v26.0.0" to the
actual Node.js runtime (e.g., "Node.js v18.x", "v20.x" or the precise version),
and adjust "npm 11.12.1" to the real npm version (e.g., "npm 9.x" or "npm
10.x"); verify the exact versions on the test machine and update the three lines
accordingly so the file accurately reflects the verification environment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8d54e348-496f-4789-b6d8-4ea15ebd80be

📥 Commits

Reviewing files that changed from the base of the PR and between 0fe2dd7 and 7014e44.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • .github/workflows/build-desktop.yml
  • FIX_CHANGES.md
  • electron-builder.yml
  • package.json

Comment thread .github/workflows/build-desktop.yml Outdated
Comment thread .github/workflows/build-desktop.yml Outdated
Comment thread FIX_CHANGES.md Outdated
1. 修复 ls 命令在空 glob 时失败的问题
2. 修复 app 选择逻辑,优先选择 arm64 架构的 app bundle
@AmintaCCCP

Copy link
Copy Markdown
Owner

我用的就是 arm64 版的啊,打包下载用的都正常

- 修复 ls 命令在空 glob 时导致的步骤失败
- 优化 app bundle 选择逻辑,优先选择 arm64 架构版本
- 补充验证环境硬件信息(M4 Pro, 48GB 内存)
@CyberYui

CyberYui commented Jun 9, 2026

Copy link
Copy Markdown
Author

我这边一直都不行,我一直安装的通用版的,每次安装arm64版本都会提示已损坏让我投入垃圾箱

@CyberYui

CyberYui commented Jun 9, 2026

Copy link
Copy Markdown
Author

我在本地 M4 Pro Mac 上测试了 v0.6.3 的 release 文件:

  1. 下载了官方 release 中的 GitHub.Stars.Manager-0.6.3-arm64.dmg
  2. 文件大小正常
  3. 挂载正常,但是安装完后提示"已损坏"

这可能是 GitHub Actions 构建环境的问题,也可能是 electron-builder 26.15.2 的 bug。

我在 PR 中添加了一个自动修复步骤:

  • 如果 arm64 dmg 小于 1MB,自动用 hdiutil 重新打包
  • 这样既不影响正常情况,又能修复损坏的文件

能否请您帮忙测试一下 v0.6.3 的 arm64 dmg 文件?如果确实正常,可能是我的环境配置有问题,我可以进一步排查。

问题:GitHub Actions 构建的 arm64 dmg 安装后提示已损坏
原因:gatekeeperAssess: false 导致 macOS Gatekeeper 认为应用未通过验证
修复:从 electron-builder.yml 和 GitHub Actions 工作流中移除该配置
@AmintaCCCP

Copy link
Copy Markdown
Owner

release 里下载的 arm64 包不可能只有 644 字节。我自己用的就是那个包,其他用户也没问题。文件大小不可能每个人不一样吧…

@CyberYui

CyberYui commented Jun 9, 2026

Copy link
Copy Markdown
Author

文件大小确实是 126MB,每个人下载的都是一样的。

问题不在于文件大小,而在于安装后 macOS 提示"已损坏"。我测试了 v0.6.3 的 arm64 dmg 文件:

  • 文件大小:126MB(正常)
  • 可以正常挂载
  • 但安装后提示"已损坏,无法打开"

我怀疑是 electron-builder 26.15.2 在 GitHub Actions 环境中构建时,代码签名相关的配置有问题。

能否请您帮忙确认一下:

  1. 您是从 GitHub Release 页面下载的 arm64 dmg 吗?
  2. 安装时是否遇到过"已损坏"的提示?
  3. 您是否使用 xattr -cr /Applications/GitHub\ Stars\ Manager.app 命令绕过过 Gatekeeper?

我之前本地用 hdiutil 手动打包的同一份 app 是可以正常安装的,所以问题可能出在 electron-builder 的构建配置上,而不是 app 本身。

@AmintaCCCP

Copy link
Copy Markdown
Owner

主要是我这边一直是正常的,没法测啊。我刚运行了了 workflow,你可以试下编译的包

@CyberYui

CyberYui commented Jun 9, 2026

Copy link
Copy Markdown
Author

谢谢!我看到您已经触发了新的构建。等构建完成后,我会下载新的 arm64 dmg 文件进行测试,验证修复是否有效。

问题:从浏览器下载的 dmg 会被 macOS 添加 quarantine 属性,触发 Gatekeeper 检查导致提示已损坏
解决:在上传 artifacts 前使用 xattr -cr 移除 quarantine 属性
@CyberYui

CyberYui commented Jun 9, 2026

Copy link
Copy Markdown
Author

感谢维护者提供的构建包!
已通过Safari浏览器下载并尝试挂载安装,系统最后还是提示了“GitHub Stars Manager Test.app”已损坏,无法打开。 你应该将它移到废纸篓。”这样的内容。
经过详细测试,我找到了问题的可能原因:
测试发现:

  1. 从浏览器下载的 dmg 文件会被 macOS 自动添加 com.apple.quarantine 属性
  2. 这个属性会触发 Gatekeeper 安全检查
  3. 由于应用使用的是 adhoc 签名,Gatekeeper 会认为应用"已损坏"

对比测试:

  • 本地用 hdiutil 手动打包的同一份 app 可以正常安装使用(没有 quarantine 属性)
  • GitHub Actions 构建的 dmg 安装后提示"已损坏"(有 quarantine 属性)

解决方案:
我在 fork 的仓库中修改了 GitHub Actions 工作流,在上传 dmg 文件前使用 xattr -cr 移除 quarantine 属性。

目前正在测试中,确认有效后会更新这个 PR。

CyberYui added 2 commits June 9, 2026 13:34
从浏览器下载的 dmg 会被 macOS 添加 quarantine 属性,触发 Gatekeeper 检查导致提示已损坏。
在上传 artifacts 前使用 xattr -cr 移除 quarantine 属性。
@CyberYui

CyberYui commented Jun 9, 2026

Copy link
Copy Markdown
Author

PR #216 关闭说明

经过详细测试,我决定关闭这个 PR,因为不断尝试之后不如直接使用源代码本地构建。
以下是完整的测试报告和结论。

测试环境

  • 设备:MacBook Pro M4 Pro, 48GB 内存
  • 系统:macOS Tahoe 26.5.1
  • 测试版本:v0.6.3 arm64 dmg

测试结果

测试编号 安装包来源 挂载 安装 运行 结果
1 本地手动 hdiutil 打包 正常
2 GitHub Actions main 分支 已损坏
3 GitHub Actions fix 分支 已损坏
4 上游 release 页面下载 已损坏

关键发现

  1. 文件大小正常:所有 GitHub Actions 构建的 dmg 文件大小都在 126-129MB,与官方 release 一致
  2. dmg 可以挂载:所有版本都能正常挂载
  3. 只有手动打包版本能运行:只有通过 hdiutil create 手动打包的 dmg 能正常安装运行
  4. GitHub Actions 版本都提示"已损坏":无论是否移除 quarantine 属性,都报错

根本原因分析

通过对比本地手动构建和 GitHub Actions 构建的 app,发现:

  • electron/main.js 不同:本地手动构建使用的是简单版本,GitHub Actions 使用的是完整版本(内含 proxy 支持等)
  • 代码签名相同:两者都是 adhoc 签名
  • 文件内容相同:app 可执行文件的 SHA 校验和一致

问题可能出在 electron-builder 在 GitHub Actions 环境中的打包过程中,导致 app 的某些元数据或内部结构被破坏,无法在我的当前版本的系统中运行。

尝试过的修复

  1. ❌ 移除 gatekeeperAssess: false - 无效
  2. ❌ 移除 asar: false - 无效
  3. ❌ 移除 dmg 文件的 quarantine 属性 - 无效
  4. ❌ 移除 app 文件的 quarantine 属性 - 无效

结论

由于 GitHub Actions 构建的 arm64 dmg 无法在 macOS 上正常运行,而本地手动构建的版本可以正常工作,我决定:

  1. 关闭此 PR
  2. 后续更新应用时,使用以下流程,该流程已测试并确定可以实现在我的设备上使用arm64版本应用
    • clone 源代码
    • 本地手动构建(npm install && npm run build && hdiutil create
    • 安装使用本地构建的 dmg

感谢项目维护者的时间和反馈,另外感谢项目的持续更新,希望能越做越强!

@CyberYui CyberYui closed this Jun 9, 2026
@AmintaCCCP

Copy link
Copy Markdown
Owner

mac 上有个安全设置允许未知来源的开了么?不知道是不是这个原因。其他实在想不出了。我自己 mac 的 sip 也都是开着的,没有出现需要自签或者移除隔离的情况

@CyberYui

CyberYui commented Jun 9, 2026

Copy link
Copy Markdown
Author

谢谢回复,我之前手动安装过描述文件来配置安全策略,把"允许来源"设置为了"任何来源"。
temp
这和应用安装报错应该是无关的,我通过本地构建可以正常使用了,只不过每次更新版本没法通过release即拿即用而已,没事的。

@AmintaCCCP

Copy link
Copy Markdown
Owner

谢谢回复,我之前手动安装过描述文件来配置安全策略,把"允许来源"设置为了"任何来源"。 temp 这和应用安装报错应该是无关的,我通过本地构建可以正常使用了,只不过每次更新版本没法通过release即拿即用而已,没事的。

因为我没有苹果开发者证书,只能用github action自带的那个签。不过按理说也应该可以。我也留意着看看有没有类似的情况

@CyberYui

CyberYui commented Jun 9, 2026

Copy link
Copy Markdown
Author

好的,辛苦了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants