Skip to content

Commit d6e2e77

Browse files
yuluo-yxrootfs
andauthored
infra: add yaml lint check and fix yaml style (#131)
Signed-off-by: yuluo-yx <[email protected]> Co-authored-by: Huamin Chen <[email protected]>
1 parent 409668f commit d6e2e77

File tree

10 files changed

+591
-519
lines changed

10 files changed

+591
-519
lines changed

.github/workflows/pre-commit.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
jobs:
1111
pre-commit:
1212
runs-on: ubuntu-latest
13-
name: Run pre-commit hooks on Go, Rust, JavaScripts, Markdown and Python files
13+
name: Run pre-commit hooks check file lint
1414

1515
steps:
1616
- name: Check out the repo
@@ -47,6 +47,7 @@ jobs:
4747
build-essential \
4848
pkg-config
4949
npm install -g markdownlint-cli
50+
pip install --user yamllint
5051
5152
- name: Cache Rust dependencies
5253
uses: actions/cache@v4
@@ -82,10 +83,10 @@ jobs:
8283
- name: Install pre-commit
8384
run: pip install pre-commit
8485

85-
- name: Run pre-commit on Go, Rust, JavaScript, Markdown and Python files
86+
- name: Run pre-commit on Go, Rust, JavaScript, Markdown, Yaml and Python files
8687
run: |
8788
# Find all Go, Rust, JavaScripts, Markdown and Python files (excluding vendored/generated code)
88-
FILES=$(find . -type f \( -name "*.go" -o -name "*.rs" -o -name "*.py" -o -name "*.js" -o -name "*.md" \) \
89+
FILES=$(find . -type f \( -name "*.go" -o -name "*.rs" -o -name "*.py" -o -name "*.js" -o -name "*.md" -o -name "*.yaml" -o -name "*.yml" \) \
8990
! -path "./target/*" \
9091
! -path "./candle-binding/target/*" \
9192
! -path "./.git/*" \
@@ -100,7 +101,7 @@ jobs:
100101
echo "Running pre-commit on files: $FILES"
101102
pre-commit run --files $FILES
102103
else
103-
echo "No Go, Rust, JavaScript, Markdown or Python files found to check"
104+
echo "No Go, Rust, JavaScript, Markdown, Yaml, or Python files found to check"
104105
fi
105106
106107
- name: Show pre-commit results

.pre-commit-config.yaml

Lines changed: 73 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,89 @@
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
44
# Basic hooks for Go, Rust, Python And JavaScript files only
5-
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v6.0.0
7-
hooks:
8-
- id: trailing-whitespace
9-
files: \.(go|rs|py|js)$
10-
- id: end-of-file-fixer
11-
files: \.(go|rs|py|js)$
12-
- id: check-added-large-files
13-
args: ['--maxkb=500']
14-
files: \.(go|rs|py|js)$
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v6.0.0
7+
hooks:
8+
- id: trailing-whitespace
9+
files: \.(go|rs|py|js)$
10+
- id: end-of-file-fixer
11+
files: \.(go|rs|py|js)$
12+
- id: check-added-large-files
13+
args: ['--maxkb=500']
14+
files: \.(go|rs|py|js)$
1515

1616
# Go specific hooks
17-
- repo: local
18-
hooks:
19-
- id: go-fmt
20-
name: go fmt
21-
entry: gofmt -w
22-
language: system
23-
files: \.go$
17+
- repo: local
18+
hooks:
19+
- id: go-fmt
20+
name: go fmt
21+
entry: gofmt -w
22+
language: system
23+
files: \.go$
2424

2525
# Markdown specific hooks
26-
- repo: local
27-
hooks:
28-
- id: md-fmt
29-
name: md fmt
30-
entry: bash -c "make markdown-lint"
31-
language: system
32-
files: \.md$
33-
exclude: ^(\node_modules/)
26+
- repo: local
27+
hooks:
28+
- id: md-fmt
29+
name: md fmt
30+
entry: bash -c "make markdown-lint"
31+
language: system
32+
files: \.md$
33+
exclude: ^(\node_modules/)
34+
35+
# Yaml specific hooks
36+
- repo: local
37+
hooks:
38+
- id: yaml-and-yml-fmt
39+
name: yaml/yml fmt
40+
entry: bash -c "make markdown-lint"
41+
language: system
42+
files: \.(yaml|yml)$
43+
exclude: ^(\node_modules/)
3444

3545
# JavaScript specific hooks
36-
- repo: local
37-
hooks:
38-
- id: js-lint
39-
name: js lint
40-
entry: bash -c 'cd website && npm install 2>/dev/null || true && npm run lint'
41-
language: system
42-
files: \.js$
43-
exclude: ^(\node_modules/)
44-
pass_filenames: false
46+
- repo: local
47+
hooks:
48+
- id: js-lint
49+
name: js lint
50+
entry: bash -c 'cd website && npm install 2>/dev/null || true && npm run lint'
51+
language: system
52+
files: \.js$
53+
exclude: ^(\node_modules/)
54+
pass_filenames: false
4555

46-
# Rust specific hooks
47-
- repo: local
48-
hooks:
49-
- id: cargo-fmt
50-
name: cargo fmt
51-
entry: bash -c 'cd candle-binding && rustup component add rustfmt 2>/dev/null || true && cargo fmt'
52-
language: system
53-
files: \.rs$
54-
pass_filenames: false
55-
- id: cargo-check
56-
name: cargo check
57-
entry: bash -c 'cd candle-binding && cargo check'
58-
language: system
59-
files: \.rs$
60-
pass_filenames: false
56+
# Rust specific hooks
57+
- repo: local
58+
hooks:
59+
- id: cargo-fmt
60+
name: cargo fmt
61+
entry: bash -c 'cd candle-binding && rustup component add rustfmt 2>/dev/null || true && cargo fmt'
62+
language: system
63+
files: \.rs$
64+
pass_filenames: false
65+
- id: cargo-check
66+
name: cargo check
67+
entry: bash -c 'cd candle-binding && cargo check'
68+
language: system
69+
files: \.rs$
70+
pass_filenames: false
6171

6272
# Python specific hooks
63-
- repo: https://github.com/psf/black
64-
rev: 25.1.0
65-
hooks:
66-
- id: black
67-
language_version: python3
68-
files: \.py$
69-
exclude: ^(\.venv/|venv/|env/|__pycache__/|\.git/|site/)
73+
- repo: https://github.com/psf/black
74+
rev: 25.1.0
75+
hooks:
76+
- id: black
77+
language_version: python3
78+
files: \.py$
79+
exclude: ^(\.venv/|venv/|env/|__pycache__/|\.git/|site/)
7080

71-
- repo: https://github.com/PyCQA/isort
72-
rev: 6.0.1
73-
hooks:
74-
- id: isort
75-
args: ["--profile", "black"]
76-
files: \.py$
77-
exclude: ^(\.venv/|venv/|env/|__pycache__/|\.git/|site/)
81+
- repo: https://github.com/PyCQA/isort
82+
rev: 6.0.1
83+
hooks:
84+
- id: isort
85+
args: ["--profile", "black"]
86+
files: \.py$
87+
exclude: ^(\.venv/|venv/|env/|__pycache__/|\.git/|site/)
7888

7989
# Commented out flake8 - only reports issues, doesn't auto-fix
8090
# - repo: https://github.com/PyCQA/flake8

.yamllint

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
ignore: |
2+
# This directory fails checks since many files
3+
# are templated. Instead, we run the linter
4+
# after running `make generate-manifests` which creates
5+
# the Install YAML in bin/
6+
.git
7+
.github
8+
node_modules
9+
10+
rules:
11+
braces:
12+
min-spaces-inside: 0
13+
max-spaces-inside: 0
14+
min-spaces-inside-empty: -1
15+
max-spaces-inside-empty: -1
16+
brackets:
17+
min-spaces-inside: 0
18+
max-spaces-inside: 1
19+
min-spaces-inside-empty: -1
20+
max-spaces-inside-empty: -1
21+
colons:
22+
max-spaces-before: 0
23+
max-spaces-after: 1
24+
commas:
25+
max-spaces-before: 1
26+
min-spaces-after: 1
27+
max-spaces-after: 1
28+
comments:
29+
level: warning
30+
require-starting-space: true
31+
min-spaces-from-content: 2
32+
comments-indentation:
33+
level: warning
34+
document-end: disable
35+
document-start: disable
36+
empty-lines:
37+
max: 2
38+
max-start: 0
39+
max-end: 1
40+
empty-values:
41+
forbid-in-block-mappings: false
42+
forbid-in-flow-mappings: true
43+
hyphens:
44+
max-spaces-after: 1
45+
indentation:
46+
spaces: 2
47+
indent-sequences: consistent
48+
check-multi-line-strings: false
49+
key-duplicates: enable
50+
key-ordering: disable
51+
new-line-at-end-of-file: enable
52+
new-lines:
53+
type: unix
54+
trailing-spaces: enable
55+
truthy:
56+
check-keys: false
57+
level: warning

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,7 @@ markdown-lint:
387387
markdown-lint-fix:
388388
@echo "Fixing markdown lint issues..."
389389
markdownlint -c markdownlint.yaml "**/*.md" --ignore node_modules --ignore website/node_modules --fix
390+
391+
yaml-lint:
392+
@echo "Linting YAML files..."
393+
yamllint --config-file=.yamllint .

0 commit comments

Comments
 (0)