Skip to content

Conversation

@MariusStorhaug
Copy link
Member

@MariusStorhaug MariusStorhaug commented Jan 18, 2026

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 branch

ReleaseType logic update

The ReleaseType calculation now factors in the target branch:

Condition ReleaseType
PR merged to default branch Release
PR merged to non-default branch None
PR closed without merge Cleanup
Open PR with prerelease label Prerelease
Everything else None

This ensures that PRs merged into feature branches or other non-default branches do not trigger releases.

Site publishing update

The PublishSite condition 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-GitHubEventData to 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:

TargetBranch          : main
DefaultBranch         : main
IsTargetDefaultBranch : True

Copilot AI review requested due to automatic review settings January 18, 2026 01:43
Copy link
Contributor

Copilot AI left a 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.

@MariusStorhaug MariusStorhaug changed the title 🚀 [Feature]: Add target branch detection to identify PRs targeting default branch 🚀 [Feature]: Add target branch detection to prevent releases from non-default branch merges Jan 18, 2026
Copilot AI review requested due to automatic review settings January 18, 2026 01:54
Copy link
Contributor

Copilot AI left a 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.

@MariusStorhaug MariusStorhaug changed the base branch from main to test January 18, 2026 02:09
@MariusStorhaug MariusStorhaug changed the base branch from test to main January 18, 2026 02:12
Copilot AI review requested due to automatic review settings January 18, 2026 02:13
Copy link
Contributor

Copilot AI left a 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.

@MariusStorhaug MariusStorhaug merged commit 98ce7ab into main Jan 18, 2026
21 checks passed
@MariusStorhaug MariusStorhaug deleted the feature/target-branch-detection branch January 18, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants