Skip to content

Commit 81e214f

Browse files
authored
Save yamllint output/log to a file (#23)
1 parent 0d4bd66 commit 81e214f

File tree

4 files changed

+88
-22
lines changed

4 files changed

+88
-22
lines changed

.github/workflows/lint.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ jobs:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v2
8-
- name: lint with config
8+
9+
- name: Get yamllint version
10+
run: yamllint --version
11+
12+
- id: lint-with-config
13+
name: lint with config
914
uses: ./
1015
with:
1116
file_or_dir: test
@@ -18,21 +23,35 @@ jobs:
1823
trailing-spaces:
1924
level: warning
2025
21-
- name: lint all - no warnings (continue on error)
26+
- id: lint-all-no-warnings
27+
name: lint all - no warnings (continue on error)
2228
continue-on-error: true
2329
uses: ./
2430
with:
2531
file_or_dir: test
2632
strict: true
2733
no_warnings: true
2834

29-
- name: lint all (continue on error)
35+
- id: lint-all-continue
36+
name: lint all (continue on error)
3037
continue-on-error: true
3138
uses: ./
3239
with:
3340
file_or_dir: test
3441
strict: true
42+
format: standard
3543

36-
- name: default lint all (continue on error)
44+
- id: default-lint-all
45+
name: default lint all (continue on error)
3746
continue-on-error: true
3847
uses: ./
48+
49+
- id: print-output
50+
if: always()
51+
name: Print output
52+
run: |
53+
echo ${{ steps.lint-with-config.outputs.logfile }}
54+
cat ${{ steps.lint-with-config.outputs.logfile }}
55+
56+
echo ${{ steps.lint-all-continue.outputs.logfile }}
57+
cat ${{ steps.lint-all-continue.outputs.logfile }}

README.md

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GitHub YAMLlint
22

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

55
## Usage
66

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

26-
**Note:** If `.yamllint` configuration file exists in your root folder, yamllint will automatically use it.
26+
**Note:** If `.yamllint` configuration file exists in your root folder, yamllint automatically uses it.
27+
28+
### Outputs
29+
30+
`logfile` - Path to yamllint log file
31+
32+
`${{ steps.<step>.outputs.logfile }}`
33+
34+
**Note:** Each yamllint run (for example if you define multiple yamllint steps) has its own log
2735

2836
### Example usage in workflow
2937

3038
```yaml
39+
---
3140
name: Yaml Lint
32-
on: [push]
41+
on: [push] # yamllint disable-line rule:truthy
3342
jobs:
3443
lintAllTheThings:
3544
runs-on: ubuntu-latest
3645
steps:
37-
- uses: actions/checkout@v1
38-
- name: yaml-lint
39-
uses: ibiqlik/action-yamllint@v3
40-
with:
41-
file_or_dir: myfolder/*values*.yaml
42-
config_file: .yamllint.yml
46+
- uses: actions/checkout@v2
47+
- name: yaml-lint
48+
uses: ibiqlik/action-yamllint@v3
49+
with:
50+
file_or_dir: myfolder/*values*.yaml
51+
config_file: .yamllint.yml
4352
```
4453

45-
Or just simply check all yaml files in the repository:
54+
Or just simply lint all yaml files in the repository:
4655

4756
```yaml
57+
---
4858
name: Yaml Lint
49-
on: [push]
59+
on: [push] # yamllint disable-line rule:truthy
5060
jobs:
5161
lintAllTheThings:
5262
runs-on: ubuntu-latest
5363
steps:
54-
- uses: actions/checkout@v2
55-
- name: yaml-lint
56-
uses: ibiqlik/action-yamllint@v3
64+
- uses: actions/checkout@v2
65+
- name: yaml-lint
66+
uses: ibiqlik/action-yamllint@v3
5767
```
5868

5969
Config data examples:
@@ -73,3 +83,26 @@ config_data: |
7383
trailing-spaces:
7484
level: warning
7585
```
86+
87+
Use output to save/upload the log in artifact. Note, you must have `id` in the step running the yamllint action.
88+
89+
```yaml
90+
---
91+
name: Yaml Lint
92+
on: [push] # yamllint disable-line rule:truthy
93+
jobs:
94+
lintAllTheThings:
95+
runs-on: ubuntu-latest
96+
steps:
97+
- uses: actions/checkout@v2
98+
- id: yaml-lint
99+
uses: ibiqlik/action-yamllint@v3
100+
101+
- run: echo ${{ steps.yaml-lint.outputs.logfile }}
102+
103+
- uses: actions/upload-artifact@v2
104+
if: always()
105+
with:
106+
name: yamllint-logfile
107+
path: ${{ steps.yaml-lint.outputs.logfile }}
108+
```

action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,18 @@ inputs:
2525
required: false
2626
default: "false"
2727

28+
outputs:
29+
logfile:
30+
description: "Yamllint log file path"
31+
value: ${{ steps.yamllint.outputs.logfile }}
32+
2833
runs:
2934
using: 'composite'
3035
steps:
31-
- run: ${{ github.action_path }}/entrypoint.sh
36+
- id: yamllint
37+
run: |
38+
# export LOGFILE=$(mktemp yamllint-XXXXXX)
39+
${{ github.action_path }}/entrypoint.sh
3240
shell: bash
3341
env:
3442
INPUT_FILE_OR_DIR: ${{ inputs.file_or_dir }}

entrypoint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#!/bin/bash -l
2+
# shellcheck disable=SC2086
3+
set -o pipefail
24

35
echo "======================"
46
echo "= Linting YAML files ="
57
echo "======================"
68

9+
if [[ -z "$LOGFILE" ]]; then
10+
LOGFILE=$(mktemp yamllint-XXXXXX)
11+
fi
12+
713
if [[ -n "$INPUT_CONFIG_FILE" ]]; then
814
options+=(-c "$INPUT_CONFIG_FILE")
915
fi
@@ -25,10 +31,10 @@ fi
2531
# Enable globstar so ** globs recursively
2632
shopt -s globstar
2733

28-
yamllint "${options[@]}" ${INPUT_FILE_OR_DIR:-.}
29-
34+
yamllint "${options[@]}" ${INPUT_FILE_OR_DIR:-.} | tee -a "$LOGFILE"
3035
exitcode=$?
3136

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

3440
exit $exitcode

0 commit comments

Comments
 (0)