Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/scenarios/hotfix/hotfix-generation-threshold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ steps:
- "target_env:"
- "pull_request:"
- "types: [closed]"
- "'env/*'"
- "'env/**'"
- "format('hotfix-finalize-{0}', github.repository)"
- "format('hotfix-{0}', github.event.inputs.target_env)"
- " plan:"
Expand Down
7 changes: 6 additions & 1 deletion internal/generate/hotfix.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,12 @@ func (g *HotfixGenerator) writeTriggers(sb *strings.Builder) {
sb.WriteString(" pull_request:\n")
sb.WriteString(" types: [closed]\n")
sb.WriteString(" branches:\n")
sb.WriteString(" - 'env/*'\n")
// Double-star matches env branches at any depth. A GitHub Actions branch
// glob `*` stops at a slash, so a single-star `env/*` never matches a
// per-component branch like env/api/staging and the closed-PR finalize
// would never fire for a multi-component pipeline. `env/**` matches both
// the single-component branch (env/staging) and the per-component branch.
sb.WriteString(" - 'env/**'\n")
sb.WriteString("\n")
}

Expand Down
21 changes: 20 additions & 1 deletion internal/generate/hotfix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestHotfixGenerator_Triggers(t *testing.T) {
assert.Contains(t, content, "pull_request:")
assert.Contains(t, content, "types: [closed]")
assert.Contains(t, content, "branches:")
assert.Contains(t, content, "'env/*'")
assert.Contains(t, content, "'env/**'")

// Dispatch inputs.
assert.Contains(t, content, "commit:")
Expand All @@ -89,6 +89,25 @@ func TestHotfixGenerator_Triggers(t *testing.T) {
assert.NotContains(t, content, "- dev")
}

// TestHotfixGenerator_FinalizeTriggerMatchesNestedEnvBranches guards that the
// finalize pull_request trigger's branch filter matches multi-component env
// branches. Per-component env branches carry two path segments
// (env/api/staging), and a GitHub Actions `*` glob stops at a slash, so a
// single-star `env/*` filter never matches them and the closed-PR finalize
// never fires. A double-star `env/**` matches any depth, covering both the
// single-component branch (env/staging) and the per-component branch
// (env/api/staging).
func TestHotfixGenerator_FinalizeTriggerMatchesNestedEnvBranches(t *testing.T) {
gen := NewHotfixGenerator(threeEnvHotfixConfig(), "")
content, err := gen.Generate()
require.NoError(t, err)

assert.Contains(t, content, " - 'env/**'",
"finalize trigger must use env/** so it matches per-component env branches like env/api/staging")
assert.NotContains(t, content, " - 'env/*'\n",
"finalize trigger must not use a single-star env/* filter, which a GitHub Actions glob will not match across the slash of env/api/staging")
}

// TestHotfixGenerator_CommitInputAcceptsMultiple guards that the dispatch
// `commit` input documents comma-delimited multi-commit hotfixes, so an operator
// can hand the workflow a stack of trunk fixes to cherry-pick as one chain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ on:
pull_request:
types: [closed]
branches:
- 'env/*'
- 'env/**'

permissions:
contents: read
Expand Down