Skip to content

ci(requirements-sync): enable auto-merge on nightly sync PRs - #876

Closed
SarahLittlejohn wants to merge 1 commit into
masterfrom
ci/requirements-sync-automerge
Closed

ci(requirements-sync): enable auto-merge on nightly sync PRs#876
SarahLittlejohn wants to merge 1 commit into
masterfrom
ci/requirements-sync-automerge

Conversation

@SarahLittlejohn

@SarahLittlejohn SarahLittlejohn commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Enables auto-merge on the nightly requirements-sync PRs so they land on master without manual clicking, now that the duplicate-migration dedup issue has been fixed.

Adds a step 8 to the requirements-sync.yml Claude prompt: after the sync PR is created or updated, run gh pr merge --auto --squash --delete-branch.

Behaviour

  • Waits for checks — auto-merge only completes once required status checks pass, including the existing independent build & integrity gate. A migration that fails the build or PRAGMA integrity_check / foreign_key_check can never merge itself.
  • No blind merge — immediate and --admin merges are explicitly disallowed in the prompt.
  • Bash(gh:*) is already in --allowedTools, so no tool-permission change was needed.

Prerequisites (repo settings)

For --auto to actually gate on checks, the repo needs:

  1. Allow auto-merge enabled in Settings → General.
  2. A branch protection rule on master with the sync workflow's checks marked as required.

Without required checks, --auto merges as soon as GitHub allows (effectively immediately).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Updated the requirements synchronisation workflow to automatically enable squash-and-merge after required checks pass.
    • If auto-merge cannot be enabled, the pull request remains open and the workflow reports the failure.

Add a step 8 to the requirements-sync prompt instructing Claude to enable
auto-merge (--auto --squash --delete-branch) on the sync PR after it is
created or updated. Auto-merge only completes once the PR's required status
checks (including the independent build & integrity gate) pass, so a bad
migration can never merge itself. Immediate/admin merge is explicitly
disallowed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The requirements-sync workflow prompt now instructs Claude to enable squash auto-merge for the synchronisation pull request, wait for required checks, and report failures without force-merging.

Changes

Requirements sync workflow

Layer / File(s) Summary
Auto-merge workflow instruction
.github/workflows/requirements-sync.yml
Adds the gh pr merge --auto --squash --delete-branch instruction, requiring checks to pass and leaving the pull request open if auto-merge fails.

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarises the main change: enabling auto-merge for nightly requirements-sync PRs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/requirements-sync-automerge

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 56ccd708-093b-4a41-bf3c-225bde793ab0

📥 Commits

Reviewing files that changed from the base of the PR and between a02d03b and bcc6e37.

📒 Files selected for processing (1)
  • .github/workflows/requirements-sync.yml

Comment on lines +196 to +199
Auto-merge only completes when the required checks are green, so a migration that
fails the build/integrity gate will never merge. Do not attempt an immediate or
admin merge; if enabling auto-merge fails (e.g. it is not enabled on the repo),
report that in the run output and leave the PR open rather than force-merging.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

rg -n 'schedule:|pull_request:|merge_group:|requirements:build|integrity_check|foreign_key_check' .github/workflows

repo=$(gh repo view --json nameWithOwner --jq '.nameWithOwner')
gh api "repos/$repo" --jq '{allow_auto_merge,delete_branch_on_merge}'
gh api "repos/$repo/branches/master/protection/required_status_checks" \
  --jq '{contexts,checks}'

Repository: hmcts/cath-service

Length of output: 1721


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "== workflow files =="
find .github/workflows -maxdepth 1 -type f | sort

echo
echo "== triggers and relevant gate references =="
for f in .github/workflows/*.yml .github/workflows/*.yaml; do
  [ -e "$f" ] || continue
  echo "--- $f"
  sed -n '1,5p;200,230p' "$f" | nl -ba
done

echo
echo "== requirements-sync around gate =="
sed -n '160,235p' .github/workflows/requirements-sync.yml | nl -ba

echo
echo "== package scripts =="
if [ -f package.json ]; then
  node - <<'JS'
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json','utf8'));
console.log(JSON.stringify(pkg.scripts || {}, null, 2));
JS
fi

echo
echo "== gh auth status =="
gh auth status 2>&1 | head -20 || true

Repository: hmcts/cath-service

Length of output: 1867


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "== workflow files count =="
find .github/workflows -maxdepth 1 -type f | wc -l
find .github/workflows -maxdepth 1 -type f | sort

echo
echo "== all workflow triggers and job names =="
for f in .github/workflows/*.yml .github/workflows/*.yaml; do
  [ -e "$f" ] || continue
  echo "--- $f"
  sed -n '1,5p' "$f"
  grep -nE '^\s+[A-Za-z].*:' "$f" | sed -n '1,40p'
done

echo
echo "== requirements-sync triggers and gate section =="
sed -n '1,40p' .github/workflows/requirements-sync.yml
sed -n '160,235p' .github/workflows/requirements-sync.yml

echo
echo "== package scripts if present =="
if [ -f package.json ]; then
  node - <<'JS'
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json','utf8'));
console.log(JSON.stringify(pkg.scripts || {}, null, 2));
JS
fi

echo
echo "== repository API summary =="
repo="$(gh repo view --json nameWithOwner --jq '.nameWithOwner')"
gh api "repos/$repo?fields=allow_auto_merge,default_branch,delete_branch_on_merge,has_issues,has_projects,description" --jq . || true
echo "protected branches list attempted:"
gh api "repos/$repo/branches" --jq '.[].name' 2>/dev/null || true

Repository: hmcts/cath-service

Length of output: 50374


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "== requirements-sync full sync job and enable-auto-merge section =="
sed -n '1,240p' .github/workflows/requirements-sync.yml

Repository: hmcts/cath-service

Length of output: 12501


🌐 Web query:

GitHub Actions pull_request event runs workflow from pull request head branch default branch head

💡 Result:

When a workflow is triggered by the pull_request event, it does not run against the head branch directly in the way a push event does [1][2]. Instead, GitHub Actions creates a temporary merge branch—a virtual ref that represents the PR's head branch merged into the base branch [3]. Key details regarding the execution environment for the pull_request event: 1. Execution Ref: The GITHUB_REF for a pull_request event (unless it is a pull_request_target event) is set to refs/pull/<pr_number>/merge, which is the merge branch [3]. 2. Commit SHA: The default GITHUB_SHA for this event corresponds to the last merge commit of this temporary merge branch [1][2]. 3. Head Access: If you require the SHA of the actual head commit of the source branch (the pull request head), you must explicitly use the github.event.pull_request.head.sha context [1][2]. 4. Branch Contexts: You can access the specific branch names using context variables: - github.head_ref: The name of the source (head) branch of the pull request [4][3]. - github.base_ref: The name of the target (base) branch of the pull request [4][3]. These contexts (github.head_ref and github.base_ref) are only available when the workflow is triggered by pull_request or pull_request_target events [4][5][3]. If you need to run a job conditionally based on the head branch name, you can use these variables in an if conditional within your workflow file [1][2].

Citations:


Make the build and integrity gate a required PR check.

This scheduled workflow runs against the default branch before enabling auto-merge, so the gate cannot block a bad PR head here. Move it into a pull_request/merge_group workflow and configure the job name as a required status check so gh pr merge --auto actually prevents a failed migration from landing.

@github-actions

Copy link
Copy Markdown
Contributor

🎭 Playwright E2E Test Results

84 tests   52 ✅  3m 47s ⏱️
33 suites  32 💤
 1 files     0 ❌

Results for commit bcc6e37.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant