Skip to content

Comments

chore: 支持所有非 main 分支的 CI/CD 构建#76

Merged
ding113 merged 1 commit intomainfrom
dev
Nov 3, 2025
Merged

chore: 支持所有非 main 分支的 CI/CD 构建#76
ding113 merged 1 commit intomainfrom
dev

Conversation

@ding113
Copy link
Owner

@ding113 ding113 commented Nov 3, 2025

Summary

  • 将 CI/CD workflow 从仅支持 dev 分支扩展到所有非 main 分支
  • 实现智能分支名处理和 Docker tag 生成策略
  • 为不同分支生成独立的测试镜像,方便并行开发

主要变更

1. 触发条件优化

  • 从仅触发 dev 分支改为触发所有分支(排除 main
  • 支持 feature、fix、hotfix 等任意分支命名

2. 智能 Tag 生成

  • dev 分支:保持原有策略 (dev + dev-{sha})
  • 其他分支:生成 {branch-name} + {branch-name}-{sha} 两个 tag
  • 自动处理分支名中的特殊字符(转小写、替换 /-

3. Docker 镜像示例

# dev 分支(不变)
ghcr.io/owner/claude-code-hub:dev
ghcr.io/owner/claude-code-hub:dev-abc1234

# feature/api-v2 分支(新增)
ghcr.io/owner/claude-code-hub:feature-api-v2
ghcr.io/owner/claude-code-hub:feature-api-v2-xyz5678

Test plan

  • 修改 workflow 配置文件
  • 验证分支名处理逻辑
  • 确保 tag 生成符合 Docker 命名规范
  • 推送后验证 GitHub Actions 是否正常触发

影响范围

  • 仅修改 .github/workflows/dev.yml
  • 不涉及核心代码逻辑
  • 向后兼容,dev 分支行为不变

🤖 Generated with Claude Code

@ding113 ding113 merged commit d903c22 into main Nov 3, 2025
4 checks passed
@claude
Copy link
Contributor

claude bot commented Nov 3, 2025

⚠️ 严重问题:违反分支管理规则

根据项目的 CLAUDE.md 中定义的 Git 工作流铁律:

永远不要创建指向 main 的 PR - 所有 PR 必须指向 dev 分支

当前问题:此 PR 的目标分支是 main,应该是 dev

标准工作流

创建新分支 → 提交 → 推送 → PR 到 dev → (测试通过后) → 合并到 main

建议修正步骤

  1. 关闭当前 PR
  2. 重新创建 PR 到 dev 分支:
    gh pr create --base dev --title "chore: 支持所有非 main 分支的 CI/CD 构建" --body "..."

代码审查(功能层面)

虽然目标分支有问题,但代码本身的实现质量很好:

优点

  • 分支名处理逻辑完善(转小写、特殊字符替换)
  • Tag 生成策略合理(dev 分支保持兼容,其他分支独立命名)
  • 向后兼容 dev 分支原有行为
  • 代码注释清晰

⚠️ 潜在问题

  1. 触发条件语法branches: - '**'- '!main' 的组合在某些 GitHub Actions 版本中可能不生效
    • 建议改为:branches-ignore: [main]
  2. 格式化自动提交:在非 dev 分支也会自动提交,可能导致意外的 commit
  3. 缺少错误处理:分支名处理逻辑没有处理边界情况(如空分支名)

建议改进

on:
  push:
    branches-ignore:
      - main  # 更可靠的排除语法

请先修正目标分支问题,再考虑功能改进。

@claude claude bot added the invalid This doesn't seem right label Nov 3, 2025
Comment on lines 5 to +6
branches:
- dev
- '**' # 匹配所有分支
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ 触发条件语法问题

这种写法在某些 GitHub Actions 版本中可能不生效('**''!main' 的组合)。

建议改为更可靠的语法

Suggested change
branches:
- dev
- '**' # 匹配所有分支
branches-ignore:
- main

这样更简洁且被广泛支持。

# 获取分支名(去掉 refs/heads/ 前缀)
BRANCH_NAME="${GITHUB_REF#refs/heads/}"

# 处理分支名:转小写,替换 / 为 -,只保留字母数字和连字符
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 建议添加边界情况处理

当前分支名处理逻辑缺少边界情况检查:

Suggested change
# 处理分支名:转小写,替换 / 为 -,只保留字母数字和连字符
# 处理分支名:转小写,替换 / 为 -,只保留字母数字和连字符
SAFE_BRANCH_NAME=$(echo "$BRANCH_NAME" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9-]/-/g' | sed 's/--*/-/g' | sed 's/^-//;s/-$//')
# 验证结果不为空
if [ -z "$SAFE_BRANCH_NAME" ]; then
echo "Error: Invalid branch name after sanitization"
exit 1
fi

防止特殊分支名导致空 tag。

Comment on lines 86 to +90
echo "No changes to commit"
else
# 提交格式化后的代码
git commit -m "chore: format code (dev-${{ steps.commit.outputs.short_sha }})"
git push origin dev
git commit -m "chore: format code (${{ steps.branch_info.outputs.versioned_tag }})"
git push origin ${{ steps.branch_info.outputs.branch_name }}
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 潜在的自动提交问题

在所有非 main 分支都自动提交格式化修改,可能导致意外的 commit 历史污染。

建议

  1. 仅在 dev 分支自动提交
  2. 其他分支只检查格式,不自动修复
Suggested change
echo "No changes to commit"
else
# 提交格式化后的代码
git commit -m "chore: format code (dev-${{ steps.commit.outputs.short_sha }})"
git push origin dev
git commit -m "chore: format code (${{ steps.branch_info.outputs.versioned_tag }})"
git push origin ${{ steps.branch_info.outputs.branch_name }}
else
# 仅在 dev 分支自动提交格式化
if [ "${{ steps.branch_info.outputs.branch_name }}" = "dev" ]; then
git commit -m "chore: format code (${{ steps.branch_info.outputs.versioned_tag }})"
git push origin ${{ steps.branch_info.outputs.branch_name }}
else
echo "::warning::Found formatting issues in non-dev branch. Please run 'pnpm format' locally."
exit 1
fi

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

Labels

invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant