diff --git a/.github/problem-matcher-gcc.json b/.github/problem-matcher-gcc.json new file mode 100644 index 0000000..09b4070 --- /dev/null +++ b/.github/problem-matcher-gcc.json @@ -0,0 +1,32 @@ +{ + "problemMatcher": [ + { + "owner": "shellcheck-gcc", + "pattern": [ + { + "regexp": "^\\.?\\/?(.+):(\\d+):(\\d+):\\s(warning|error):\\s(.*)\\s\\[(SC\\d+)\\]$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5, + "code": 6 + } + ] + }, + { + "owner": "shellcheck-gcc-notice", + "severity": "notice", + "pattern": [ + { + "regexp": "^\\.?\\/?(.+):(\\d+):(\\d+):\\s(note):\\s(.*)\\s\\[(SC\\d+)\\]$", + "file": 1, + "line": 2, + "column": 3, + "message": 5, + "code": 6 + } + ] + } + ] +} diff --git a/.github/problem-matcher-tty.json b/.github/problem-matcher-tty.json new file mode 100644 index 0000000..2467ff8 --- /dev/null +++ b/.github/problem-matcher-tty.json @@ -0,0 +1,23 @@ +{ + "problemMatcher": [ + { + "owner": "shellcheck-tty", + "pattern": [ + { + "regexp": "^In\\s\\.?\\/?(.+)\\sline\\s(\\d+):$", + "file": 1, + "line": 2 + }, + { + "regexp": ".*" + }, + { + "regexp": "(SC\\d+):\\s(.+)$", + "code": 1, + "message": 2, + "loop": true + } + ] + } + ] + } diff --git a/README.md b/README.md index f1aa462..5eccc66 100644 --- a/README.md +++ b/README.md @@ -140,12 +140,26 @@ If you need to scan for unusual files, you can use the `additional_files` key. additional_files: 'run finish' ``` +## Disable problem matcher + +If you do not want to have the problem-matcher annotate files, you can disable it +by setting `disable_matcher` to `true`. + +```yaml + ... + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + with: + disable_matcher: true +``` + ## Change output format Shellcheck can print output in these formats: `checkstyle`, `diff`, `gcc`, `json`, `json1`, `quiet`, `tty`. See some examples [here](https://github.com/koalaman/shellcheck/wiki/Integration#pick-the-output-format-that-makes-your-life-easier). +Only `tty` and `gcc` produce file annotations via problem matcher, default is `gcc`. -- `tty` has multi-line log messages -- `gcc` has single-line log messages +- `tty` has multi-line log messages, but all annotations are reported as errors +- `gcc` has single-line log messages, so it's easier to parse with a problem matcher (including correct severity annotation) ```yaml ... diff --git a/action.yaml b/action.yaml index 130781e..2aa622d 100644 --- a/action.yaml +++ b/action.yaml @@ -35,7 +35,6 @@ inputs: description: "Set to true to skip using problem-matcher" required: false default: "false" - deprecationMessage: "There are no problem-matchers, this setting does not do anything." format: description: "Output format (checkstyle, diff, gcc, json, json1, quiet, tty)" required: false @@ -57,6 +56,17 @@ branding: runs: using: "composite" steps: + - name: Enable problem-matcher + shell: bash + env: + INPUT_FORMAT: ${{ inputs.format }} + INPUT_DISABLE_MATCHER: ${{ inputs.disable_matcher }} + run: | + problem_matcher_file="${{ github.action_path }}/.github/problem-matcher-${INPUT_FORMAT}.json" + if [[ "${INPUT_DISABLE_MATCHER}" != "true" && -f "$problem_matcher_file" ]]; then + echo "::add-matcher::$problem_matcher_file" + fi + - name: Download shellcheck shell: bash env: @@ -220,6 +230,13 @@ runs: set +f # re-enable globbing + - name: Remove problem-matcher + shell: bash + run: | + echo "::remove-matcher owner=shellcheck-gcc::" + echo "::remove-matcher owner=shellcheck-gcc-notice::" + echo "::remove-matcher owner=shellcheck-tty::" + - name: Exit action shell: bash run: exit ${{steps.check.outputs.statuscode}}