Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

Commit 0c695c5

Browse files
author
Thulio Ferraz Assis
authored
Merge pull request #161 from SUSE/viccuad/add-yaml-linting
Add yaml linting
2 parents 2d3f908 + 0879c1b commit 0c695c5

9 files changed

+69
-4
lines changed

.gitlab-ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ lint:
1717
only: *common_refs
1818
script:
1919
- ./dev/linters/shellcheck.sh
20+
- ./dev/linters/yamllint.sh
2021

2122
build:chart:
2223
stage: build

WORKSPACE

+21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@ external_binary(
1313
windows = project.shellcheck.platforms.windows,
1414
)
1515

16+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
17+
18+
git_repository(
19+
name = "rules_python",
20+
remote = "https://github.com/bazelbuild/rules_python.git",
21+
commit = project.rules_python.commit,
22+
)
23+
24+
load("@rules_python//python:pip.bzl", "pip_repositories", "pip3_import")
25+
26+
pip_repositories()
27+
28+
pip3_import(
29+
name = "yamllint",
30+
requirements = "//dev/linters:requirements.txt",
31+
)
32+
33+
load("@yamllint//:requirements.bzl", "pip_install")
34+
35+
pip_install()
36+
1637
http_archive(
1738
name = "cf_deployment",
1839
build_file_content = """

def.bzl

+3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ project = struct(
112112
},
113113
),
114114
),
115+
rules_python = struct(
116+
commit = "94677401bc56ed5d756f50b441a6a5c7f735a6d4"
117+
),
115118
mysql_chart = struct(
116119
version = "1.3.3",
117120
sha256 = "9ef4ce3693eb2a7428598f9dae833ee546eac9c105b4005c6d7375c55e33bdff",

dev/linters/BUILD.bazel

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@yamllint//:requirements.bzl","all_requirements")
2+
3+
load("@rules_python//python:defs.bzl", "py_binary")
4+
5+
py_binary(
6+
name = "yamllint",
7+
srcs = ["//dev/linters:run_yamllint.py"],
8+
main = "run_yamllint.py",
9+
python_version = "PY3",
10+
deps = all_requirements,
11+
)

dev/linters/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yamllint

dev/linters/run_yamllint.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import os
2+
from yamllint import cli
3+
4+
bazel_working_dir = os.environ['BUILD_WORKING_DIRECTORY']
5+
6+
if bazel_working_dir:
7+
os.chdir(bazel_working_dir)
8+
9+
cli.run()

dev/linters/yamllint.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
5+
# shellcheck disable=SC2046
6+
# We want word splitting with find.
7+
bazel run //dev/linters:yamllint -- \
8+
-d "{extends: relaxed, rules: {line-length: {max: 120}}}" \
9+
--strict $(find . -type f \
10+
-path "./deploy/helm/kubecf/values.*" \
11+
-or -not -path "./deploy/helm/kubecf/*" \
12+
-name '*.yaml' -or -name '*.yml')

doc/Contribute.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,20 @@ associated documentation, if we have any.
9797

9898
## Linting
9999

100-
Currently only one linter is available:
100+
Currently, 2 linters are available:
101101

102102
- `dev/linters/shellcheck.sh`
103+
- `dev/linters/yamllint.sh`
103104

104-
Invoke this linter as
105+
Invoke these linters as
105106

106107
```sh
107108
dev/linters/shellcheck.sh
109+
dev/linters/yamllint.sh
108110
```
109111

110-
to run shellcheck on all `.sh` files found in the entire checkout and
111-
report any issues found.
112+
to run shellcheck on all `.sh` files found in the entire checkout, or yamllint
113+
on all `.yaml` or `.yml` files respectively, and report any issues found.
112114

113115
## Patching
114116

doc/linters.md

+5
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ The following linters are available:
99

1010
Runs shellcheck on all `.sh` files found in the entire checkout
1111
and reports any issues found.
12+
13+
- `yamllint.sh`:
14+
15+
Runs yamllint on all `.{yaml,yml}` files found in the entire checkout
16+
and reports any issues found.

0 commit comments

Comments
 (0)