-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
133 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package actionlint_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/rhysd/actionlint" | ||
) | ||
|
||
// A rule type to check every steps have their names. | ||
type RuleStepName struct { | ||
// Embedding RuleBase struct implements the minimal Rule interface. | ||
actionlint.RuleBase | ||
} | ||
|
||
// Reimplement methods in RuleBase. Visit* methods are called on checking workflows. | ||
func (r *RuleStepName) VisitStep(n *actionlint.Step) error { | ||
// Implement your own check | ||
if n.Name == nil { | ||
// RuleBase provides methods to report errors. See RuleBase.Error and RuleBase.Errorf. | ||
r.Error(n.Pos, "every step must have its name") | ||
} | ||
return nil | ||
} | ||
|
||
func NewRuleStepName() *RuleStepName { | ||
return &RuleStepName{ | ||
RuleBase: actionlint.NewRuleBase("step-name", "Checks every step has their own name"), | ||
} | ||
} | ||
|
||
func ExampleLinter_yourOwnRule() { | ||
// The function set at OnRulesCreated is called after rule instances are created. You can | ||
// add/remove some rules and return the modified slice. This function is called on linting | ||
// each workflow files. | ||
o := &actionlint.LinterOptions{ | ||
OnRulesCreated: func(rules []actionlint.Rule) []actionlint.Rule { | ||
rules = append(rules, NewRuleStepName()) | ||
return rules | ||
}, | ||
} | ||
|
||
l, err := actionlint.NewLinter(os.Stdout, o) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
f := filepath.Join("testdata", "ok", "minimal.yaml") | ||
|
||
// First return value is an array of lint errors found in the workflow file. | ||
errs, err := l.LintFile(f, nil) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(len(errs), "lint errors found by actionlint") | ||
|
||
// Output: | ||
// testdata/ok/minimal.yaml:6:9: every step must have its name [step-name] | ||
// | | ||
// 6 | - run: echo | ||
// | ^~~~ | ||
// 1 lint errors found by actionlint | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/test\.yaml:4:14: label "ubuntu-oldest" is unknown\. available labels are .+\. if it is a custom label for self-hosted runner, set list of labels in actionlint.yaml config file \[runner-label\]/ | ||
test.yaml:8:30: label "windows-latest" conflicts with label "ubuntu-latest" defined at line:8,col:15. note: to run your job on each workers, use matrix [runner-label] | ||
test.yaml:8:46: label "macos-latest" conflicts with label "ubuntu-latest" defined at line:8,col:15. note: to run your job on each workers, use matrix [runner-label] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
on: push | ||
jobs: | ||
test1: | ||
runs-on: ubuntu-oldest | ||
steps: | ||
- run: echo | ||
test2: | ||
runs-on: [ubuntu-latest, windows-latest, macos-latest] | ||
steps: | ||
- run: echo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
on: push | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: echo |