diff --git a/action.yml b/action.yml index c50797c..31b09a8 100644 --- a/action.yml +++ b/action.yml @@ -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]. @@ -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 ### locale: description: '-locale flag of misspell. (US/UK)' @@ -55,7 +58,11 @@ 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 + sarif_file: ${{ inputs.output_dir }} # Ref: https://haya14busa.github.io/github-action-brandings/ # TODO: update branding if you want. diff --git a/script.sh b/script.sh index 644fe84..2dbabd1 100755 --- a/script.sh +++ b/script.sh @@ -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" ]] + 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' @@ -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 "${OUTPUT_FILE_NAME}" + +exit_code=${PIPESTATUS[1]} echo '::endgroup::' exit $exit_code