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

View file

@ -1,5 +1,5 @@
name: Docker Image CI name: Docker Image CI
on: on:
push: push:
branches: branches:
- master - master

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 FROM python:3-alpine
RUN pip install yamllint && \ RUN pip install 'yamllint>=1.25.0' && \
apk add --no-cache bash && \ apk add --no-cache bash && \
rm -rf ~/.cache/pip rm -rf ~/.cache/pip

View file

@ -4,17 +4,23 @@ This action executes `yamllint` (https://github.com/adrienverge/yamllint) agains
## Usage ## Usage
Simple as:
```yaml
- uses: ibiqlik/action-yamllint@v2
```
### Optional parameters ### Optional parameters
- `config_file` - Path to custom configuration - `config_file` - Path to custom configuration
- `config_data` - Custom configuration (as YAML source) - `config_data` - Custom configuration (as YAML source)
- `file_or_dir` - Enter file/folder (space separated), wildcards accepted. Examples: - `file_or_dir` - Enter file/folder (space separated), wildcards accepted. Examples:
- `.` - run against all yaml files in a directory recursively (default) - `.` - run against all yaml files in a directory recursively (default)
- `file1.yaml` - `file1.yaml`
- `file1.yaml file2.yaml` - `file1.yaml file2.yaml`
- `kustomize/**/*.yaml mychart/*values.yaml` - `kustomize/**/*.yaml mychart/*values.yaml`
- `format` - Format for parsing output [parsable,standard,colored,auto] (default: colored) - `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] - `strict` - Return non-zero exit code on warnings as well as errors [true,false] (default: false)
### Example usage in workflow ### Example usage in workflow
@ -27,7 +33,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: yaml-lint - name: yaml-lint
uses: ibiqlik/action-yamllint@v1 uses: ibiqlik/action-yamllint@v2
with: with:
file_or_dir: myfolder/*values*.yaml file_or_dir: myfolder/*values*.yaml
config_file: .yamllint.yml config_file: .yamllint.yml
@ -44,5 +50,25 @@ jobs:
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: yaml-lint - 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: inputs:
file_or_dir: file_or_dir:
description: 'File(s) or Directory, separate by space if multiple files or folder are specified' description: 'File(s) or Directory, separate by space if multiple files or folder are specified'
required: true required: false
config_file: config_file:
description: 'Path to custom configuration' description: 'Path to custom configuration'
required: false required: false
@ -13,9 +13,9 @@ inputs:
description: 'Custom configuration (as YAML source)' description: 'Custom configuration (as YAML source)'
required: false required: false
format: format:
description: 'Format for parsing output [parsable,standard,colored,auto]' description: 'Format for parsing output [parsable,standard,colored,github,auto]'
required: false required: false
default: "colored" default: "github"
strict: strict:
description: 'Return non-zero exit code on warnings as well as errors' description: 'Return non-zero exit code on warnings as well as errors'
required: false 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