Skip to content

Commit

Permalink
Use yamllint github format to set file annotations on errors & warnin…
Browse files Browse the repository at this point in the history
…gs (#12)

* Use github format output

* Add few tests

* Config yamllint
  • Loading branch information
ibiqlik authored Oct 22, 2020
1 parent 7f68ad7 commit 76fdac3
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dockerimage.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Docker Image CI
on:
on:
push:
branches:
- master
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
```
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ 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
config_data:
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
Expand Down
5 changes: 5 additions & 0 deletions test/nok.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
this:
is: Not
a valid
- yaml
file
6 changes: 6 additions & 0 deletions test/ok.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
this:
is: a
valid:
- yaml
- file
7 changes: 7 additions & 0 deletions test/warning.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
this:
is: a
valid:
- yaml
- file
with: warnings

0 comments on commit 76fdac3

Please sign in to comment.