Skip to content

Commit 35510b3

Browse files
authored
Merge pull request #29 from crytic/dev-new-exit-code-behavior
Add support for new `--fail-*` behavior
2 parents 670c387 + 18adb3e commit 35510b3

File tree

3 files changed

+88
-10
lines changed

3 files changed

+88
-10
lines changed

README.md

+27-8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
| Key | Description
3333
|------------------|------------
3434
| `ignore-compile` | If set to true, the Slither action will not attempt to compile the project. False by default. See [Advanced compilation](#advanced-compilation).
35+
| `fail-on` | Cause the action to fail if Slither finds any issue of this severity or higher. See [action fail behavior](#action-fail-behavior).
3536
| `node-version` | The version of `node` to use. If this field is not set, the latest version will be used.
3637
| `sarif` | If provided, the path of the SARIF file to produce, relative to the repo root (see [Github Code Scanning integration](#github-code-scanning-integration)).
3738
| `slither-args` | Extra arguments to pass to Slither.
@@ -47,6 +48,24 @@ If the project requires advanced compilation settings or steps, set
4748
Slither. You can find an example workflow that uses this option in the
4849
[examples](#examples) section.
4950

51+
### Action fail behavior
52+
53+
The Slither action supports a `fail-on` option, based on the `--fail-*` flags
54+
added in Slither 0.8.4. To maintain the current action behavior, this option
55+
defaults to `all`. The following table summarizes the action behavior across
56+
different Slither versions. You may adjust this option as needed for your
57+
workflows. If you are setting these options on your config file, set `fail-on:
58+
config` to prevent the action from overriding your settings.
59+
60+
| `fail-on` | Slither <= 0.8.3 | Slither > 0.8.3
61+
|--------------------|---------------------------|----------------
62+
| `all` / `pedantic` | Fail on any finding | Fail on any finding
63+
| `low` | Fail on any finding | Fail on any finding >= low
64+
| `medium` | Fail on any finding | Fail on any finding >= medium
65+
| `high` | Fail on any finding | Fail on any finding >= high
66+
| `none` | Do not fail on findings | Do not fail on findings
67+
| `config` | Determined by config file | Determined by config file
68+
5069
### Using a different Slither version
5170

5271
If the latest Slither release has a bug that does not let you analyze your
@@ -99,9 +118,9 @@ jobs:
99118
- name: Run Slither
100119
uses: crytic/[email protected]
101120
id: slither
102-
continue-on-error: true
103121
with:
104122
sarif: results.sarif
123+
fail-on: none
105124
106125
- name: Upload SARIF file
107126
uses: github/codeql-action/upload-sarif@v2
@@ -111,7 +130,7 @@ jobs:
111130

112131
Here:
113132

114-
- `continue-on-error: true` is required to let the SARIF upload step run if Slither finds issues
133+
- `fail-on: none` is required to let the SARIF upload step run if Slither finds issues
115134
- `id: slither` is the name used to reference the step later on (e.g., in `steps.slither.outputs.sarif`)
116135

117136
## Examples
@@ -146,8 +165,8 @@ NodeJS 16.x and install project dependencies before running Slither on the
146165
project. Slither will output findings in SARIF format, and those will get
147166
uploaded to GitHub.
148167

149-
We include `continue-on-error: true` on the Slither action to avoid failing the
150-
run if findings are found.
168+
We include `fail-on: none` on the Slither action to avoid failing the run if
169+
findings are found.
151170

152171
```yaml
153172
name: Slither Analysis
@@ -170,11 +189,11 @@ jobs:
170189
171190
- name: Run Slither
172191
uses: crytic/[email protected]
173-
continue-on-error: true
174192
id: slither
175193
with:
176194
node-version: 16
177195
sarif: results.sarif
196+
fail-on: none
178197
179198
- name: Upload SARIF file
180199
uses: github/codeql-action/upload-sarif@v2
@@ -191,8 +210,8 @@ virtual environment and install project dependencies before running Slither on
191210
the project. Slither will output findings in SARIF format, and those will get
192211
uploaded to GitHub.
193212

194-
We also include `continue-on-error: true` on the Slither action to avoid
195-
failing the run if findings are found.
213+
We also include `fail-on: none` on the Slither action to avoid failing the run
214+
if findings are found.
196215

197216
```yaml
198217
name: Slither Analysis
@@ -215,10 +234,10 @@ jobs:
215234
216235
- name: Run Slither
217236
uses: crytic/[email protected]
218-
continue-on-error: true
219237
id: slither
220238
with:
221239
sarif: results.sarif
240+
fail-on: none
222241
223242
- name: Upload SARIF file
224243
uses: github/codeql-action/upload-sarif@v2

action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ inputs:
2121
description: 'Whether to ignore the compilation step when running crytic-compile and Slither.'
2222
default: false
2323
type: boolean
24+
fail-on:
25+
description: 'Cause the action to fail if Slither finds any findings of this severity or higher. By default it will fail if any finding is found'
26+
default: all
27+
type: string
2428
internal-github-workspace:
2529
# Do not set manually. This is a hacky way to pass the host workspace path to inside the action
2630
# This is used to improve compatibility when using `ignore-compile`.

entrypoint.sh

+57-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ get() {
66
env | sed -n "s/^$1=\(.*\)/\1/;T;p"
77
}
88

9+
version_lte() {
10+
printf '%s\n%s\n' "$1" "$2" | sort -C -V
11+
}
12+
913
TARGET="$1"
1014
SOLCVER="$2"
1115
NODEVER="$3"
@@ -30,6 +34,55 @@ compatibility_link()
3034
fi
3135
}
3236

37+
fail_on_flags()
38+
{
39+
INSTALLED_VERSION="$(slither --version)"
40+
FAIL_ON_LEVEL="$(get INPUT_FAIL-ON)"
41+
42+
if [ "$FAIL_ON_LEVEL" = "config" ]; then
43+
return
44+
fi
45+
46+
if version_lte "$INSTALLED_VERSION" "0.8.3"; then
47+
# older behavior - fail on findings by default
48+
case "$FAIL_ON_LEVEL" in
49+
low|medium|high|pedantic|all)
50+
echo "[!] Requested fail-on $FAIL_ON_LEVEL but it is unsupported on Slither $INSTALLED_VERSION, ignoring" >&2
51+
;;
52+
none)
53+
echo "--ignore-return-value"
54+
;;
55+
*)
56+
echo "[!] Unknown fail-on value $FAIL_ON_LEVEL, ignoring" >&2
57+
;;
58+
esac
59+
else
60+
# newer behavior - does not fail on findings by default
61+
case "$FAIL_ON_LEVEL" in
62+
all|pedantic)
63+
# default behavior on slither >= 0.8.4
64+
echo "--fail-pedantic"
65+
;;
66+
low)
67+
echo "--fail-low"
68+
;;
69+
medium)
70+
echo "--fail-medium"
71+
;;
72+
high)
73+
echo "--fail-high"
74+
;;
75+
none)
76+
echo "--no-fail-pedantic"
77+
;;
78+
*)
79+
echo "[!] Unknown fail-on value $FAIL_ON_LEVEL, ignoring" >&2
80+
;;
81+
esac
82+
83+
fi
84+
}
85+
3386
install_solc()
3487
{
3588
if [[ -z "$SOLCVER" ]]; then
@@ -202,9 +255,11 @@ if [[ -n "$SLITHERCONF" ]]; then
202255
CONFIGFLAG="--config-file=$SLITHERCONF"
203256
fi
204257

258+
FAILONFLAG="$(fail_on_flags)"
259+
205260
if [[ -z "$SLITHERARGS" ]]; then
206-
slither "$TARGET" $SARIFFLAG $IGNORECOMPILEFLAG $CONFIGFLAG
261+
slither "$TARGET" $SARIFFLAG $IGNORECOMPILEFLAG $FAILONFLAG $CONFIGFLAG
207262
else
208263
echo "[-] SLITHERARGS provided. Running slither with extra arguments"
209-
printf "%s\n" "$SLITHERARGS" | xargs slither "$TARGET" $SARIFFLAG $IGNORECOMPILEFLAG $CONFIGFLAG
264+
printf "%s\n" "$SLITHERARGS" | xargs slither "$TARGET" $SARIFFLAG $IGNORECOMPILEFLAG $FAILONFLAG $CONFIGFLAG
210265
fi

0 commit comments

Comments
 (0)