Skip to content

Commit c50d5c0

Browse files
committed
✨ feat: Support sarif reporter which uses Code Scanning
1 parent d515852 commit c50d5c0

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,17 @@ jobs:
5858
- name: check the exit code
5959
if: ${{ !success() }}
6060
run: echo 'The previous step should fail' && exit 1
61+
62+
test-sarif:
63+
name: runner / rails_best_practices (sarif)
64+
runs-on: ubuntu-latest
65+
steps:
66+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
67+
- uses: ruby/setup-ruby@1a615958ad9d422dd932dc1d5823942ee002799f # v1.227.0
68+
with:
69+
ruby-version: ruby
70+
- uses: ./
71+
with:
72+
reporter: sarif
73+
# workdir: ./testdata/
74+
# output_dir: ../../reviewdog-results

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ inputs:
3434
description: Report level for reviewdog [info,warning,error].
3535
default: error
3636
reporter:
37-
description: Reporter of reviewdog command [github-check,github-pr-review,github-pr-check].
37+
description: Reporter of reviewdog command [github-check,github-pr-review,github-pr-check,sarif].
3838
default: github-check
3939
filter_mode:
4040
description: |
4141
Filtering mode for the reviewdog command [added,diff_context,file,nofilter].
42-
Default is added.
43-
default: added
42+
Default is `added` except that sarif reporter uses `nofilter`.
43+
default: ''
4444
fail_on_error:
4545
description: |
4646
Exit code for reviewdog when errors are found [true,false].
@@ -49,6 +49,9 @@ inputs:
4949
reviewdog_flags:
5050
description: Additional reviewdog flags.
5151
default: ''
52+
output_dir:
53+
description: Output directory of reviewdog result. Useful for -reporter=sarif
54+
default: ../reviewdog-results
5255
### Flags for rails_best_practices ###
5356
rails_best_practices_version:
5457
description: rails_best_practices version

action.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ inputs:
1717
description: Report level for reviewdog [info,warning,error].
1818
default: error
1919
reporter:
20-
description: Reporter of reviewdog command [github-check,github-pr-review,github-pr-check].
20+
description: Reporter of reviewdog command [github-check,github-pr-review,github-pr-check,sarif].
2121
default: github-check
2222
filter_mode:
2323
description: |
2424
Filtering mode for the reviewdog command [added,diff_context,file,nofilter].
25-
Default is added.
26-
default: added
25+
Default is `added` except that sarif reporter uses `nofilter`.
26+
default: ''
2727
fail_on_error:
2828
description: |
2929
Exit code for reviewdog when errors are found [true,false].
@@ -32,6 +32,9 @@ inputs:
3232
reviewdog_flags:
3333
description: Additional reviewdog flags.
3434
default: ''
35+
output_dir:
36+
description: Output directory of reviewdog result. Useful for -reporter=sarif
37+
default: ../reviewdog-results
3538
### Flags for rails_best_practices ###
3639
rails_best_practices_version:
3740
description: rails_best_practices version
@@ -58,8 +61,13 @@ runs:
5861
INPUT_FILTER_MODE: ${{ inputs.filter_mode }}
5962
INPUT_FAIL_ON_ERROR: ${{ inputs.fail_on_error }}
6063
INPUT_REVIEWDOG_FLAGS: ${{ inputs.reviewdog_flags }}
64+
INPUT_OUTPUT_DIR: ${{ inputs.output_dir }}
6165
INPUT_RAILS_BEST_PRACTICES_VERSION: ${{ inputs.rails_best_practices_version }}
6266
INPUT_RAILS_BEST_PRACTICES_FLAGS: ${{ inputs.rails_best_practices_flags }}
67+
- if: inputs.reporter == 'sarif'
68+
uses: github/codeql-action/upload-sarif@6bb031afdd8eb862ea3fc1848194185e076637e5 # v3.28.11
69+
with:
70+
sarif_file: ${{ inputs.output_dir }}
6371

6472
# Ref: https://haya14busa.github.io/github-action-brandings/
6573
branding:

script.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -e
33

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

8+
mkdir -p "${INPUT_OUTPUT_DIR}"
9+
OUTPUT_FILE_NAME="reviewdog-${INPUT_TOOL_NAME}"
10+
if [[ "${INPUT_REPORTER}" == "sarif" ]]; then
11+
OUTPUT_FILE_NAME="${OUTPUT_FILE_NAME}.sarif"
12+
fi
13+
814
export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}"
915

1016
echo '::group::🐶 Installing rails_best_practices ... https://github.com/flyerhzm/rails_best_practices'
@@ -42,7 +48,9 @@ rails_best_practices --without-color --silent . ${INPUT_RAILS_BEST_PRACTICES_FLA
4248
-filter-mode="${INPUT_FILTER_MODE}" \
4349
-fail-on-error="${INPUT_FAIL_ON_ERROR}" \
4450
-level="${INPUT_LEVEL}" \
45-
${INPUT_REVIEWDOG_FLAGS}
46-
exit_code=$?
51+
${INPUT_REVIEWDOG_FLAGS} |
52+
tee "${INPUT_OUTPUT_DIR}/${OUTPUT_FILE_NAME}"
53+
54+
exit_code=${PIPESTATUS[1]}
4755
echo '::endgroup::'
48-
exit $exit_code
56+
exit "$exit_code"

0 commit comments

Comments
 (0)