-
Notifications
You must be signed in to change notification settings - Fork 4
Add capability-development branch protection CI #327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
amit-momin
merged 5 commits into
main
from
cre/add-capability-development-branch-protection-ci
Mar 26, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4396356
Add capability-development branch protection ci
amit-momin 64301fe
Upgraded checkout action to major version tag
amit-momin 3f6b3c2
Updated validation to only occur when target branch is main
amit-momin a72b2e4
Addressed feedback
amit-momin d508e43
Merge branch 'main' into cre/add-capability-development-branch-protec…
amit-momin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| name: CRE branch protection | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, synchronize] | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: {} | ||
|
|
||
| jobs: | ||
| check-cre-target-branch: | ||
| permissions: | ||
| contents: read | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Enforce CRE changes target capabilities-development | ||
| env: | ||
| TARGET_BRANCH: ${{ github.base_ref }} | ||
| run: | | ||
| git fetch origin "${TARGET_BRANCH}" --quiet 2>/dev/null || true | ||
|
|
||
| CRE_CHANGED=$(git diff --name-only "origin/${TARGET_BRANCH}...HEAD" -- cre/) | ||
|
|
||
| if [[ -z "$CRE_CHANGED" ]]; then | ||
| echo "No cre/ files modified. Skipping branch check." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "The following cre/ files are modified in this PR:" | ||
| echo "$CRE_CHANGED" | ||
| echo "" | ||
|
|
||
| echo "PR targets 'main' and contains cre/ changes." | ||
| echo "Verifying all CRE-modifying commits are cherry-picks from capabilities-development..." | ||
| echo "" | ||
|
|
||
| if ! git fetch origin capabilities-development --quiet 2>/dev/null; then | ||
| echo "::error::Could not fetch the 'capabilities-development' branch. Ensure it exists on the remote." | ||
| echo "::error::CRE changes must target 'capabilities-development' or be cherry-picks of commits already in that branch." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Precompute patch-ids for all CRE-touching commits in capabilities-development | ||
| CAP_PATCH_IDS=$(mktemp) | ||
| git log --format=%H origin/capabilities-development -- cre/ | while read -r cap_commit; do | ||
| git show "$cap_commit" -- cre/ | git patch-id --stable 2>/dev/null | awk '{print $1}' | ||
| done | sort -u > "$CAP_PATCH_IDS" | ||
|
|
||
| CAP_COUNT=$(wc -l < "$CAP_PATCH_IDS" | tr -d ' ') | ||
| echo "Found ${CAP_COUNT} unique CRE patch-ids in capabilities-development." | ||
| echo "" | ||
|
|
||
| # Check each PR commit that touches cre/ | ||
| FAILURES=$(mktemp) | ||
| git log --format=%H "origin/${TARGET_BRANCH}..HEAD" -- cre/ | while read -r commit; do | ||
| PATCH_ID=$(git show "$commit" -- cre/ | git patch-id --stable 2>/dev/null | awk '{print $1}') | ||
|
|
||
| if [ -z "$PATCH_ID" ]; then | ||
| continue | ||
| fi | ||
|
|
||
| if ! grep -qF "$PATCH_ID" "$CAP_PATCH_IDS"; then | ||
| git log -1 --format='%h %s' "$commit" >> "$FAILURES" | ||
| fi | ||
| done | ||
|
|
||
| if [ -s "$FAILURES" ]; then | ||
| echo "::error::The following commits modify cre/ but are not cherry-picks of commits in capabilities-development:" | ||
| echo "" | ||
| while IFS= read -r line; do | ||
| echo " - ${line}" | ||
| done < "$FAILURES" | ||
| echo "" | ||
| echo "::error::CRE changes must first be merged into 'capabilities-development'. PRs to other branches may only include cherry-picks of commits already in that branch." | ||
| rm -f "$CAP_PATCH_IDS" "$FAILURES" | ||
| exit 1 | ||
| fi | ||
|
|
||
| rm -f "$CAP_PATCH_IDS" "$FAILURES" | ||
| echo "All CRE-modifying commits are verified cherry-picks from capabilities-development." | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.