Skip to content

Commit 3a1b640

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 854615f commit 3a1b640

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
@@ -212,6 +212,41 @@ jobs:
212212
--latest=legacy
213213
echo "Created release $TAG"
214214
215+
- name: Unlock main branch
216+
if: steps.changesets.outputs.hasChangesets == 'false' && github.ref_name == 'main'
217+
env:
218+
ADMIN_TOKEN: ${{ secrets.RELEASE_ADMIN_TOKEN }}
219+
run: |
220+
set -euo pipefail
221+
if [ -z "${ADMIN_TOKEN:-}" ]; then
222+
echo "::warning::RELEASE_ADMIN_TOKEN not configured; skipping main branch unlock"
223+
exit 0
224+
fi
225+
226+
RULE_ID=$(GITHUB_TOKEN="$ADMIN_TOKEN" gh api graphql \
227+
-f query='query($owner: String!, $repo: String!) {
228+
repository(owner: $owner, name: $repo) {
229+
branchProtectionRules(first: 50) { nodes { id pattern } }
230+
}
231+
}' \
232+
-F owner="${GITHUB_REPOSITORY%/*}" \
233+
-F repo="${GITHUB_REPOSITORY#*/}" \
234+
--jq '.data.repository.branchProtectionRules.nodes[] | select(.pattern == "main") | .id')
235+
236+
if [ -z "$RULE_ID" ]; then
237+
echo "::warning::No branch protection rule found for main; skipping unlock"
238+
exit 0
239+
fi
240+
241+
GITHUB_TOKEN="$ADMIN_TOKEN" gh api graphql \
242+
-f query='mutation($id: ID!) {
243+
updateBranchProtectionRule(input: { branchProtectionRuleId: $id, lockBranch: false }) {
244+
branchProtectionRule { lockBranch }
245+
}
246+
}' \
247+
-f id="$RULE_ID" >/dev/null
248+
echo "Unlocked main branch"
249+
215250
# Manual/Cron release job - runs on schedule or manual trigger with tag
216251
manual-cron-release:
217252
name: Manual & Cron Release

0 commit comments

Comments
 (0)