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

Rework Foundry installation #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
|------------------|------------
| `ignore-compile` | If set to true, the Slither action will not attempt to compile the project. False by default. See [Advanced compilation](#advanced-compilation).
| `fail-on` | Cause the action to fail if Slither finds any issue of this severity or higher. See [action fail behavior](#action-fail-behavior).
| `foundry-version`| The version of `forge` to use, if required. If this field is not set, the `nightly` version will be used.
| `node-version` | The version of `node` to use. If this field is not set, the latest version will be used.
| `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)).
| `slither-args` | Extra arguments to pass to Slither.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
description: 'The version of solc to use. Should be autodetected, but may be specified manually.'
node-version:
description: 'The version of node to use.'
foundry-version:
description: 'The version of foundry to install, if required. By default, nightly is used.'
default: nightly
type: string
target:
description: 'The path of the project that Slither should analyze, relative to the repo root.'
default: .
Expand Down
22 changes: 20 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SLITHERARGS="$(get INPUT_SLITHER-ARGS)"
SLITHERCONF="$(get INPUT_SLITHER-CONFIG)"
STDOUTFILE="/tmp/slither-stdout"
IGNORECOMPILE="$(get INPUT_IGNORE-COMPILE)"
FOUNDRYVER="$(get INPUT_FOUNDRY-VERSION)"

# #19 - an user may set SOLC_VERSION in the workflow and cause problems here.
# Make sure it's unset. If you need to use a different solc version, override
Expand Down Expand Up @@ -151,7 +152,7 @@ install_node()
install_foundry()
{
if [[ -d "$TARGET" ]] && [[ -f "$TARGET/foundry.toml" ]]; then
echo "[-] Foundry target detected, installing foundry nightly"
echo "[-] Foundry target detected, installing foundry $FOUNDRYVER"

wget -q -O foundryup https://raw.githubusercontent.com/foundry-rs/foundry/7b452656f722fc560f0414db3ce24a1f2972a8b7/foundryup/foundryup
if [ ! "e7628766329e2873484d5d633c750b5019eec77ae506c11a0ef13b440cc3e7c2 foundryup" = "$(sha256sum foundryup)" ]; then
Expand All @@ -162,8 +163,25 @@ install_foundry()
export FOUNDRY_DIR="/opt/foundry"
export PATH="$FOUNDRY_DIR/bin:$PATH"
mkdir -p "$FOUNDRY_DIR/bin" "$FOUNDRY_DIR/share/man/man1"
bash foundryup
# foundryup sometimes fails to install foundry, so try a few times
FOUNDRY_INSTALL_TRIES=0
FOUNDRY_INSTALL_TRIES_MAX=7
FOUNDRY_INSTALL_SLEEP=1
while [[ ! -f "$FOUNDRY_DIR/bin/forge" && $FOUNDRY_INSTALL_TRIES -lt $FOUNDRY_INSTALL_TRIES_MAX ]]; do
if [[ "$FOUNDRY_INSTALL_TRIES" -gt 0 ]]; then
echo "foundryup failed. Sleeping $FOUNDRY_INSTALL_SLEEP seconds before trying again."
sleep "$FOUNDRY_INSTALL_SLEEP"
fi
bash foundryup -v "$FOUNDRYVER"
FOUNDRY_INSTALL_TRIES=$((FOUNDRY_INSTALL_TRIES+1))
FOUNDRY_INSTALL_SLEEP=$((FOUNDRY_INSTALL_SLEEP*2))
done
rm foundryup
if [[ ! -f "$FOUNDRY_DIR/bin/forge" ]]; then
echo "Foundry installlation via foundryup failed $FOUNDRY_INSTALL_TRIES_MAX times in a row."
echo "Report this issue to the Foundry developers with the log from above."
exit 1
fi
fi
}

Expand Down