Skip to content

Commit

Permalink
Merge pull request #378 from kishaningithub/add-glob-support
Browse files Browse the repository at this point in the history
Add glob support for self hosted runner known labels configuration
  • Loading branch information
rhysd authored Feb 10, 2024
2 parents 10ee569 + 6161b3b commit f538644
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
/man/actionlint.1.html
/playground-dist
/actionlint-workflow-ast
# IntelliJ IDE Folder
.idea/
8 changes: 7 additions & 1 deletion rule_runner_label.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package actionlint

import (
"path/filepath"
"strings"
)

Expand Down Expand Up @@ -205,7 +206,12 @@ func (rule *RuleRunnerLabel) verifyRunnerLabel(label *String) runnerOSCompat {

known := rule.getKnownLabels()
for _, k := range known {
if strings.EqualFold(l, k) {
matched, err := filepath.Match(k, l)
if matched {
return compatInvalid
}
if err != nil {
rule.Errorf(label.Pos, "label pattern %q is an invalid glob, kindly check list of labels in actionlint.yaml config file: %v", k, err)
return compatInvalid
}
}
Expand Down
11 changes: 11 additions & 0 deletions rule_runner_label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ func TestRuleRunnerLabelCheckLabels(t *testing.T) {
labels: []string{"self-hosted", "foo", "bar", "linux"},
known: []string{"foo", "bar"},
},
{
what: "user-defined labels with patterns",
labels: []string{"self-hosted", "INSTANCE_TYPE=m6a.large", "some-base-prefix:size=large&cpu=8"},
known: []string{"INSTANCE_TYPE=*", "some-base-prefix:size=*&cpu=?"},
},
{
what: "user-defined labels with invalid glob pattern",
labels: []string{"self-hosted", "INSTANCE_TYPE=m6a.large"},
known: []string{"INSTANCE_TYPE=["},
errs: []string{`label pattern "INSTANCE_TYPE=[" is an invalid glob, kindly check list of labels in actionlint.yaml config file: syntax error in pattern`},
},
{
what: "matrix",
labels: []string{"${{matrix.os}}"},
Expand Down

0 comments on commit f538644

Please sign in to comment.