Skip to content

Commit

Permalink
Save yamllint output/log to a file (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibiqlik authored Oct 7, 2021
1 parent 0d4bd66 commit 81e214f
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 22 deletions.
27 changes: 23 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: lint with config

- name: Get yamllint version
run: yamllint --version

- id: lint-with-config
name: lint with config
uses: ./
with:
file_or_dir: test
Expand All @@ -18,21 +23,35 @@ jobs:
trailing-spaces:
level: warning
- name: lint all - no warnings (continue on error)
- id: lint-all-no-warnings
name: lint all - no warnings (continue on error)
continue-on-error: true
uses: ./
with:
file_or_dir: test
strict: true
no_warnings: true

- name: lint all (continue on error)
- id: lint-all-continue
name: lint all (continue on error)
continue-on-error: true
uses: ./
with:
file_or_dir: test
strict: true
format: standard

- name: default lint all (continue on error)
- id: default-lint-all
name: default lint all (continue on error)
continue-on-error: true
uses: ./

- id: print-output
if: always()
name: Print output
run: |
echo ${{ steps.lint-with-config.outputs.logfile }}
cat ${{ steps.lint-with-config.outputs.logfile }}
echo ${{ steps.lint-all-continue.outputs.logfile }}
cat ${{ steps.lint-all-continue.outputs.logfile }}
63 changes: 48 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GitHub YAMLlint

This action executes `yamllint` (https://github.com/adrienverge/yamllint) against file(s) or folder
This action executes `yamllint` (https://github.com/adrienverge/yamllint) against files or folder

## Usage

Expand All @@ -10,7 +10,7 @@ Simple as:
- uses: ibiqlik/action-yamllint@v3
```
### Optional parameters
### Optional input parameters
- `config_file` - Path to custom configuration
- `config_data` - Custom configuration (as YAML source)
Expand All @@ -23,37 +23,47 @@ Simple as:
- `strict` - Return non-zero exit code on warnings as well as errors `[true,false] (default: false)`
- `no_warnings` - Output only error level problems `[true,false] (default: false)`

**Note:** If `.yamllint` configuration file exists in your root folder, yamllint will automatically use it.
**Note:** If `.yamllint` configuration file exists in your root folder, yamllint automatically uses it.

### Outputs

`logfile` - Path to yamllint log file

`${{ steps.<step>.outputs.logfile }}`

**Note:** Each yamllint run (for example if you define multiple yamllint steps) has its own log

### Example usage in workflow

```yaml
---
name: Yaml Lint
on: [push]
on: [push] # yamllint disable-line rule:truthy
jobs:
lintAllTheThings:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: yaml-lint
uses: ibiqlik/action-yamllint@v3
with:
file_or_dir: myfolder/*values*.yaml
config_file: .yamllint.yml
- uses: actions/checkout@v2
- name: yaml-lint
uses: ibiqlik/action-yamllint@v3
with:
file_or_dir: myfolder/*values*.yaml
config_file: .yamllint.yml
```

Or just simply check all yaml files in the repository:
Or just simply lint all yaml files in the repository:

```yaml
---
name: Yaml Lint
on: [push]
on: [push] # yamllint disable-line rule:truthy
jobs:
lintAllTheThings:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: yaml-lint
uses: ibiqlik/action-yamllint@v3
- uses: actions/checkout@v2
- name: yaml-lint
uses: ibiqlik/action-yamllint@v3
```

Config data examples:
Expand All @@ -73,3 +83,26 @@ config_data: |
trailing-spaces:
level: warning
```

Use output to save/upload the log in artifact. Note, you must have `id` in the step running the yamllint action.

```yaml
---
name: Yaml Lint
on: [push] # yamllint disable-line rule:truthy
jobs:
lintAllTheThings:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- id: yaml-lint
uses: ibiqlik/action-yamllint@v3
- run: echo ${{ steps.yaml-lint.outputs.logfile }}
- uses: actions/upload-artifact@v2
if: always()
with:
name: yamllint-logfile
path: ${{ steps.yaml-lint.outputs.logfile }}
```
10 changes: 9 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ inputs:
required: false
default: "false"

outputs:
logfile:
description: "Yamllint log file path"
value: ${{ steps.yamllint.outputs.logfile }}

runs:
using: 'composite'
steps:
- run: ${{ github.action_path }}/entrypoint.sh
- id: yamllint
run: |
# export LOGFILE=$(mktemp yamllint-XXXXXX)
${{ github.action_path }}/entrypoint.sh
shell: bash
env:
INPUT_FILE_OR_DIR: ${{ inputs.file_or_dir }}
Expand Down
10 changes: 8 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/bin/bash -l
# shellcheck disable=SC2086
set -o pipefail

echo "======================"
echo "= Linting YAML files ="
echo "======================"

if [[ -z "$LOGFILE" ]]; then
LOGFILE=$(mktemp yamllint-XXXXXX)
fi

if [[ -n "$INPUT_CONFIG_FILE" ]]; then
options+=(-c "$INPUT_CONFIG_FILE")
fi
Expand All @@ -25,10 +31,10 @@ fi
# Enable globstar so ** globs recursively
shopt -s globstar

yamllint "${options[@]}" ${INPUT_FILE_OR_DIR:-.}

yamllint "${options[@]}" ${INPUT_FILE_OR_DIR:-.} | tee -a "$LOGFILE"
exitcode=$?

shopt -u globstar
echo "::set-output name=logfile::$(realpath ${LOGFILE})"

exit $exitcode

0 comments on commit 81e214f

Please sign in to comment.