Skip to content

Bug: Label trigger shorthand does not produce label filter condition in compiled workflow #19770

Description

@deyaaeldeen

Bug Description

When using the label trigger shorthand syntax (e.g. on: pull_request labeled my-label), the compiled .lock.yml does not include a label name condition in the activation job's if: clause. This means the workflow triggers on any labeled event, not just the specified label(s).

The YAML-format syntax (on: pull_request: types: [labeled] names: [my-label]) works correctly.

Root Cause

In pkg/workflow/label_trigger_parser.go, expandLabelTriggerShorthand() stores the names field as []string:

triggerConfig["names"] = labelNames  // labelNames is []string

But in pkg/workflow/filters.go, applyLabelFilter() only type-asserts for string or []any:

if namesStr, isNamesStr := namesValue.(string); isNamesStr {
    labelNames = []string{namesStr}
} else if namesArray, isNamesArray := namesValue.([]any); isNamesArray {
    // ...
}

In Go, []string is not assignable to []any, so both branches fail silently. The label filter is never applied.

When the YAML format is used, YAML unmarshalling naturally produces []any{"my-label"}, which is why that path works correctly.

Fix

Convert []string to []any in expandLabelTriggerShorthand before storing:

namesAny := make([]any, len(labelNames))
for i, name := range labelNames {
    namesAny[i] = name
}
triggerConfig["names"] = namesAny

The tests in label_trigger_parser_test.go (line 382) and label_trigger_parser_fuzz_test.go (line 144) also assert []string and need to be updated to []any.

Reproduction

  1. Create a workflow with shorthand: on: pull_request labeled architecture-review-needed
  2. Compile with gh aw compile
  3. Inspect the activation job's if: condition — it will not contain a github.event.label.name check

Expected Behavior

The compiled activation job should include:

github.event.label.name == 'architecture-review-needed'

Versions Tested

  • gh-aw v0.51.0 and v0.53.4 — both affected

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions