-
Notifications
You must be signed in to change notification settings - Fork 0
🚀 [Feature]: Add target branch detection to prevent releases from non-default branch merges #7
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds target branch detection functionality to identify whether a pull request is targeting the repository's default branch. The feature extracts branch information from GitHub event data and exposes it through logging outputs, enabling downstream workflows to implement branch-specific policies.
Changes:
- Added logic to extract the target branch from pull request base ref
- Added logic to retrieve the default branch with multiple fallback options (PascalCase, camelCase, environment variable)
- Added comparison logic to determine if the target branch matches the default branch
- Exposed the new branch information in both debug logging and job run conditions output
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The action now detects whether a pull request targets the repository's default branch and uses this to determine the correct release type. Releases and site deployments are only triggered when PRs are merged into the default branch, preventing accidental releases from feature branch merges.
Target branch detection
Added detection logic to identify the PR's target branch and compare it against the repository's default branch:
targetBranch- Extracted from the PR's base ref (pullRequest.Base.Ref)defaultBranch- Retrieved from repository info (eventData.Repository.default_branch)isTargetDefaultBranch- Boolean flag indicating whether the PR targets the default branchReleaseType logic update
The
ReleaseTypecalculation now factors in the target branch:ReleaseNoneCleanupPrereleaseNoneThis ensures that PRs merged into feature branches or other non-default branches do not trigger releases.
Site publishing update
The
PublishSitecondition now also requires the PR to be merged into the default branch ($isMergedPR -and $isTargetDefaultBranch), ensuring sites are only deployed when merging to the main branch.Code simplification
Simplified the event data extraction by removing defensive null-checking in favor of relying on
Get-GitHubEventDatato provide valid data. The action now uses direct property access for cleaner, more readable code.Logging improvements
The GitHub event inputs logging now includes branch information for debugging: