ci: do not run cd when a branch is created - #1064
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The change is minimal, syntactically correct for job-level gating, and effectively prevents unintended publishes on branch creation while preserving normal pushes and manual runs.
Pull request overview
This PR prevents the CD workflow from publishing when a release/** branch is created (i.e., the first push that creates the remote ref), which can otherwise accidentally trigger a publish for an already-released version (or worse, publish a version bump from a branch that wasn’t intentionally treated as a release).
Changes:
- Add a job-level gate to skip the CD pipeline when the
pushevent indicates the ref was newly created (github.event.created == true). - Rely on the existing
needschain (buildneedslint,pypi-publishneedsbuild) so skippinglintskips the entire publish flow. - Keep
workflow_dispatchbehavior unchanged (missingcreatedevaluates falsy, so the condition passes).
File summaries
| File | Description |
|---|---|
| .github/workflows/cd.yml | Adds an if: ${{ !github.event.created }} gate to prevent CD from running on branch-creation pushes. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|



CD triggers on pushes to
mainandrelease/**filtered topyproject.toml. Creating arelease/*branch at a commit that touchedpyproject.tomlis a push that can match that filter, so the branch creation itself starts a publish run for a version that was already released.Today PyPI rejects the duplicate upload, so the run just goes red. It is not harmless in every case: if the base commit's version bump was never actually published, branch creation would publish it from a branch nobody treated as a release. The
pypienvironment has no protection rules or deployment branch policy, so there is no second gate.Gate the CD entry job on
!github.event.created.buildneedslintandpypi-publishneedsbuild, so skippinglintskips the chain. Manualworkflow_dispatchruns are unaffected, since the property is absent there and evaluates as falsy.Merging a hotfix PR into a release branch is a normal push with commits, so
createdis false and the publish still runs as intended.