Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

CI: restrict manual publish dispatch to release refs

Louis Choquel7f2b98d7ab0b
diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml
index f835ac79a..5caed604e 100644
--- a/.github/workflows/publish-pypi.yml
+++ b/.github/workflows/publish-pypi.yml
@@ -19,6 +19,24 @@ jobs:
runs-on: ubuntu-latest
steps:
+ # A manual run can target any ref that contains this workflow, and every
+ # job below builds and publishes whatever it checks out — so an unguarded
+ # dispatch could push a feature branch to production PyPI and tag it.
+ # guard-branches.yml cannot help: it only runs on pull_request_target.
+ # Restrict manual runs to the refs a publish can legitimately come from;
+ # pull_request runs are already constrained by their base branch.
+ - name: Verify the dispatched ref may publish
+ if: github.event_name == 'workflow_dispatch'
+ env:
+ REF: ${{ github.ref }}
+ run: |
+ echo "Dispatched from $REF"
+ if [[ "$REF" != "refs/heads/main" ]] \
+ && [[ ! "$REF" =~ ^refs/heads/release/v[0-9]+\.[0-9]+\.[0-9]+$ ]] \
+ && [[ ! "$REF" =~ ^refs/heads/pre-release/v ]]; then
+ echo "::error::Manual publish is allowed only from main, release/vX.Y.Z or pre-release/v*. Got: $REF"
+ exit 1
+ fi
- uses: actions/checkout@v4
with:
persist-credentials: false