chore: add readme linter to CI (#11020)
This commit is contained in:
parent
df3e9ec2a2
commit
622815c4a2
|
|
@ -0,0 +1,23 @@
|
|||
name: Lint plugin readmes
|
||||
on:
|
||||
# push:
|
||||
# branches-ignore: master
|
||||
pull_request:
|
||||
branches: # Names of target branches, not source branches
|
||||
- master
|
||||
jobs:
|
||||
run-readme-linter:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/setup-go@v3
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Get changed files
|
||||
id: changed-files
|
||||
uses: tj-actions/changed-files@v18.7
|
||||
with:
|
||||
base_sha: ${{ github.event.pull_request.base.sha }}
|
||||
files: plugins/**/README.md
|
||||
- name: Run readme linter on changed files
|
||||
run: go run ./tools/readme_linter ${{ steps.changed-files.outputs.all_changed_files }}
|
||||
|
|
@ -140,3 +140,7 @@ func (t *T) assertHeadingLevel(expected int, n ast.Node) {
|
|||
|
||||
t.printFailedAssertf(n, "expected header level %d, have %d", expected, h.Level)
|
||||
}
|
||||
|
||||
func (t *T) pass() bool {
|
||||
return t.fails == 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,11 +20,17 @@ func main() {
|
|||
flag.Parse()
|
||||
|
||||
var err error
|
||||
pass := true
|
||||
for _, filename := range flag.Args() {
|
||||
err = checkFile(filename, guessPluginType(filename), *sourceFlag)
|
||||
var filePass bool
|
||||
filePass, err = checkFile(filename, guessPluginType(filename), *sourceFlag)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
pass = pass && filePass
|
||||
}
|
||||
if !pass {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,10 +63,10 @@ func init() {
|
|||
rules[pluginInput] = append(rules[pluginInput], inputRules...)
|
||||
}
|
||||
|
||||
func checkFile(filename string, pluginType plugin, sourceFlag bool) error {
|
||||
func checkFile(filename string, pluginType plugin, sourceFlag bool) (bool, error) {
|
||||
md, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
return false, err
|
||||
}
|
||||
|
||||
// Goldmark returns locations as offsets. We want line
|
||||
|
|
@ -107,10 +113,10 @@ func checkFile(filename string, pluginType plugin, sourceFlag bool) error {
|
|||
for _, rule := range rules {
|
||||
err = rule(&tester, root)
|
||||
if err != nil {
|
||||
return err
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
tester.printPassFail()
|
||||
|
||||
return nil
|
||||
return tester.pass(), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue