From f10322f2aa19b5ce914a8f5bba8968f8074a42a6 Mon Sep 17 00:00:00 2001 From: Federico Gimenez Date: Sun, 10 Mar 2024 12:03:27 +0100 Subject: [PATCH] named args --- action.yml | 3 +++ entrypoint.sh | 39 ++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/action.yml b/action.yml index 8b3bef5..be3bf28 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,9 @@ runs: using: 'docker' image: 'Dockerfile' args: + - --foundry-command - ${{ inputs.foundry-command }} + - --foundry-directory - ${{ inputs.foundry-directory }} + - --foundry-script - ${{ inputs.foundry-script }} diff --git a/entrypoint.sh b/entrypoint.sh index c96412e..e259196 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,17 +1,30 @@ #!/bin/bash -FOUNDRY_COMMAND="$1" -SOLC_PATH="--use /usr/local/bin/solc" -FOUNDRY_DIRECTORY="--root $2" -FOUNDRY_SCRIPT="$3" +main() { + local FOUNDRY_COMMAND="" + local FOUNDRY_DIRECTORY="" + local FOUNDRY_SCRIPT="" + local SOLC_PATH="--use /usr/local/bin/solc" -if [ "$FOUNDRY_COMMAND" = "script" ] && [ -z "$FOUNDRY_SCRIPT" ]; then - echo "Error: 'foundry-script' is required when 'foundry-command' is 'script'" - exit 1 -fi + # Parse named arguments + while [[ "$#" -gt 0 ]]; do + case $1 in + --foundry-command) FOUNDRY_COMMAND="$2"; shift ;; + --foundry-directory) FOUNDRY_DIRECTORY="--root $2"; shift ;; + --foundry-script) FOUNDRY_SCRIPT="$2"; shift ;; + *) echo "Unknown parameter passed: $1"; exit 1 ;; + esac + shift + done -if [ "$FOUNDRY_COMMAND" = "script" ]; then - exec forge script $FOUNDRY_SCRIPT $SOLC_PATH $FOUNDRY_DIRECTORY --fork-url http://localhost:8545 --broadcast -vvvv -else - exec forge $FOUNDRY_COMMAND $SOLC_PATH $FOUNDRY_DIRECTORY -fi + if [ "$FOUNDRY_COMMAND" = "script" ] && [ -z "$FOUNDRY_SCRIPT" ]; then + echo "Error: 'foundry-script' is required when 'foundry-command' is 'script'" + exit 1 + fi + + if [ "$FOUNDRY_COMMAND" = "script" ]; then + exec forge script $FOUNDRY_SCRIPT $SOLC_PATH $FOUNDRY_DIRECTORY --fork-url http://localhost:8545 --broadcast -vvvv + else + exec forge $FOUNDRY_COMMAND $SOLC_PATH $FOUNDRY_DIRECTORY + fi +}