Skip to content

Commit 6780212

Browse files
isaacroldanclaude
andcommitted
Automatically unlock main branch after release publishes
Adds a final step in the changeset-release job that flips the lockBranch field on the main branch protection rule back to false once a release publishes successfully. The pre-release lock is still applied manually; only the unlock is automated for now. The step requires a RELEASE_ADMIN_TOKEN secret (PAT or GitHub App installation token with admin permissions on branch protection). If the secret is not configured, the step warns and skips so it never blocks a release. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent fb9e6f5 commit 6780212

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,41 @@ jobs:
170170
--latest=legacy
171171
echo "Created release $TAG"
172172
173+
- name: Unlock main branch
174+
if: steps.changesets.outputs.hasChangesets == 'false' && github.ref_name == 'main'
175+
env:
176+
ADMIN_TOKEN: ${{ secrets.RELEASE_ADMIN_TOKEN }}
177+
run: |
178+
set -euo pipefail
179+
if [ -z "${ADMIN_TOKEN:-}" ]; then
180+
echo "::warning::RELEASE_ADMIN_TOKEN not configured; skipping main branch unlock"
181+
exit 0
182+
fi
183+
184+
RULE_ID=$(GITHUB_TOKEN="$ADMIN_TOKEN" gh api graphql \
185+
-f query='query($owner: String!, $repo: String!) {
186+
repository(owner: $owner, name: $repo) {
187+
branchProtectionRules(first: 50) { nodes { id pattern } }
188+
}
189+
}' \
190+
-F owner="${GITHUB_REPOSITORY%/*}" \
191+
-F repo="${GITHUB_REPOSITORY#*/}" \
192+
--jq '.data.repository.branchProtectionRules.nodes[] | select(.pattern == "main") | .id')
193+
194+
if [ -z "$RULE_ID" ]; then
195+
echo "::warning::No branch protection rule found for main; skipping unlock"
196+
exit 0
197+
fi
198+
199+
GITHUB_TOKEN="$ADMIN_TOKEN" gh api graphql \
200+
-f query='mutation($id: ID!) {
201+
updateBranchProtectionRule(input: { branchProtectionRuleId: $id, lockBranch: false }) {
202+
branchProtectionRule { lockBranch }
203+
}
204+
}' \
205+
-f id="$RULE_ID" >/dev/null
206+
echo "Unlocked main branch"
207+
173208
# Manual/Cron release job - runs on schedule or manual trigger with tag
174209
manual-cron-release:
175210
name: Manual & Cron Release

0 commit comments

Comments
 (0)