From c880b49d82156dcc5f35cd0a417aad5704444179 Mon Sep 17 00:00:00 2001 From: Ilir Bekteshi Date: Tue, 10 Aug 2021 19:47:03 +0200 Subject: [PATCH] Save yamllint output/log to a file --- .github/workflows/lint.yml | 16 +++++++++++++--- README.md | 29 ++++++++++++++++++++++++++++- action.yml | 8 +++++++- entrypoint.sh | 6 +++++- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e8afeca..f65a1cb 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,7 +5,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: lint with config + + - id: lint-with-config + name: lint with config uses: ./ with: file_or_dir: test @@ -18,7 +20,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,9 +29,16 @@ 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 + + - id: print-output + name: Print output + run: | + echo ${{ steps.lint-with-config.outputs.logfile }} + cat ${{ steps.lint-with-config.outputs.logfile }} diff --git a/README.md b/README.md index 16ffad0..95fc90d 100644 --- a/README.md +++ b/README.md @@ -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) @@ -25,6 +25,12 @@ Simple as: **Note:** If `.yamllint` configuration file exists in your root folder, yamllint will automatically use it. +### Outputs + +`logfile` - Path to yamllint log file + +`${{ steps..outputs.logfile }}` + ### Example usage in workflow ```yaml @@ -73,3 +79,24 @@ 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] +jobs: + lintAllTheThings: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - id: yaml-lint + uses: ibiqlik/action-yamllint@v3 + + - run: echo ${{ steps.yaml-lint.outputs.logfile }} + + - uses: actions/upload-artifact@v2 + with: + name: yamllint-logfile + path: ${{ steps.yaml-lint.outputs.logfile }} +``` diff --git a/action.yml b/action.yml index 99fcfcb..7c400e9 100644 --- a/action.yml +++ b/action.yml @@ -25,10 +25,16 @@ 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: ${{ 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 7ae3616..0eade4a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,6 +4,8 @@ echo "======================" echo "= Linting YAML files =" echo "======================" +LOGFILE=yamllint.log + if [[ -n "$INPUT_CONFIG_FILE" ]]; then options+=(-c "$INPUT_CONFIG_FILE") fi @@ -28,4 +30,6 @@ shopt -s globstar options+=("${INPUT_FILE_OR_DIR:-.}") shopt -u globstar -yamllint "${options[@]}" +yamllint "${options[@]}" | tee -a $LOGFILE + +echo "::set-output name=logfile::$(realpath ${LOGFILE})"