Skip to content

fix(ci): gate iOS release automation on successful Analyze - #81

Open
CNDY1390 wants to merge 1 commit into
masterfrom
fix/ios-release-analyze-gate
Open

fix(ci): gate iOS release automation on successful Analyze#81
CNDY1390 wants to merge 1 commit into
masterfrom
fix/ios-release-analyze-gate

Conversation

@CNDY1390

@CNDY1390 CNDY1390 commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

背景

原来的 iOS 自动发布流程监听 PR 合并事件:

PR 合并 + ios:release:* Label
→ 创建 Git Tag
→ 派遣私有仓库构建签名 IPA

该流程不会等待合并提交在 master 上的 flutter analyze 完成。

此前 PR #71 合并后,自动流程创建了 ios-v0.4.0+1,但代码中的 TargetPlatform.ohos 随后导致 Analyze 和 iOS 构建失败。核心问题:CI 尚未通过,发布流程已经开始。

修改目标

  • PR 合并后,等待 master 对应提交的 Analyze 完成。
  • Analyze 失败:不创建 Tag、不构建 IPA。
  • Analyze 成功:继续检查 ios:release:* Label。
  • 复用准确 Commit SHA 已有的 Analyze 结果,不重复执行 flutter analyze
  • 手动创建的 iOS Tag 同样不能绕过 Analyze。
  • 防止同一 SHA 重复发版,以及旧 SHA 被标记成更高版本。

修改内容

Auto Tag iOS Release

触发条件从:

pull_request_target: closed

改为:

Analyze workflow_run: completed

仅在以下条件全部成立时继续:

event == push
head_branch == master
conclusion == success

随后:

  1. 使用 Analyze 的准确 head_sha
  2. 查询该 SHA 对应的已合并 PR。
  3. 检查 PR 是否恰好具有一个 ios:release:patch/minor/major Label。
  4. 没有发布 Label:正常跳过。
  5. 同一 SHA 已存在合法 iOS Tag:跳过,防止重复发布。
  6. 最新发布 Tag 不是目标 SHA 的祖先:拒绝发布,防止旧代码获得更高版本号。
  7. 创建 Tag 后显式调用 Dispatch iOS Release

Dispatch iOS Release

派遣私有签名仓库前增加 Analyze 门禁:

  1. 解析 Git Tag 对应的准确 TAG_SHA
  2. 查询 analyze.yml 已有的 Workflow Runs。
  3. 仅接受同时满足以下条件的结果:
event == push
head_branch == master
head_sha == TAG_SHA
conclusion == success

找不到对应结果:拒绝派遣私有仓库。

该步骤只查询已有 CI 结果,不会重新运行 flutter analyze

最终流程

PR 更新
└─ Analyze:检查 PR

PR 合并到 master
└─ Analyze:检查实际合并 SHA
   ├─ failure:结束
   └─ success
      └─ Auto Tag
         ├─ 无 ios:release:* Label:结束
         └─ 有发布 Label
            ├─ 创建 Git Tag
            └─ Dispatch
               ├─ 再次核对该 Tag SHA 已有的 Analyze 结果
               └─ 通知私有仓库签名 IPA、上传 TestFlight

验证

  • 三段 Bash 脚本语法检查通过。
  • 新 SHA:正常计算下一版本。
  • 已打 Tag 的 SHA:正常跳过。
  • 比最新发布版本更旧的 SHA:拒绝发布。
  • git diff --check 通过。
  • Commit GPG 签名验证通过。
  • 私有 TechPie-release 仓库未修改。

尚未验证:真实 GitHub Actions 端到端运行。workflow_run 必须进入默认分支后才能进行真实验证。

请重点 Review

  1. workflow_run 的触发条件是否正确。
  2. head_sha 是否始终对应准备发布的准确提交。
  3. Commit 与已合并 PR、PR Label 的关联逻辑是否可靠。
  4. 同一 SHA 的幂等处理是否合理。
  5. 多个 Analyze 乱序完成时,祖先检查是否足够。
  6. Workflow Runs API 对 TAG_SHA 的过滤是否正确。
  7. actions: read/writecontents: write 权限是否合理。
  8. 使用 GITHUB_TOKEN 创建 Tag 后,再显式调用 workflow_dispatch 的逻辑是否正确。
  9. Tag 已创建但 Dispatch 失败时的恢复方式是否可接受。

合并后预期行为

master Analyze 成功
→ Auto Tag 启动
→ 检查到本 PR 没有发布 Label
→ 正常跳过
→ 不创建 Git Tag
→ 不调用私有签名仓库

@CNDY1390
CNDY1390 requested review from HeZeBang and Honahec July 31, 2026 11:07
@github-project-automation github-project-automation Bot moved this to Backlog in TechPie Jul 31, 2026
@CNDY1390
CNDY1390 marked this pull request as ready for review August 1, 2026 09:01
@CNDY1390
CNDY1390 requested a review from Copilot August 1, 2026 09:01

Copilot AI 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.

Pull request overview

This PR updates the iOS release automation to only proceed when the Analyze workflow has completed successfully for the exact merge/tag SHA, preventing tag creation and release dispatch when CI hasn’t passed yet.

Changes:

  • Rework Auto Tag iOS Release to trigger from workflow_run of Analyze (push to master, conclusion success), then resolve the merged PR + release label from the analyzed head_sha.
  • Add an Analyze-result gate to Dispatch iOS Release by verifying an existing successful Analyze run matches the release tag’s resolved TAG_SHA.
  • Add safeguards for idempotency and version ordering (skip if SHA already tagged; refuse tagging older history as newer version).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
.github/workflows/dispatch-ios-release.yml Adds an explicit “Analyze must have succeeded for TAG_SHA” gate before dispatching the private signing workflow; updates permissions for Actions API reads.
.github/workflows/auto-tag-ios-release.yml Switches to workflow_run trigger from Analyze success on master, resolves PR/labels via SHA, enforces idempotency + ancestry checks, then tags + dispatches release.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +84 to +91
analyze_runs="$(
gh api --method GET \
"/repos/$REPOSITORY/actions/workflows/analyze.yml/runs" \
-f event=push \
-f status=success \
-f head_sha="$TAG_SHA" \
-f per_page=100
)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants