Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions pkg/workflow/compiler_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ func (c *Compiler) emitSandboxRuntimeWarnings(workflowData *WorkflowData, markdo
}

func (c *Compiler) emitGeneralToolWarnings(workflowData *WorkflowData, markdownPath string) {
if strings.Contains(workflowData.On, "workflow_dispatch") && workflowData.ConcurrencyJobDiscriminator == "" {
Comment thread
github-actions[bot] marked this conversation as resolved.
Outdated
fmt.Fprintln(os.Stderr, formatCompilerMessage(markdownPath, "warning",
"workflow_dispatch workflow has no concurrency.job-discriminator; the generated conclusion concurrency group is shared by all dispatches of this workflow. "+
"Set a discriminator (for example, `${{ github.run_id }}`) to give each dispatch its own slot."))
c.IncrementWarningCount()
}
if workflowData.Concurrency != "" && strings.Contains(workflowData.Concurrency, "cancel-in-progress: true") && hasBotSelfCancelRisk(workflowData) {
fmt.Fprintln(os.Stderr, formatCompilerMessage(markdownPath, "warning",
"Custom workflow-level concurrency with cancel-in-progress: true may cause self-cancellation.\n"+
Expand Down
69 changes: 69 additions & 0 deletions pkg/workflow/workflow_dispatch_concurrency_warning_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//go:build !integration

package workflow

import (
"testing"

"github.com/github/gh-aw/pkg/testutil"
"github.com/stretchr/testify/assert"
)

func TestWorkflowDispatchConcurrencyWarning(t *testing.T) {
tests := []struct {
name string
on string
discriminator string
expectWarning bool
}{
{
name: "workflow dispatch without discriminator",
on: "on: workflow_dispatch",
expectWarning: true,
},
{
name: "workflow dispatch with inputs without discriminator",
on: "on:\n workflow_dispatch:\n inputs:\n target_repo:\n type: string",
expectWarning: true,
},
{
name: "mixed workflow dispatch without discriminator",
on: "on:\n workflow_dispatch:\n schedule:\n - cron: '0 0 * * *'",
expectWarning: true,
},
{
name: "workflow dispatch with discriminator",
on: "on: workflow_dispatch",
discriminator: "${{ github.run_id }}",
expectWarning: false,
},
{
name: "schedule without discriminator",
on: "on:\n schedule:\n - cron: '0 0 * * *'",
expectWarning: false,
},
}

const warning = "workflow_dispatch workflow has no concurrency.job-discriminator"
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
compiler := NewCompiler()
workflowData := &WorkflowData{
On: tt.on,
ConcurrencyJobDiscriminator: tt.discriminator,
}

output := testutil.CaptureStderr(t, func() {
compiler.emitGeneralToolWarnings(workflowData, "test.md")
})

if tt.expectWarning {
assert.Contains(t, output, warning)
assert.Equal(t, 1, compiler.GetWarningCount())
} else {
assert.NotContains(t, output, warning)
assert.Zero(t, compiler.GetWarningCount())
}
})
}
}
Loading