Repository navigation
feat(ci): support independent G2 release lines - #818
Conversation
Reviewer's GuideAPIReview the reusable group-version workflow interface and its inherited App secrets, permissions, and guard-status reporting.
ImplementationReview the preparation logic that validates trusted release-line configuration, preflights all members, creates fixed-SHA branches, synchronizes templates, and verifies protections.
ConfigurationReview the dispatchable preparation workflow, its trust and permission boundaries, and the default-branch template-sync changes used by preparation.
Review the 17 member template configurations together to verify release-line branch coverage and shared workflow sources.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 15 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path=".github/workflows/prepare-release-line.yml" line_range="4" />
<code_context>
+name: Prepare release line
+
+on:
+ workflow_dispatch:
+ inputs:
+ release_line:
</code_context>
<issue_to_address>
**Write users inherit App privileges**
When a user with write access to the coordinator repository dispatches the workflow with `dry_run` false and a configured release line, the workflow mints an installation token with organization-wide Contents/Actions write and, when available, Administration write, then passes it to `prepare()` to create member branches and update their protections. A user who can dispatch this workflow can therefore exercise the App’s broader privileges across the 17 repositories.
Restrict dispatch to an explicitly authorized maintainer set or require approval through a protected environment before minting the elevated token.
</issue_to_address>
### Comment 2
<location path=".github/scripts/prepare_release_line.py" line_range="177" />
<code_context>
+ if name != GUARD_CONTEXT and name in checks and checks[name] != binding:
+ raise RuntimeError(f"同一必需检查 {name} 有冲突 App 绑定,不能覆盖现有规则")
+ checks[name] = binding
+ checks[GUARD_CONTEXT] = app_id
+ payload = {
+ "required_status_checks": {"strict": True, "checks": [
</code_context>
<issue_to_address>
**Guard status can be forged**
When a contributor who can push a branch adds a `pull_request` workflow with `statuses: write` and posts success for the PR head, a PR-controlled workflow can use its `GITHUB_TOKEN` with `statuses: write` to post a successful `group-version-guard` status under the same GitHub Actions App identity required by this protection. The version guard is therefore bypassable, allowing an otherwise eligible PR with an invalid release version to satisfy this check.
Publish and require the guard result under a dedicated GitHub App identity whose credentials are unavailable to PR-controlled workflows.
</issue_to_address>
### Comment 3
<location path=".github/scripts/prepare_release_line.py" line_range="344-351" />
<code_context>
+ check_member_workflows(api, repo, branch)
+ state = "PROTECTION_FAILED"
+ app_source = actions_app_id(api)
+ target = read_protection(api, repo, branch)
+ if not protection_ready(target, app_source):
+ default = read_protection(api, repo, row["default"])
+ payload = protection_payload(target, default, app_source)
+ if not admin_write:
+ raise ReadinessError(state, f"{repo} App 无 Admin Write;管理员保留现有审核/检查并配置"
+ f"保护后重跑: https://github.com/{repo}/settings/branches")
+ api(f"repos/{repo}/branches/{quote(branch, safe='')}/protection", payload, method="PUT")
+ observed = read_protection(api, repo, branch)
+ verify_preserved(observed, payload, app_source)
</code_context>
<issue_to_address>
**Concurrent protection edits disappear**
When an administrator changes target-branch protection after Prepare reads it but before Prepare writes the payload, the protection payload is built from `target` as read before the PUT. If an administrator adds a required check or changes another protection setting between that read and the PUT, the update replaces the intervening policy with the stale payload, and the new requirement disappears.
Use a conditional update if supported, or re-read and compare protection immediately before writing, aborting and rebuilding the payload when it changed.
</issue_to_address>
### Comment 4
<location path=".github/scripts/prepare_release_line.py" line_range="148" />
<code_context>
+ reviews.pop("url", None)
+ if "dismissal_restrictions" in reviews:
+ reviews["dismissal_restrictions"] = _actors(reviews["dismissal_restrictions"])
+ reviews["bypass_pull_request_allowances"] = {"users": [], "teams": [], "apps": []}
+ reviews.setdefault("required_approving_review_count", 0)
+ reviews.setdefault("dismiss_stale_reviews", False)
</code_context>
<issue_to_address>
**Review bypass access disappears**
When the source branch has configured pull-request review bypass allowances, `protection_payload` replaces the existing user, team, and app allowances with empty lists, so applying protection removes those bypass rights and disrupts the usual merge path.
Preserve the source branch’s existing pull-request bypass allowances in the protection payload.
</issue_to_address>
### Comment 5
<location path=".github/scripts/prepare_release_line.py" line_range="331" />
<code_context>
+ if any(content(api, row["repo"], f".github/workflows/{name}", base, missing=True) != text
+ for row in rows for base in dict.fromkeys((row["default"], branch))
+ for name, text in row["templates"].items()):
+ sync_templates(api, coordinator.split("/")[0])
+ for row in rows:
+ state = "TEMPLATE_MISSING"
</code_context>
<issue_to_address>
**Concurrent sync aborts preparation**
When two release-line preparations dispatch template synchronization before the first sync completes, the shared templates-sync concurrency group cancels the in-progress run, and `sync_templates` treats the canceled run as a failure when it appears in the poll; Prepare then exits after creating branches, leaving setup incomplete.
Prevent one release-line sync dispatch from canceling another, or make the polling logic wait for the replacement run before treating cancellation as a failure.
Also at `.github/workflows/prepare-release-line.yml:20`, `.github/scripts/prepare_release_line.py:214-219`, `.github/scripts/prepare_release_line.py:221`.
</issue_to_address>
### Comment 6
<location path=".github/workflows/templates-sync.yml" line_range="17" />
<code_context>
templates-sync:
# limit push on linuxdeepin/.github master branch
- if: github.repository == 'linuxdeepin/.github' && github.ref == 'refs/heads/master'
+ if: github.repository == 'linuxdeepin/.github' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-latest
steps:
</code_context>
<issue_to_address>
**Organization-specific sync job skips**
When prepare dispatches templates-sync from a `.github` repository outside `linuxdeepin`, the job condition requires `github.repository` to equal `linuxdeepin/.github`, so the dispatched job skips; `sync_templates` then times out and Prepare leaves created branches without synchronized workflows or protection checks.
Allow the job to run in the dispatched organization’s `.github` repository while retaining the default-branch condition.
</issue_to_address>
### Comment 7
<location path=".github/workflows/verify-group-version.yml" line_range="213-214" />
<code_context>
if (after != target or source["full_name"] != repo or pr["head"]["ref"] != branch
or pr["base"]["ref"] != member["base"] or pr["created_at"] < release["started_at"]):
raise RuntimeError(f"{repo} 的改版 PR 不属于 {group} 本轮 {target},请从 DDE Release group 发起")
+ for path, version in recipes.items():
</code_context>
<issue_to_address>
**Release-line changelog branches collide**
When two release lines for the same member use the same target version, the changelog workflow names its head branch only from the target version, so both runs push to the same branch and the later run overwrites the earlier changes; a PR can then represent the wrong release line.
Include the release-line identity in the changelog head branch name and have the version guard validate that distinct branch.
Also at `.github/workflows/verify-group-version.yml:172`.
</issue_to_address>
### Comment 8
<location path=".github/scripts/prepare_release_line.py" line_range="317" />
<code_context>
+ target = branch_info(api, row["repo"], branch, missing=True)
+ if target is None:
+ try:
+ api(f"repos/{row['repo']}/git/refs", {"ref": f"refs/heads/{branch}", "sha": row["base"]})
+ except RuntimeError:
+ target = branch_info(api, row["repo"], branch, missing=True)
</code_context>
<issue_to_address>
**Changed config leaves stale branches**
When the DDE default branch changes release-line bases or mappings after the live-config comparison but before member refs are created, prepare continues using the earlier `lines` and `rows` snapshot, so it creates branches from bases no longer configured for the release line and leaves those branches in place.
Refresh and validate the live release-line configuration before creating member refs, aborting if it no longer matches the reviewed configuration.
Also at `.github/scripts/prepare_release_line.py:310-313`.
</issue_to_address>
### Comment 9
<location path=".github/scripts/prepare_release_line.py" line_range="355" />
<code_context>
+ observed = read_protection(api, repo, branch)
+ verify_preserved(observed, payload, app_source)
+ check_member_ready(api, repo, branch)
+ row.update(state="READY", detail="已读回验证入口、workflow 启用与实际有效保护")
+ except ReadinessError as error:
+ row.update(state=error.state, detail=str(error))
</code_context>
<issue_to_address>
**Ready branch no longer contains base**
When a writer changes a newly created member branch after the ancestry check and before protection is applied, `check_member_ready` does not recheck ancestry, so Prepare can report READY even though the branch no longer contains its configured base SHA.
Recheck that each branch descends from its configured base immediately before reporting it READY.
Also at `.github/scripts/prepare_release_line.py:324-331`.
</issue_to_address>
### Comment 10
<location path=".github/scripts/prepare_release_line.py" line_range="86" />
<code_context>
+ continue
+ if rule.get("blocksCreations") is None or rule.get("restrictsPushes") is None:
+ raise RuntimeError(f"{repo}:{branch} 创建保护权限未知")
+ if rule["blocksCreations"] and rule["restrictsPushes"]:
+ allowances = rule["pushAllowances"]
+ if allowances["totalCount"] != len(allowances["nodes"]) or not any(
</code_context>
<issue_to_address>
**Blocked branches are partially created**
When a matching classic protection rule blocks creations without also restricting pushes, `_may_create` skips a matching classic rule when `blocksCreations` is true but `restrictsPushes` is false, so the preflight accepts a branch the rule blocks. The later ref-creation loop can then fail after creating branches for earlier members, leaving a partial setup that requires a rerun.
Treat every matching `blocksCreations` rule as a creation restriction and verify the App can bypass it before any writes.
</issue_to_address>
### Comment 11
<location path=".github/workflows/templates-sync.yml" line_range="117" />
<code_context>
+ names[name].write_text(json.dumps(entries, ensure_ascii=False), encoding="utf-8")
+ PY
+
+ - name: Sync release-line update template
+ if: github.event_name == 'workflow_dispatch'
+ uses: linuxdeepin/action-sync@main
</code_context>
<issue_to_address>
**Develop dispatch targets master**
When a maintainer runs the synced workflow from a develop branch and accepts its default inputs, the synced caller keeps `base_branch` defaulted to `master` and passes it to the reusable workflow, which checks out that branch. A maintainer running the newly available workflow from a `develop/...` branch with the defaults therefore generates the changelog and PR for master instead of the selected release line.
Make the caller default its base branch to the selected workflow ref, or otherwise require an explicit branch for non-master runs.
</issue_to_address>
### Comment 12
<location path=".github/tests/test_prepare_release_line.py" line_range="72" />
<code_context>
+ files = self.github.files[repo, sha]
+ files.update({f".github/workflows/{name}": text
+ for name, text in self.github.templates.items()})
+ self.github.add_commit(repo, files, [sha], branch=branch, message="template sync")
+ self.sync_runs.insert(0, {
+ "id": 900 + self.sync_dispatches, "status": "completed", "conclusion": "success",
</code_context>
<issue_to_address>
**Mocked sync masks workflow failures**
When the real templates-sync workflow fails or skips its updates after dispatch, `test_template_sync_updates_existing_branch_without_pr` relies on the API stub to create commits with the template files at line 72, so the test passes even if the real templates-sync workflow fails to update any branch.
Test the templates-sync workflow's dispatch path and verify its actual sync behavior rather than having the API stub perform the sync.
</issue_to_address>
### Comment 13
<location path=".github/tests/test_verify_group_version.py" line_range="748" />
<code_context>
+ PR_HEAD_SHA='previous-head'):
+ with patch('builtins.open', mock_open(read_data=json.dumps({'number': 1}))):
+ with self.assertRaisesRegex(RuntimeError, 'PR 提交已变化'):
+ self.ns['main']()
+
+ def test_epoch_version_cannot_be_silently_downgraded(self):
</code_context>
<issue_to_address>
**Closed-PR test accepts no-op**
When the test runs with the closed-PR event fixture, `test_closed_pr_recomputes_only_remaining_open_prs` only calls `self.ns['main']()` at line 748 and makes no assertion, so a no-op `main` passes while the shared status remains stale.
Assert that `main` checks the remaining open PRs and publishes the expected status.
</issue_to_address>
### Comment 14
<location path=".github/scripts/prepare_release_line.py" line_range="1" />
<code_context>
+"""Prepare only the 17 G2 members from the merged, trusted dde configuration."""
+
+import copy
</code_context>
<issue_to_address>
**New files lack SPDX headers**
The new script, tests, and workflow have no SPDX header at the file start, so they do not identify the required copyright year or license.
Add a current-year SPDX copyright line and an appropriate SPDX license identifier to each new file, using the required comment prefix for its file type.
Also at `.github/tests/test_prepare_release_line.py:1`, `.github/tests/test_verify_group_version.py:1`, `.github/workflows/prepare-release-line.yml:1`.
</issue_to_address>
### Comment 15
<location path=".github/workflows/templates-sync.yml" line_range="17" />
<code_context>
templates-sync:
# limit push on linuxdeepin/.github master branch
- if: github.repository == 'linuxdeepin/.github' && github.ref == 'refs/heads/master'
+ if: github.repository == 'linuxdeepin/.github' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-latest
steps:
</code_context>
<issue_to_address>
**Modified workflows lack SPDX years**
Both modified workflows still have no SPDX copyright header, so their copyright years are not updated to reflect this change.
Add an SPDX copyright header with the current year and an appropriate license identifier to each modified workflow.
Also at `.github/workflows/verify-group-version.yml:36`.
</issue_to_address>| if name != GUARD_CONTEXT and name in checks and checks[name] != binding: | ||
| raise RuntimeError(f"同一必需检查 {name} 有冲突 App 绑定,不能覆盖现有规则") | ||
| checks[name] = binding | ||
| checks[GUARD_CONTEXT] = app_id |
There was a problem hiding this comment.
🟠 High · Guard status can be forged
When a contributor who can push a branch adds a pull_request workflow with statuses: write and posts success for the PR head, a PR-controlled workflow can use its GITHUB_TOKEN with statuses: write to post a successful group-version-guard status under the same GitHub Actions App identity required by this protection. The version guard is therefore bypassable, allowing an otherwise eligible PR with an invalid release version to satisfy this check.
Publish and require the guard result under a dedicated GitHub App identity whose credentials are unavailable to PR-controlled workflows.
Prompt for AI agents
In `.github/scripts/prepare_release_line.py` at line 177:
**Guard status can be forged**
When a contributor who can push a branch adds a `pull_request` workflow with `statuses: write` and posts success for the PR head, a PR-controlled workflow can use its `GITHUB_TOKEN` with `statuses: write` to post a successful `group-version-guard` status under the same GitHub Actions App identity required by this protection. The version guard is therefore bypassable, allowing an otherwise eligible PR with an invalid release version to satisfy this check.
Publish and require the guard result under a dedicated GitHub App identity whose credentials are unavailable to PR-controlled workflows.| reviews.pop("url", None) | ||
| if "dismissal_restrictions" in reviews: | ||
| reviews["dismissal_restrictions"] = _actors(reviews["dismissal_restrictions"]) | ||
| reviews["bypass_pull_request_allowances"] = {"users": [], "teams": [], "apps": []} |
There was a problem hiding this comment.
🟡 Medium · Review bypass access disappears
When the source branch has configured pull-request review bypass allowances, protection_payload replaces the existing user, team, and app allowances with empty lists, so applying protection removes those bypass rights and disrupts the usual merge path.
Preserve the source branch’s existing pull-request bypass allowances in the protection payload.
Prompt for AI agents
In `.github/scripts/prepare_release_line.py` at line 148:
**Review bypass access disappears**
When the source branch has configured pull-request review bypass allowances, `protection_payload` replaces the existing user, team, and app allowances with empty lists, so applying protection removes those bypass rights and disrupts the usual merge path.
Preserve the source branch’s existing pull-request bypass allowances in the protection payload.| if any(content(api, row["repo"], f".github/workflows/{name}", base, missing=True) != text | ||
| for row in rows for base in dict.fromkeys((row["default"], branch)) | ||
| for name, text in row["templates"].items()): | ||
| sync_templates(api, coordinator.split("/")[0]) |
There was a problem hiding this comment.
🟡 Medium · Concurrent sync aborts preparation
When two release-line preparations dispatch template synchronization before the first sync completes, the shared templates-sync concurrency group cancels the in-progress run, and sync_templates treats the canceled run as a failure when it appears in the poll; Prepare then exits after creating branches, leaving setup incomplete.
Prevent one release-line sync dispatch from canceling another, or make the polling logic wait for the replacement run before treating cancellation as a failure.
Also at .github/workflows/prepare-release-line.yml:20, .github/scripts/prepare_release_line.py:214-219, .github/scripts/prepare_release_line.py:221.
Prompt for AI agents
In `.github/scripts/prepare_release_line.py` at line 331:
**Concurrent sync aborts preparation**
When two release-line preparations dispatch template synchronization before the first sync completes, the shared templates-sync concurrency group cancels the in-progress run, and `sync_templates` treats the canceled run as a failure when it appears in the poll; Prepare then exits after creating branches, leaving setup incomplete.
Prevent one release-line sync dispatch from canceling another, or make the polling logic wait for the replacement run before treating cancellation as a failure.
Also at `.github/workflows/prepare-release-line.yml:20`, `.github/scripts/prepare_release_line.py:214-219`, `.github/scripts/prepare_release_line.py:221`.| names[name].write_text(json.dumps(entries, ensure_ascii=False), encoding="utf-8") | ||
| PY | ||
|
|
||
| - name: Sync release-line update template |
There was a problem hiding this comment.
🟠 High · Develop dispatch targets master
When a maintainer runs the synced workflow from a develop branch and accepts its default inputs, the synced caller keeps base_branch defaulted to master and passes it to the reusable workflow, which checks out that branch. A maintainer running the newly available workflow from a develop/... branch with the defaults therefore generates the changelog and PR for master instead of the selected release line.
Make the caller default its base branch to the selected workflow ref, or otherwise require an explicit branch for non-master runs.
Prompt for AI agents
In `.github/workflows/templates-sync.yml` at line 117:
**Develop dispatch targets master**
When a maintainer runs the synced workflow from a develop branch and accepts its default inputs, the synced caller keeps `base_branch` defaulted to `master` and passes it to the reusable workflow, which checks out that branch. A maintainer running the newly available workflow from a `develop/...` branch with the defaults therefore generates the changelog and PR for master instead of the selected release line.
Make the caller default its base branch to the selected workflow ref, or otherwise require an explicit branch for non-master runs.85be53f to
ae1df0a
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['建议为 _ancestors、_installation_repositories、_creation_rules 等内部函数补充简短注释说明参数含义'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['建议将 prepare() 函数拆分为 _dry_run_check 和 _execute 两个子函数', '建议为缺少 docstring 的函数补充简短说明'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['建议持续保持当前的输入校验和防御性编程水平'] 💡 改进建议代码示例# 建议:将 prepare() 函数拆分为 dry_run 和 execute 两个阶段
def _dry_run_check(api, rows, branch):
"""Dry-run: verify each member is ready without making changes."""
for row in rows:
try:
if row["operation"] == "create":
raise ReadinessError("BRANCH_MISSING", f"将从固定基准 {row['base']} 创建")
if any(content(api, row["repo"], f".github/workflows/{name}", base, missing=True) != text
for base in dict.fromkeys((row["default"], branch))
for name, text in row["templates"].items()):
raise ReadinessError("TEMPLATE_MISSING", "正式运行将调用统一模板同步")
check_member_ready(api, row["repo"], branch)
row["state"] = "READY"
except ReadinessError as error:
row.update(state=error.state, detail=str(error))
except Exception as error:
row.update(state="PROTECTION_FAILED", detail=str(error))
_report(rows)
return rows
def _execute_create(api, rows, branch):
"""Execute: create branches, sync templates, and configure protection."""
for row in rows:
try:
target = branch_info(api, row["repo"], branch, missing=True)
if target is None:
try:
api(f"repos/{row['repo']}/git/refs",
{"ref": f"refs/heads/{branch}", "sha": row["base"]})
except RuntimeError:
target = branch_info(api, row["repo"], branch, missing=True)
if target is None:
raise
target = branch_info(api, row["repo"], branch)
_ancestors(api, row["repo"], row["base"], target["commit"]["sha"])
except Exception as error:
row.update(operation="conflict", detail=str(error))
_report(rows)
raise RuntimeError("分支创建中断;保留所有已创建分支,重跑只补缺失项") from error本报告由 AI 代码审查工具自动生成 |
af1246e to
9cf2d18
Compare
1. Add release-line preparation workflows with fixed base SHAs. 2. Keep member workflows on the existing base_branch input. 3. Validate release-line mappings, guard records, templates, and protections. 4. Reuse one template sync and preserve app-bound required checks. Log: Add isolated G2 release-line preparation and verification. Influence: Enables independent G2 release lines. feat(ci): 支持独立 G2 发布线 1. 新增发布线准备流程,并固定成员基准 SHA。 2. 成员 workflow 继续复用 base_branch 输入。 3. 校验发布线映射、guard 记录、模板与分支保护。 4. 复用统一模板同步并保留 App 绑定必需检查。 Log: 新增隔离的 G2 发布线准备与校验能力。 PMS: TASK-398637 Influence: 支持多条 G2 发布线独立推进。
9cf2d18 to
90115d0
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: BLumia, MyLeeJiEun The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
背景
G2 当前只有一套组版本和发布分支,无法让多个版本线并行准备、发布和记录状态。本 PR 为成员侧提供独立发布线所需的 workflow 入口、模板同步和实时保护校验。
变更
Prepare release line,按已合并的发布线配置创建固定 SHA 成员分支。templates-sync,一次同步 17 个成员的发版与 guard 模板,不再创建逐成员、逐分支的模板 PR。base.ref唯一反查 G2 发布线,并校验对应发布记录。master、develop/.+与release/.+。group-version-guard绑定到受保护的发布 GitHub App。验证
git diff --check通过。配对 PR:linuxdeepin/dde#7
Summary by Sourcery
Enable independent G2 release lines with automated member-branch preparation, shared template synchronization, and release-line-aware workflow and protection validation.
New Features:
Bug Fixes:
Enhancements:
CI: