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

Commit

Permalink
Merge pull request #161 from SUSE/viccuad/add-yaml-linting
Browse files Browse the repository at this point in the history
Add yaml linting
  • Loading branch information
Thulio Ferraz Assis authored Nov 26, 2019
2 parents 2d3f908 + 0879c1b commit 0c695c5
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ lint:
only: *common_refs
script:
- ./dev/linters/shellcheck.sh
- ./dev/linters/yamllint.sh

build:chart:
stage: build
Expand Down
21 changes: 21 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,27 @@ external_binary(
windows = project.shellcheck.platforms.windows,
)

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "rules_python",
remote = "https://github.com/bazelbuild/rules_python.git",
commit = project.rules_python.commit,
)

load("@rules_python//python:pip.bzl", "pip_repositories", "pip3_import")

pip_repositories()

pip3_import(
name = "yamllint",
requirements = "//dev/linters:requirements.txt",
)

load("@yamllint//:requirements.bzl", "pip_install")

pip_install()

http_archive(
name = "cf_deployment",
build_file_content = """
Expand Down
3 changes: 3 additions & 0 deletions def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ project = struct(
},
),
),
rules_python = struct(
commit = "94677401bc56ed5d756f50b441a6a5c7f735a6d4"
),
mysql_chart = struct(
version = "1.3.3",
sha256 = "9ef4ce3693eb2a7428598f9dae833ee546eac9c105b4005c6d7375c55e33bdff",
Expand Down
11 changes: 11 additions & 0 deletions dev/linters/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@yamllint//:requirements.bzl","all_requirements")

load("@rules_python//python:defs.bzl", "py_binary")

py_binary(
name = "yamllint",
srcs = ["//dev/linters:run_yamllint.py"],
main = "run_yamllint.py",
python_version = "PY3",
deps = all_requirements,
)
1 change: 1 addition & 0 deletions dev/linters/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yamllint
9 changes: 9 additions & 0 deletions dev/linters/run_yamllint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os
from yamllint import cli

bazel_working_dir = os.environ['BUILD_WORKING_DIRECTORY']

if bazel_working_dir:
os.chdir(bazel_working_dir)

cli.run()
12 changes: 12 additions & 0 deletions dev/linters/yamllint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -o errexit

# shellcheck disable=SC2046
# We want word splitting with find.
bazel run //dev/linters:yamllint -- \
-d "{extends: relaxed, rules: {line-length: {max: 120}}}" \
--strict $(find . -type f \
-path "./deploy/helm/kubecf/values.*" \
-or -not -path "./deploy/helm/kubecf/*" \
-name '*.yaml' -or -name '*.yml')
10 changes: 6 additions & 4 deletions doc/Contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,20 @@ associated documentation, if we have any.

## Linting

Currently only one linter is available:
Currently, 2 linters are available:

- `dev/linters/shellcheck.sh`
- `dev/linters/yamllint.sh`

Invoke this linter as
Invoke these linters as

```sh
dev/linters/shellcheck.sh
dev/linters/yamllint.sh
```

to run shellcheck on all `.sh` files found in the entire checkout and
report any issues found.
to run shellcheck on all `.sh` files found in the entire checkout, or yamllint
on all `.yaml` or `.yml` files respectively, and report any issues found.

## Patching

Expand Down
5 changes: 5 additions & 0 deletions doc/linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ The following linters are available:

Runs shellcheck on all `.sh` files found in the entire checkout
and reports any issues found.

- `yamllint.sh`:

Runs yamllint on all `.{yaml,yml}` files found in the entire checkout
and reports any issues found.

0 comments on commit 0c695c5

Please sign in to comment.