Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sarif reporter which uses Code Scanning #33

Merged
merged 8 commits into from
Jul 21, 2024
Merged
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
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,13 @@ jobs:
- name: check the exit code
if: ${{ !success() }}
run: echo 'The previous step should fail' && exit 1

test-sarif:
name: runner / <linter-name> (sarif)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./
with:
reporter: sarif
locale: "US"
14 changes: 11 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ inputs:
description: 'Report level for reviewdog [info,warning,error].'
default: 'error'
reporter:
description: 'Reporter of reviewdog command [github-check,github-pr-review,github-pr-check].'
description: 'Reporter of reviewdog command [github-check,github-pr-review,github-pr-check,sarif].'
default: 'github-check'
filter_mode:
description: |
Filtering mode for the reviewdog command [added,diff_context,file,nofilter].
Default is added.
default: 'added'
Default is `added` except that sarif reporter uses `nofilter`.
default: ''
fail_on_error:
description: |
Exit code for reviewdog when errors are found [true,false].
Expand All @@ -32,6 +32,9 @@ inputs:
reviewdog_flags:
description: 'Additional reviewdog flags.'
default: ''
output_dir:
description: 'Output directory of reviewdog result. Useful for -reporter=sarif'
default: '../reviewdog-results'
### Flags for <linter-name> ###
locale:
description: '-locale flag of misspell. (US/UK)'
Expand All @@ -55,7 +58,12 @@ runs:
INPUT_FILTER_MODE: ${{ inputs.filter_mode }}
INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }}
INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }}
INPUT_OUTPUT_DIR: ${{ inputs.output_dir }}
INPUT_LOCALE: ${{ inputs.locale }}
- if: inputs.reporter == 'sarif'
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ inputs.output_dir }}

# Ref: https://haya14busa.github.io/github-action-brandings/
# TODO: update branding if you want.
Expand Down
16 changes: 12 additions & 4 deletions script.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/bin/sh
#!/bin/bash
set -e

if [ -n "${GITHUB_WORKSPACE}" ]; then
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
fi

mkdir -p "${INPUT_OUTPUT_DIR}"
OUTPUT_FILE_NAME="reviewdog-${INPUT_TOOL_NAME}"
if [[ "${INPUT_REPORTER}" == "sarif" ]]; then
OUTPUT_FILE_NAME="${OUTPUT_FILE_NAME}.sarif"
fi

export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"

echo '::group::🐶 Installing misspell ... https://github.com/client9/misspell'
Expand All @@ -22,7 +28,9 @@ misspell -locale="${INPUT_LOCALE}" . |
-filter-mode="${INPUT_FILTER_MODE}" \
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
-level="${INPUT_LEVEL}" \
${INPUT_REVIEWDOG_FLAGS}
exit_code=$?
${INPUT_REVIEWDOG_FLAGS} |
tee "${INPUT_OUTPUT_DIR}/${OUTPUT_FILE_NAME}"

exit_code=${PIPESTATUS[1]}
echo '::endgroup::'
exit $exit_code
exit "$exit_code"