From 76fdac38393593cc46d89860c3e9698d4fe6b1a4 Mon Sep 17 00:00:00 2001 From: Ilir Bekteshi Date: Thu, 22 Oct 2020 12:23:39 +0200 Subject: [PATCH] Use yamllint github format to set file annotations on errors & warnings (#12) * Use github format output * Add few tests * Config yamllint --- .github/workflows/dockerimage.yml | 2 +- .github/workflows/lint.yml | 26 +++++++++++++++++++ .yamllint | 11 ++++++++ Dockerfile | 2 +- README.md | 42 +++++++++++++++++++++++++------ action.yml | 6 ++--- test/nok.yaml | 5 ++++ test/ok.yaml | 6 +++++ test/warning.yaml | 7 ++++++ 9 files changed, 94 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .yamllint create mode 100644 test/nok.yaml create mode 100644 test/ok.yaml create mode 100644 test/warning.yaml diff --git a/.github/workflows/dockerimage.yml b/.github/workflows/dockerimage.yml index c608ac9..98b71c6 100644 --- a/.github/workflows/dockerimage.yml +++ b/.github/workflows/dockerimage.yml @@ -1,5 +1,5 @@ name: Docker Image CI -on: +on: push: branches: - master diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..d98fa24 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,26 @@ +name: Test Action +on: pull_request +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: lint with config + uses: ./ + with: + file_or_dir: test + config_data: | + extends: default + ignore: nok.yaml + rules: + new-line-at-end-of-file: + level: warning + trailing-spaces: + level: warning + + - name: lint all (but pass) + continue-on-error: true + uses: ./ + with: + file_or_dir: test + strict: true diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..4a33dd6 --- /dev/null +++ b/.yamllint @@ -0,0 +1,11 @@ +--- +extends: default + +rules: + line-length: disable + new-lines: + type: unix + new-line-at-end-of-file: + level: warning + trailing-spaces: + level: warning diff --git a/Dockerfile b/Dockerfile index a4d95d6..464b3cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM python:3-alpine -RUN pip install yamllint && \ +RUN pip install 'yamllint>=1.25.0' && \ apk add --no-cache bash && \ rm -rf ~/.cache/pip diff --git a/README.md b/README.md index ca37538..b09df54 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,23 @@ This action executes `yamllint` (https://github.com/adrienverge/yamllint) agains ## Usage +Simple as: + +```yaml +- uses: ibiqlik/action-yamllint@v2 +``` + ### Optional parameters - `config_file` - Path to custom configuration - `config_data` - Custom configuration (as YAML source) - `file_or_dir` - Enter file/folder (space separated), wildcards accepted. Examples: - - `.` - run against all yaml files in a directory recursively (default) - - `file1.yaml` - - `file1.yaml file2.yaml` - - `kustomize/**/*.yaml mychart/*values.yaml` -- `format` - Format for parsing output [parsable,standard,colored,auto] (default: colored) -- `strict` - Return non-zero exit code on warnings as well as errors [true,false] + - `.` - run against all yaml files in a directory recursively (default) + - `file1.yaml` + - `file1.yaml file2.yaml` + - `kustomize/**/*.yaml mychart/*values.yaml` +- `format` - Format for parsing output [parsable,standard,colored,github,auto] (default: github) +- `strict` - Return non-zero exit code on warnings as well as errors [true,false] (default: false) ### Example usage in workflow @@ -27,7 +33,7 @@ jobs: steps: - uses: actions/checkout@v1 - name: yaml-lint - uses: ibiqlik/action-yamllint@v1 + uses: ibiqlik/action-yamllint@v2 with: file_or_dir: myfolder/*values*.yaml config_file: .yamllint.yml @@ -44,5 +50,25 @@ jobs: steps: - uses: actions/checkout@v1 - name: yaml-lint - uses: ibiqlik/action-yamllint@v1 + uses: ibiqlik/action-yamllint@v2 +``` + +**Note:** Action will use `.yamllint` as configuration file automatically if it is available in root. + +Config data examples: + +```yaml +# Single line +config_data: "{extends: default, rules: {new-line-at-end-of-file: disable}}" +``` + +``` yaml +# Multi line +config_data: | + extends: default + rules: + new-line-at-end-of-file: + level: warning + trailing-spaces: + level: warning ``` diff --git a/action.yml b/action.yml index 5458928..896163a 100644 --- a/action.yml +++ b/action.yml @@ -5,7 +5,7 @@ author: 'ibiqlik' inputs: file_or_dir: description: 'File(s) or Directory, separate by space if multiple files or folder are specified' - required: true + required: false config_file: description: 'Path to custom configuration' required: false @@ -13,9 +13,9 @@ inputs: description: 'Custom configuration (as YAML source)' required: false format: - description: 'Format for parsing output [parsable,standard,colored,auto]' + description: 'Format for parsing output [parsable,standard,colored,github,auto]' required: false - default: "colored" + default: "github" strict: description: 'Return non-zero exit code on warnings as well as errors' required: false diff --git a/test/nok.yaml b/test/nok.yaml new file mode 100644 index 0000000..30a4804 --- /dev/null +++ b/test/nok.yaml @@ -0,0 +1,5 @@ +this: + is: Not + a valid + - yaml + file \ No newline at end of file diff --git a/test/ok.yaml b/test/ok.yaml new file mode 100644 index 0000000..bc649cb --- /dev/null +++ b/test/ok.yaml @@ -0,0 +1,6 @@ +--- +this: + is: a + valid: + - yaml + - file diff --git a/test/warning.yaml b/test/warning.yaml new file mode 100644 index 0000000..35f22f6 --- /dev/null +++ b/test/warning.yaml @@ -0,0 +1,7 @@ +--- +this: + is: a + valid: + - yaml + - file + with: warnings \ No newline at end of file