Commit 98ce7ab
authored
🚀 [Feature]: Add target branch detection to prevent releases from non-default branch merges (#7)
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
```1 parent 3b93ae6 commit 98ce7ab
1 file changed
+24
-40
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
| 198 | + | |
207 | 199 | | |
208 | 200 | | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
| 201 | + | |
226 | 202 | | |
227 | 203 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
233 | 210 | | |
234 | 211 | | |
235 | 212 | | |
236 | 213 | | |
237 | 214 | | |
238 | 215 | | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
239 | 219 | | |
240 | 220 | | |
241 | 221 | | |
| |||
254 | 234 | | |
255 | 235 | | |
256 | 236 | | |
| 237 | + | |
257 | 238 | | |
258 | 239 | | |
259 | | - | |
| 240 | + | |
260 | 241 | | |
| 242 | + | |
| 243 | + | |
261 | 244 | | |
262 | 245 | | |
263 | 246 | | |
| |||
267 | 250 | | |
268 | 251 | | |
269 | 252 | | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
277 | 261 | | |
278 | 262 | | |
279 | 263 | | |
| |||
467 | 451 | | |
468 | 452 | | |
469 | 453 | | |
470 | | - | |
| 454 | + | |
471 | 455 | | |
472 | 456 | | |
473 | 457 | | |
| |||
0 commit comments