关于 gating-production-deploys
面向 PostHog 仓库维护者的 GitHub Actions 部署门控指南,规定生产镜像推送和部署触发应依据 CD_DEPLOY_ENABLED 控制,并区分不应门控的工作流。
主要功能
- 01限定生产镜像推送的门控范围
- 02限制 Charts 部署派发
- 03提供仓库变量条件表达式
- 04区分发布与 PR 验证工作流
- 05列出相关工作流示例
适用场景
- 01配置 master 推送时的生产部署
- 02检查 GitHub Actions 是否会误触发部署
- 03保留发布流程和 PR 构建的正常运行
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ posthog/ posthog --skill gating-production-deploys安装后在 Claude Code 中输入/gating-production-deploys确认已加载。
详细介绍
对生产构建和部署进行门控
容器镜像推送和 Charts 部署分发由一个规范部署仓库运行,通过 CD_DEPLOY_ENABLED 变量选择。对每个此类步骤进行门控,否则它会从错误的位置发布/部署。
门控这些在 push 到 master / schedule / workflow_dispatch 上运行的步骤:
- 生产标签容器镜像推送,以及
- 向
PostHog/charts发送commit_state_update分发(以及其部署者令牌步骤)。
不要门控:
- 发布/分发工作流 — GitHub release、npm、crate、Homebrew(例如
build-phrocs.yml、release-cli.yml)。它们从公开位置发布;保持原样。 pull_request验证构建(门控它们会破坏贡献者 CI)。- 变更检测/设置作业(仅使用组织检查,不要使用该变量)。
测试标准是“推送生产镜像或触发部署”——而不是“在 master 上构建”。
门控
if: github.repository_owner == 'PostHog' && vars.CD_DEPLOY_ENABLED == 'true'
使用此方法,而不是硬编码 github.repository == 'PostHog/posthog'。
模式
# whole job is the deploy/push (no PR builds) — gate the job:
if: github.repository_owner == 'PostHog' && vars.CD_DEPLOY_ENABLED == 'true'
# deploy job/step already keyed to master — add the gate:
if: github.repository_owner == 'PostHog' && vars.CD_DEPLOY_ENABLED == 'true' && github.ref == 'refs/heads/master'
# build job that also serves PRs — gate only the master arm of its `if`:
(github.event_name == 'push' && github.ref == 'refs/heads/master' && needs.changes.outputs.files == 'true'
&& github.repository_owner == 'PostHog' && vars.CD_DEPLOY_ENABLED == 'true')
# push step, master-only:
push: ${{ github.ref == 'refs/heads/master' && vars.CD_DEPLOY_ENABLED == 'true' }}
# push step, `push: true` (also pushes on PR for validation):
push: ${{ github.event_name == 'pull_request' || vars.CD_DEPLOY_ENABLED == 'true' }}
# reusable that pushes — add a `push` boolean input (default true), pass from caller:
# with: { push: ${{ github.event_name == 'pull_request' || vars.CD_DEPLOY_ENABLED == 'true' }} }
在合并之前应在需要发布的仓库上设置 CD_DEPLOY_ENABLED,否则 master 推送会跳过构建/部署。使用 actionlint 进行 lint。
示例:container-images-cd.yml(整个作业);cd-mcp-image.yml、livestream-docker-image.yml、cd-sandbox-base-image.yml(混合 PR+master);rust-docker-build.yml + _rust-build-images.yml(可复用的 push 输入)。反例,未门控:build-phrocs.yml。
评论
支持 Markdown