Use yamllint github format to set file annotations on errors & warnings (#12)

* Use github format output

* Add few tests

* Config yamllint
This commit is contained in:
Ilir Bekteshi 2020-10-22 12:23:39 +02:00 committed by GitHub
parent 7f68ad7a33
commit 76fdac3839
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 94 additions and 13 deletions

26
.github/workflows/lint.yml vendored Normal file
View file

@ -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

11
.yamllint Normal file
View file

@ -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

View file

@ -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

View file

@ -4,6 +4,12 @@ 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
@ -13,8 +19,8 @@ This action executes `yamllint` (https://github.com/adrienverge/yamllint) agains
- `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]
- `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
```

View file

@ -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

5
test/nok.yaml Normal file
View file

@ -0,0 +1,5 @@
this:
is: Not
a valid
- yaml
file

6
test/ok.yaml Normal file
View file

@ -0,0 +1,6 @@
---
this:
is: a
valid:
- yaml
- file

7
test/warning.yaml Normal file
View file

@ -0,0 +1,7 @@
---
this:
is: a
valid:
- yaml
- file
with: warnings