From 81e214fd484713882ce4237cb7cd264d550856cf Mon Sep 17 00:00:00 2001 From: Ilir Bekteshi Date: Thu, 7 Oct 2021 10:05:58 +0200 Subject: [PATCH] Save yamllint output/log to a file (#23) --- .github/workflows/lint.yml | 27 +++++++++++++--- README.md | 63 +++++++++++++++++++++++++++++--------- action.yml | 10 +++++- entrypoint.sh | 10 ++++-- 4 files changed, 88 insertions(+), 22 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2dd2698..9416688 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 @@ -18,7 +23,8 @@ 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: @@ -26,13 +32,26 @@ jobs: 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 }} diff --git a/README.md b/README.md index 00eb325..c93405b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) @@ -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..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: @@ -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 }} +``` diff --git a/action.yml b/action.yml index 99fcfcb..c894ff2 100644 --- a/action.yml +++ b/action.yml @@ -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 }} diff --git a/entrypoint.sh b/entrypoint.sh index 153ef1b..caec456 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 @@ -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