Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ If you need to scan for unusual files, you can use the `additional_files` key.

## 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).
Shellcheck can print output [in these formats](https://github.com/koalaman/shellcheck/wiki/Integration): `checkstyle`, `diff`, `gcc`, `json`, `json1`, `quiet`, `tty`. The special output format `actions` will reformat Shellcheck output to appear as _annotations_ in the GitHub UI.

- `tty` has multi-line log messages
- `gcc` has single-line log messages
- `gcc` has single-line log messages (default)
- `tty` has multi-line log messages and color output
- `actions` integrates shellcheck errors into GitHub Pull Requests view

```yaml
...
Expand Down
35 changes: 30 additions & 5 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ inputs:
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)"
description: "Output format (checkstyle, diff, gcc, json, json1, quiet, tty, actions)"
required: false
default: "gcc"
version:
Expand Down Expand Up @@ -91,9 +91,15 @@ runs:
run: |
declare -a options
if [[ -n "${INPUT_SEVERITY}" ]]; then
options+=("-S ${INPUT_SEVERITY}")
options+=(-S "${INPUT_SEVERITY}")
fi
if [ "${INPUT_FORMAT}" = "actions" ]; then
options+=(--format=json1)
elif [ "${INPUT_FORMAT}" = "tty" ]; then
options+=(--format=tty --color=always)
else
options+=(--format="${INPUT_FORMAT}")
Comment on lines +94 to +101
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Based on the verification results, I can now provide the final response:

Potential issue with format handling implementation

The code only explicitly handles "actions" and "tty" formats, while falling back to direct format value for others. However, the input definition in action.yaml specifies 8 supported formats: "checkstyle", "diff", "gcc", "json", "json1", "quiet", "tty", and "actions". While the fallback might work, explicit handling would be safer to:

  • Validate input against supported formats
  • Apply format-specific options (like we do for "tty" with --color=always)
🔗 Analysis chain

LGTM: Options handling is robust and maintains compatibility.

The implementation correctly maps the "actions" format to json1 output while preserving existing format handling.

Let's verify that all format options are handled correctly:


Let me gather more information about the format handling by checking the documentation and input definitions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that all documented format options are properly handled in the code
formats="checkstyle diff gcc json json1 quiet tty actions"
for format in $formats; do
  echo "Checking handling of format: $format"
  rg -A 2 "INPUT_FORMAT.*=.*$format" 
done

Length of output: 1642


Script:

#!/bin/bash
# Check format input definition and documentation
echo "Checking format input definition:"
rg "format:" action.yaml -B 2 -A 4

echo -e "\nChecking format documentation:"
rg -i "format.*supported" README.md -A 10 -B 2 || true
rg "format:" README.md -A 10 -B 2 || true

Length of output: 1041

fi
options+=("--format=${INPUT_FORMAT}")
echo "options=${options[@]}" >> $GITHUB_OUTPUT

- name: Gather excluded paths
Expand Down Expand Up @@ -152,6 +158,7 @@ runs:
INPUT_EXCLUDE_ARGS: ${{ steps.exclude.outputs.excludes }}
INPUT_ADDITIONAL_FILE_ARGS: ${{ steps.additional.outputs.files }}
INPUT_SHELLCHECK_OPTIONS: ${{ steps.options.outputs.options }}
INPUT_FORMAT: ${{ inputs.format }}
run: |
statuscode=0
declare -a filepaths
Expand Down Expand Up @@ -203,15 +210,33 @@ runs:
-type f ! -name '*.*' -perm /111 \
-print0)

# Reformats shellcheck "json1" output as GitHub Actions workflow commands
reformat() {
if [ "${INPUT_FORMAT}" = "actions" ]; then
jq -r '
def workflow_command:
if . == "note" or . == "info" or . == "style"
then "notice"
else . # error, warning
end;
.comments[] |
"::\(.level | workflow_command) file=\(.file),line=\(.line),endLine=\(.endLine),col=\(.column),endColumn=\(.endColumn)::\(.message) [SC\(.code)]"
'
else
cat
fi
}

set -o pipefail
if [[ -n "${INPUT_CHECK_TOGETHER}" ]]; then
"${{ github.action_path }}/shellcheck" \
${INPUT_SHELLCHECK_OPTIONS} \
"${filepaths[@]}" || statuscode=$?
"${filepaths[@]}" | reformat || statuscode=$?
else
for file in "${filepaths[@]}"; do
"${{ github.action_path }}/shellcheck" \
${INPUT_SHELLCHECK_OPTIONS} \
"$file" || statuscode=$?
"$file" | reformat || statuscode=$?
done
fi

Expand Down