Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add readme linter to CI #11020

Merged
merged 4 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/readme-linter.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
base_sha: ${{ github.event.pull_request.base.sha }}
files: plugins/**/README.md
powersj marked this conversation as resolved.
Show resolved Hide resolved
- name: Run readme linter on changed files
run: go run ./tools/readme_linter ${{ steps.changed-files.outputs.all_changed_files }}
4 changes: 4 additions & 0 deletions tools/readme_linter/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
16 changes: 11 additions & 5 deletions tools/readme_linter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}