From a5b2687f83cb34746a768a3833a972d6c9858f73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= Date: Tue, 13 Feb 2024 10:12:34 -0300 Subject: [PATCH] Rework Foundry installation The action will now attempt to run `foundryup` multiple times in an attempt to make the installation more reliable. A new action parameter, `foundry-version`, is now available as well, so users can lock in a known-working Foundry version if needed. Closes #69 --- README.md | 1 + action.yml | 4 ++++ entrypoint.sh | 22 ++++++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a720a3..ba99746 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/action.yml b/action.yml index f3d6ea3..a64b90c 100644 --- a/action.yml +++ b/action.yml @@ -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: . diff --git a/entrypoint.sh b/entrypoint.sh index 69557e1..f077ad4 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 @@ -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 @@ -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 }