Skip to content

Commit

Permalink
Merge branch 'issue-371' (fix #371)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Feb 15, 2024
2 parents cdff815 + 5b9c4f3 commit 64902ec
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 51 deletions.
72 changes: 40 additions & 32 deletions rule_runner_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ const (
// https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
var allGitHubHostedRunnerLabels = []string{
"windows-latest",
"windows-latest-8-cores",
"windows-2022",
"windows-2019",
"windows-2016",
"ubuntu-latest",
"ubuntu-latest-4-cores",
"ubuntu-latest-8-cores",
"ubuntu-latest-16-cores",
"ubuntu-22.04",
"ubuntu-20.04",
"macos-latest",
Expand Down Expand Up @@ -76,38 +80,42 @@ var selfHostedRunnerPresetOtherLabels = []string{
}

var defaultRunnerOSCompats = map[string]runnerOSCompat{
"ubuntu-latest": compatUbuntu2204,
"ubuntu-22.04": compatUbuntu2204,
"ubuntu-20.04": compatUbuntu2004,
"macos-14-xl": compatMacOS140XL,
"macos-14-xlarge": compatMacOS140XL,
"macos-14-large": compatMacOS140L,
"macos-14": compatMacOS140,
"macos-14.0": compatMacOS140,
"macos-13-xl": compatMacOS130XL,
"macos-13-xlarge": compatMacOS130XL,
"macos-13-large": compatMacOS130L,
"macos-13": compatMacOS130,
"macos-13.0": compatMacOS130,
"macos-latest-xl": compatMacOS120XL,
"macos-latest-xlarge": compatMacOS120XL,
"macos-latest-large": compatMacOS120L,
"macos-latest": compatMacOS120,
"macos-12-xl": compatMacOS120XL,
"macos-12-xlarge": compatMacOS120XL,
"macos-12-large": compatMacOS120L,
"macos-12": compatMacOS120,
"macos-12.0": compatMacOS120,
"macos-11": compatMacOS110,
"macos-11.0": compatMacOS110,
"macos-10.15": compatMacOS1015,
"windows-latest": compatWindows2022,
"windows-2022": compatWindows2022,
"windows-2019": compatWindows2019,
"windows-2016": compatWindows2016,
"linux": compatUbuntu2204 | compatUbuntu2004, // Note: "linux" does not always indicate Ubuntu. It might be Fedora or Arch or ...
"macos": compatMacOS130 | compatMacOS130L | compatMacOS130XL | compatMacOS120 | compatMacOS120L | compatMacOS120XL | compatMacOS110 | compatMacOS1015,
"windows": compatWindows2022 | compatWindows2019 | compatWindows2016,
"ubuntu-latest": compatUbuntu2204,
"ubuntu-latest-4-cores": compatUbuntu2204,
"ubuntu-latest-8-cores": compatUbuntu2204,
"ubuntu-latest-16-cores": compatUbuntu2204,
"ubuntu-22.04": compatUbuntu2204,
"ubuntu-20.04": compatUbuntu2004,
"macos-14-xl": compatMacOS140XL,
"macos-14-xlarge": compatMacOS140XL,
"macos-14-large": compatMacOS140L,
"macos-14": compatMacOS140,
"macos-14.0": compatMacOS140,
"macos-13-xl": compatMacOS130XL,
"macos-13-xlarge": compatMacOS130XL,
"macos-13-large": compatMacOS130L,
"macos-13": compatMacOS130,
"macos-13.0": compatMacOS130,
"macos-latest-xl": compatMacOS120XL,
"macos-latest-xlarge": compatMacOS120XL,
"macos-latest-large": compatMacOS120L,
"macos-latest": compatMacOS120,
"macos-12-xl": compatMacOS120XL,
"macos-12-xlarge": compatMacOS120XL,
"macos-12-large": compatMacOS120L,
"macos-12": compatMacOS120,
"macos-12.0": compatMacOS120,
"macos-11": compatMacOS110,
"macos-11.0": compatMacOS110,
"macos-10.15": compatMacOS1015,
"windows-latest": compatWindows2022,
"windows-latest-8-cores": compatWindows2022,
"windows-2022": compatWindows2022,
"windows-2019": compatWindows2019,
"windows-2016": compatWindows2016,
"linux": compatUbuntu2204 | compatUbuntu2004, // Note: "linux" does not always indicate Ubuntu. It might be Fedora or Arch or ...
"macos": compatMacOS130 | compatMacOS130L | compatMacOS130XL | compatMacOS120 | compatMacOS120L | compatMacOS120XL | compatMacOS110 | compatMacOS1015,
"windows": compatWindows2022 | compatWindows2019 | compatWindows2016,
}

// RuleRunnerLabel is a rule to check runner label like "ubuntu-latest". There are two types of
Expand Down
29 changes: 23 additions & 6 deletions rule_runner_label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ func TestRuleRunnerLabelCheckLabels(t *testing.T) {
what: "self-hosted runner with GH-hosted runner label",
labels: []string{"self-hosted", "ubuntu-20.04"},
},
{
what: "larger Ubuntu runner",
labels: []string{"ubuntu-latest-16-cores"},
},
{
what: "larger Ubuntu runner with other labels",
labels: []string{"ubuntu-latest", "ubuntu-latest-16-cores"},
},
{
what: "larger Windows runner",
labels: []string{"windows-latest-8-cores"},
},
{
what: "multiple labels for GH-hosted runner",
labels: []string{"ubuntu-latest", "ubuntu-22.04"},
Expand All @@ -73,12 +85,6 @@ func TestRuleRunnerLabelCheckLabels(t *testing.T) {
labels: []string{`linux-[arch]`},
known: []string{`*-\[*]`},
},
{
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 Expand Up @@ -226,6 +232,17 @@ func TestRuleRunnerLabelCheckLabels(t *testing.T) {
labels: []string{"macos-13-xl", "macos-13"},
errs: []string{`label "macos-13" conflicts with label "macos-13-xl"`},
},
{
what: "larger runner labels conflict",
labels: []string{"ubuntu-latest-16-cores", "windows-latest-8-cores"},
errs: []string{`label "windows-latest-8-cores" conflicts with label "ubuntu-latest-16-cores"`},
},
{
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`},
},
// TODO: Add error tests for 'include:'
}

Expand Down
2 changes: 1 addition & 1 deletion testdata/format/test.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"message":"unexpected key \"branch\" for \"push\" section. expected one of \"branches\", \"branches-ignore\", \"paths\", \"paths-ignore\", \"tags\", \"tags-ignore\", \"types\", \"workflows\"","filepath":"testdata/format/test.yaml","line":3,"column":5,"kind":"syntax-check","snippet":" branch: main\n ^~~~~~~","end_column":11},{"message":"label \"linux-latest\" is unknown. available labels are \"windows-latest\", \"windows-2022\", \"windows-2019\", \"windows-2016\", \"ubuntu-latest\", \"ubuntu-22.04\", \"ubuntu-20.04\", \"macos-latest\", \"macos-latest-xl\", \"macos-latest-xlarge\", \"macos-latest-large\", \"macos-14-xl\", \"macos-14-xlarge\", \"macos-14-large\", \"macos-14\", \"macos-14.0\", \"macos-13-xl\", \"macos-13-xlarge\", \"macos-13-large\", \"macos-13\", \"macos-13.0\", \"macos-12-xl\", \"macos-12-xlarge\", \"macos-12-large\", \"macos-12\", \"macos-12.0\", \"macos-11\", \"macos-11.0\", \"macos-10.15\", \"self-hosted\", \"x64\", \"arm\", \"arm64\", \"linux\", \"macos\", \"windows\". if it is a custom label for self-hosted runner, set list of labels in actionlint.yaml config file","filepath":"testdata/format/test.yaml","line":6,"column":14,"kind":"runner-label","snippet":" runs-on: linux-latest\n ^~~~~~~~~~~~","end_column":25}]
[{"message":"unexpected key \"branch\" for \"push\" section. expected one of \"branches\", \"branches-ignore\", \"paths\", \"paths-ignore\", \"tags\", \"tags-ignore\", \"types\", \"workflows\"","filepath":"testdata/format/test.yaml","line":3,"column":5,"kind":"syntax-check","snippet":" branch: main\n ^~~~~~~","end_column":11},{"message":"property \"msg\" is not defined in object type {}","filepath":"testdata/format/test.yaml","line":9,"column":23,"kind":"expression","snippet":" - run: echo ${{ matrix.msg }}\n ^~~~~~~~~~","end_column":32},{"message":"this step is for running shell command since it contains at least one of \"run\", \"shell\" keys, but also contains \"with\" key which is used for running action","filepath":"testdata/format/test.yaml","line":10,"column":9,"kind":"syntax-check","snippet":" with:\n ^~~~~","end_column":13}]
3 changes: 2 additions & 1 deletion testdata/format/test.jsonl
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
{"message":"unexpected key \"branch\" for \"push\" section. expected one of \"branches\", \"branches-ignore\", \"paths\", \"paths-ignore\", \"tags\", \"tags-ignore\", \"types\", \"workflows\"","filepath":"testdata/format/test.yaml","line":3,"column":5,"kind":"syntax-check","snippet":" branch: main\n ^~~~~~~","end_column":11}
{"message":"label \"linux-latest\" is unknown. available labels are \"windows-latest\", \"windows-2022\", \"windows-2019\", \"windows-2016\", \"ubuntu-latest\", \"ubuntu-22.04\", \"ubuntu-20.04\", \"macos-latest\", \"macos-latest-xl\", \"macos-latest-xlarge\", \"macos-latest-large\", \"macos-14-xl\", \"macos-14-xlarge\", \"macos-14-large\", \"macos-14\", \"macos-14.0\", \"macos-13-xl\", \"macos-13-xlarge\", \"macos-13-large\", \"macos-13\", \"macos-13.0\", \"macos-12-xl\", \"macos-12-xlarge\", \"macos-12-large\", \"macos-12\", \"macos-12.0\", \"macos-11\", \"macos-11.0\", \"macos-10.15\", \"self-hosted\", \"x64\", \"arm\", \"arm64\", \"linux\", \"macos\", \"windows\". if it is a custom label for self-hosted runner, set list of labels in actionlint.yaml config file","filepath":"testdata/format/test.yaml","line":6,"column":14,"kind":"runner-label","snippet":" runs-on: linux-latest\n ^~~~~~~~~~~~","end_column":25}
{"message":"property \"msg\" is not defined in object type {}","filepath":"testdata/format/test.yaml","line":9,"column":23,"kind":"expression","snippet":" - run: echo ${{ matrix.msg }}\n ^~~~~~~~~~","end_column":32}
{"message":"this step is for running shell command since it contains at least one of \"run\", \"shell\" keys, but also contains \"with\" key which is used for running action","filepath":"testdata/format/test.yaml","line":10,"column":9,"kind":"syntax-check","snippet":" with:\n ^~~~~","end_column":13}
17 changes: 13 additions & 4 deletions testdata/format/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ unexpected key "branch" for "push" section. expected one of "branches", "branche
^~~~~~~
```

### Error at line 6, col 14 of `testdata/format/test.yaml`
### Error at line 9, col 23 of `testdata/format/test.yaml`

label "linux-latest" is unknown. available labels are "windows-latest", "windows-2022", "windows-2019", "windows-2016", "ubuntu-latest", "ubuntu-22.04", "ubuntu-20.04", "macos-latest", "macos-latest-xl", "macos-latest-xlarge", "macos-latest-large", "macos-14-xl", "macos-14-xlarge", "macos-14-large", "macos-14", "macos-14.0", "macos-13-xl", "macos-13-xlarge", "macos-13-large", "macos-13", "macos-13.0", "macos-12-xl", "macos-12-xlarge", "macos-12-large", "macos-12", "macos-12.0", "macos-11", "macos-11.0", "macos-10.15", "self-hosted", "x64", "arm", "arm64", "linux", "macos", "windows". if it is a custom label for self-hosted runner, set list of labels in actionlint.yaml config file
property "msg" is not defined in object type {}

```
runs-on: linux-latest
^~~~~~~~~~~~
- run: echo ${{ matrix.msg }}
^~~~~~~~~~
```

### Error at line 10, col 9 of `testdata/format/test.yaml`

this step is for running shell command since it contains at least one of "run", "shell" keys, but also contains "with" key which is used for running action

```
with:
^~~~~
```

36 changes: 30 additions & 6 deletions testdata/format/test.sarif
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@
]
},
{
"ruleId": "runner-label",
"ruleId": "expression",
"message": {
"text": "label \"linux-latest\" is unknown. available labels are \"windows-latest\", \"windows-2022\", \"windows-2019\", \"windows-2016\", \"ubuntu-latest\", \"ubuntu-22.04\", \"ubuntu-20.04\", \"macos-latest\", \"macos-latest-xl\", \"macos-latest-xlarge\", \"macos-latest-large\", \"macos-14-xl\", \"macos-14-xlarge\", \"macos-14-large\", \"macos-14\", \"macos-14.0\", \"macos-13-xl\", \"macos-13-xlarge\", \"macos-13-large\", \"macos-13\", \"macos-13.0\", \"macos-12-xl\", \"macos-12-xlarge\", \"macos-12-large\", \"macos-12\", \"macos-12.0\", \"macos-11\", \"macos-11.0\", \"macos-10.15\", \"self-hosted\", \"x64\", \"arm\", \"arm64\", \"linux\", \"macos\", \"windows\". if it is a custom label for self-hosted runner, set list of labels in actionlint.yaml config file"
"text": "property \"msg\" is not defined in object type {}"
},
"locations": [
{
Expand All @@ -290,11 +290,35 @@
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 6,
"startColumn": 14,
"endColumn": 25,
"startLine": 9,
"startColumn": 23,
"endColumn": 32,
"snippet": {
"text": " runs-on: linux-latest\n ^~~~~~~~~~~~"
"text": " - run: echo ${{ matrix.msg }}\n ^~~~~~~~~~"
}
}
}
}
]
},
{
"ruleId": "syntax-check",
"message": {
"text": "this step is for running shell command since it contains at least one of \"run\", \"shell\" keys, but also contains \"with\" key which is used for running action"
},
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "testdata/format/test.yaml",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 10,
"startColumn": 9,
"endColumn": 13,
"snippet": {
"text": " with:\n ^~~~~"
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion testdata/format/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
branch: main
jobs:
test:
runs-on: linux-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: echo ${{ matrix.msg }}
with:
arg: foo

0 comments on commit 64902ec

Please sign in to comment.