-
Notifications
You must be signed in to change notification settings - Fork 13
Add workflow to validate branch ancestry #40
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
base: dev
Are you sure you want to change the base?
Conversation
6fd5512 to
f22c842
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This workflow prevents branches containing pre-initialization git history from being merged into dev/main, protecting against re-introduction of sensitive data that was removed during repository re-initialization. ## How It Works The workflow runs on every push and pull request, performing these steps: 1. Checks out full git history (fetch-depth: 0) 2. Finds ALL root commits of the branch using git rev-list --max-parents=0 3. Validates each root commit against a list of valid initialization commits 4. FAILS if ANY root commit doesn't match the valid list 5. PASSES if all root commits are valid Valid root commit: 97e73c5 ## What Happens When It Runs **Valid Branch (created from current dev/main):** - Workflow passes with ✅ - Branch can proceed to merge (if other checks pass) **Invalid Branch (contains old git history):** - Workflow FAILS with clear error message - Shows which root commits are invalid - Provides step-by-step remediation instructions - Branch CANNOT be merged if branch protection is configured ## Security Features - Multi-root detection: Handles merged branches with multiple histories - Empty line handling: Robust parsing of git output - Clear error messages: Developers know exactly how to fix the issue - Minimal permissions: Only requires contents:read and pull-requests:read - No tokens needed: Uses built-in GITHUB_TOKEN automatically - Timeout protection: 10-minute limit prevents runaway workflows ## Branch Protection Configuration Required After merging, these branch protection rules MUST be configured to actually block invalid branches from merging: ### For 'dev' branch: 1. Go to: Settings → Branches → Edit 'dev' protection rule 2. Under 'Require status checks to pass before merging' 3. Click 'Add status check' 4. Search for and add: 'Validate Clean History' 5. Save changes ### For 'main' branch: 1. Go to: Settings → Branches → Edit 'main' protection rule 2. Under 'Require status checks to pass before merging' 3. Click 'Add status check' 4. Search for and add: 'Validate Clean History' 5. Save changes **IMPORTANT:** Without this configuration, the workflow will alert but will NOT block merges. The check must run successfully at least once before it appears in the status check dropdown. ## Future Maintenance If the repository is re-initialized again: 1. Edit .github/workflows/validate-branch-history.yml 2. Add the new root commit to VALID_ROOTS array (line 32) 3. Commit and push the change ## No Configuration Needed - No secrets or tokens to configure - No repository variables to set - Uses built-in GITHUB_TOKEN automatically - Works immediately upon merge Only action required: Configure branch protection rules (see above).
f22c842 to
aaf4901
Compare
This comment was marked as resolved.
This comment was marked as resolved.
|
Hi @jake-mahon-netwrix, thank you for creating this much-needed workflow. I just want to double-check that it is ready since I see there have been a few rounds of Claude Code Review for this PR, and the last one shows Status: Conditional Approval. Once you confirm no more changes are needed, I will approve. |
This comment was marked as resolved.
This comment was marked as resolved.
- Run on pushes to feature branches (exclude main/dev) - Run on PRs targeting main or dev branches only - Prevents redundant runs on protected target branches
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Pull Request Review - Validate Branch History WorkflowI've reviewed PR #40 and here is my comprehensive feedback: Strengths
Issues & Recommendations1. Workflow Name vs Status Check Name MismatchLocation: Line 1 and Line 20 Issue:
The status check that appears in GitHub will be named after the job name, not the workflow name. Your PR description references "Validate Clean History" which is correct. Recommendation: Rename the workflow to "Validate Clean History" to match the job name for consistency. 2. Error Message Contact VariableLocation: Line 15-16 and Line 91 The GitHub team reference format should include the @ symbol for proper mentions. Recommendation: Update to: 3. Trigger Configuration NoteLocation: Lines 3-13 The workflow creates the status check but doesn't enforce blocking until branch protection is configured. Consider adding a comment in the workflow file to clarify this. Recommendation: Add a comment at the top of the workflow explaining that branch protection rules must be configured separately to enforce blocking. Code Quality Assessment
Pre-Merge Checklist
Performance & Security
Overall AssessmentThis is a well-crafted security workflow with excellent documentation. The implementation correctly handles edge cases (merged branches) and provides clear user guidance. The issues identified are minor and primarily related to naming consistency and formatting of the team mention. Recommendation: Approve with minor changes (contact formatting and name consistency) Post-Merge Actions
Great work on this security-focused workflow! |
|
To test this new workflow and branch protection rule, we need to recreate the scenario of someone attempting to merge the old Git history into the fresh repository. So we're going to make two private copies, one of the fresh repository, one of the archived one. We're going to add this workflow and branch protection rule to the private copy of the fresh repo. And then we're going to attempt to merge the private copy of the old archived one into the new one and see if it works. And if it does, and we test a few other edge cases and it works, then we'll come back here and merge this branch. |
Summary
This workflow prevents branches containing old git history (from before repository re-initialization) from being merged into dev/main, protecting against re-introduction of sensitive data.
How It Works
The workflow validates branch ancestry by:
This handles edge cases like merged branches with multiple root commits.
What This Blocks
Branches containing pre-initialization git history that include sensitive data removed during repository cleanup.
Configuration After Merge
The workflow creates a status check named
Validate Clean Historybut does NOT block merges until you configure branch protection rules.For
devbranch:devprotection ruleValidate Clean HistoryFor
mainbranch:mainprotection ruleValidate Clean HistoryNote: The check must run successfully at least once before it appears in the dropdown.
No Other Configuration Needed
✅ No secrets or tokens to configure
✅ No repository variables to set
✅ Uses built-in GITHUB_TOKEN automatically
✅ Works immediately upon merge
Only action: Configure branch protection rules ☝️
Security Features
Future Maintenance
If repository is re-initialized again:
.github/workflows/validate-branch-history.ymlVALID_ROOTSarray (line 32)Testing Plan
After merge:
Review Notes