diff --git a/.github/workflows/ai-moderator.lock.yml b/.github/workflows/ai-moderator.lock.yml index 1f9298904cb..b43a4b3a0c3 100644 --- a/.github/workflows/ai-moderator.lock.yml +++ b/.github/workflows/ai-moderator.lock.yml @@ -1025,7 +1025,7 @@ jobs: env: GH_AW_RATE_LIMIT_MAX: "5" GH_AW_RATE_LIMIT_WINDOW: "60" - GH_AW_RATE_LIMIT_EVENTS: "issues,issue_comment,workflow_dispatch" + GH_AW_RATE_LIMIT_EVENTS: "issue_comment,issues,workflow_dispatch" with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | diff --git a/pkg/workflow/role_checks.go b/pkg/workflow/role_checks.go index 2446f1e9b27..b0de86a1745 100644 --- a/pkg/workflow/role_checks.go +++ b/pkg/workflow/role_checks.go @@ -2,6 +2,7 @@ package workflow import ( "fmt" + "sort" "strings" "github.com/github/gh-aw/pkg/constants" @@ -62,7 +63,11 @@ func (c *Compiler) generateRateLimitCheck(data *WorkflowData, steps []string) [] // Set events to check (if specified) if len(data.RateLimit.Events) > 0 { - steps = append(steps, fmt.Sprintf(" GH_AW_RATE_LIMIT_EVENTS: %q\n", strings.Join(data.RateLimit.Events, ","))) + // Sort events alphabetically for consistent output + events := make([]string, len(data.RateLimit.Events)) + copy(events, data.RateLimit.Events) + sort.Strings(events) + steps = append(steps, fmt.Sprintf(" GH_AW_RATE_LIMIT_EVENTS: %q\n", strings.Join(events, ","))) } steps = append(steps, " with:\n") @@ -211,15 +216,15 @@ func (c *Compiler) inferEventsFromTriggers(frontmatter map[string]any) []string var events []string programmaticTriggers := map[string]string{ - "workflow_dispatch": "workflow_dispatch", - "repository_dispatch": "repository_dispatch", - "issues": "issues", + "discussion": "discussion", + "discussion_comment": "discussion_comment", "issue_comment": "issue_comment", + "issues": "issues", "pull_request": "pull_request", "pull_request_review": "pull_request_review", "pull_request_review_comment": "pull_request_review_comment", - "discussion": "discussion", - "discussion_comment": "discussion_comment", + "repository_dispatch": "repository_dispatch", + "workflow_dispatch": "workflow_dispatch", } switch on := onValue.(type) { @@ -243,6 +248,8 @@ func (c *Compiler) inferEventsFromTriggers(frontmatter map[string]any) []string } } + // Sort events alphabetically for consistent output + sort.Strings(events) return events } diff --git a/pkg/workflow/role_checks_test.go b/pkg/workflow/role_checks_test.go index 2065f13dd68..0d58b362dd5 100644 --- a/pkg/workflow/role_checks_test.go +++ b/pkg/workflow/role_checks_test.go @@ -165,7 +165,7 @@ func TestInferEventsFromTriggers(t *testing.T) { "workflow_dispatch": nil, }, }, - expected: []string{"issues", "issue_comment", "workflow_dispatch"}, + expected: []string{"issue_comment", "issues", "workflow_dispatch"}, }, { name: "infer only programmatic triggers", @@ -206,15 +206,15 @@ func TestInferEventsFromTriggers(t *testing.T) { }, }, expected: []string{ - "workflow_dispatch", - "repository_dispatch", - "issues", + "discussion", + "discussion_comment", "issue_comment", + "issues", "pull_request", "pull_request_review", "pull_request_review_comment", - "discussion", - "discussion_comment", + "repository_dispatch", + "workflow_dispatch", }, }, } @@ -222,12 +222,8 @@ func TestInferEventsFromTriggers(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := c.inferEventsFromTriggers(tt.frontmatter) - // Use ElementsMatch since map iteration order is non-deterministic - if len(tt.expected) > 0 && len(result) > 0 { - assert.ElementsMatch(t, tt.expected, result, "Inferred events should match expected") - } else { - assert.Equal(t, tt.expected, result, "Inferred events should match expected") - } + // Events should be sorted alphabetically + assert.Equal(t, tt.expected, result, "Inferred events should match expected (in sorted order)") }) } }