From 0e6b19cba87a0f4fa3b3649c70d0703bd13c6cc6 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 7 Jul 2024 09:15:51 +0900 Subject: [PATCH 1/8] Support sarif reporter which uses Code Scanning --- action.yml | 13 ++++++++++--- script.sh | 14 +++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index bf164b7..1acf5b0 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 From 045b015210ce6edcc325f1e613561e6883a8e257 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 7 Jul 2024 09:17:52 +0900 Subject: [PATCH 2/8] Add sarif reporter test --- .github/workflows/test.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43a038a..f26e8c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 / (sarif) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./ + with: + reporter: sarif + locale: "US" From dd8457b76cf6ecff6c9404ec48985a2ae79bcc47 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 7 Jul 2024 09:18:38 +0900 Subject: [PATCH 3/8] fix config --- action.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 1acf5b0..af7339d 100644 --- a/action.yml +++ b/action.yml @@ -62,7 +62,8 @@ runs: INPUT_LOCALE: ${{ inputs.locale }} - if: inputs.reporter == 'sarif' uses: github/codeql-action/upload-sarif@v3 - sarif_file: ${{ inputs.output_dir }} + with: + sarif_file: ${{ inputs.output_dir }} # Ref: https://haya14busa.github.io/github-action-brandings/ # TODO: update branding if you want. From 6cd63d622464363ed51d450a1bdd7b725899ed8e Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 7 Jul 2024 09:21:18 +0900 Subject: [PATCH 4/8] fix bash if-then statement --- script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.sh b/script.sh index 2dbabd1..b926bfe 100755 --- a/script.sh +++ b/script.sh @@ -7,7 +7,7 @@ fi mkdir -p "${INPUT_OUTPUT_DIR}" OUTPUT_FILE_NAME="reviewdog-${INPUT_TOOL_NAME}" -if [[ "${INPUT_REPORTER}" == "sarif" ]] +if [[ "${INPUT_REPORTER}" == "sarif" ]]; then OUTPUT_FILE_NAME="${OUTPUT_FILE_NAME}.sarif" fi From fd5ee62d5ee7c837b1c076e144b1d5e267b5f872 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 7 Jul 2024 09:28:51 +0900 Subject: [PATCH 5/8] Update script.sh Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.sh b/script.sh index b926bfe..3421ff8 100755 --- a/script.sh +++ b/script.sh @@ -29,7 +29,7 @@ misspell -locale="${INPUT_LOCALE}" . | -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ -level="${INPUT_LEVEL}" \ ${INPUT_REVIEWDOG_FLAGS} | - tee "${OUTPUT_FILE_NAME}" + tee "${OUTPUT_FILE_NAME}" exit_code=${PIPESTATUS[1]} echo '::endgroup::' From b9c5875ba5500a43ed46d152dce279e9b0d8ff7f Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 7 Jul 2024 09:30:15 +0900 Subject: [PATCH 6/8] Update script.sh Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.sh b/script.sh index 3421ff8..bc70fce 100755 --- a/script.sh +++ b/script.sh @@ -33,4 +33,4 @@ misspell -locale="${INPUT_LOCALE}" . | exit_code=${PIPESTATUS[1]} echo '::endgroup::' -exit $exit_code +exit "$exit_code" From b7eb9784556cd908ff0d7f84ab125db76dd8a023 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 7 Jul 2024 09:30:55 +0900 Subject: [PATCH 7/8] fix output dir --- script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.sh b/script.sh index bc70fce..379ac88 100755 --- a/script.sh +++ b/script.sh @@ -29,7 +29,7 @@ misspell -locale="${INPUT_LOCALE}" . | -fail-on-error="${INPUT_FAIL_ON_ERROR}" \ -level="${INPUT_LEVEL}" \ ${INPUT_REVIEWDOG_FLAGS} | - tee "${OUTPUT_FILE_NAME}" + tee "${INPUT_OUTPUT_DIR}/${OUTPUT_FILE_NAME}" exit_code=${PIPESTATUS[1]} echo '::endgroup::' From 6c39538681f6a0ee243d26ef5921ca1a09886fb5 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sun, 21 Jul 2024 16:08:12 +0900 Subject: [PATCH 8/8] use backquotes --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index af7339d..5177cb9 100644 --- a/action.yml +++ b/action.yml @@ -22,7 +22,7 @@ inputs: filter_mode: description: | Filtering mode for the reviewdog command [added,diff_context,file,nofilter]. - Default is added except that sarif reporter uses nofilter. + Default is `added` except that sarif reporter uses `nofilter`. default: '' fail_on_error: description: |