diff --git a/action.yml b/action.yml index bd18a77..e185e96 100644 --- a/action.yml +++ b/action.yml @@ -63,4 +63,5 @@ runs: INPUT_PASSWORD: ${{ inputs.password }} INPUT_DOCKER_NETWORK: ${{ inputs.docker_network }} INPUT_PLATFORM: ${{ inputs.platform }} + INPUT_ACTIONS_ENV: ${{ toJson(env) }} run: "$GITHUB_ACTION_PATH/entrypoint.sh" diff --git a/entrypoint.sh b/entrypoint.sh index 95bdd9c..f776c1d 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -8,6 +8,10 @@ main() { local COLOR_RED="\e[0;31m" local COLOR_RESET="\e[0m" + declare -A env_vars=( + [HOME]=1 [CI]=1 [GITHUB_ACTIONS]=1 [GITHUB_WORKSPACE]=1 [GITHUB_EVENT_PATH]=1 [GITHUB_OUTPUT]=1 + [GITHUB_ENV]=1 [GITHUB_STATE]=1 [GITHUB_STEP_SUMMARY]=1 [GITHUB_PATH]=1 + ) local script IFS=" " read -r -a argv <<< "$INPUT_OPTIONS" IFS=" " read -r -a run_args <<< "$INPUT_RUN_ARGS" @@ -37,15 +41,40 @@ main() { argv+=(--platform "$INPUT_PLATFORM") fi - # load all environment variables - for prefix in GITHUB_ RUNNER_ ACTIONS_; do - while IFS= read -r env; do + # add important environment variables that mustn't be overriden + argv+=( + -e "HOME=/github/home" + -e "CI=true" + -e "GITHUB_ACTIONS=true" + -e "GITHUB_WORKSPACE=/github/workspace" + -e "GITHUB_EVENT_PATH=${GITHUB_EVENT_PATH/#$RUNNER_TEMP//github/workflow}" + -e "GITHUB_OUTPUT=${GITHUB_OUTPUT/#$RUNNER_TEMP//github/file_commands}" + -e "GITHUB_ENV=${GITHUB_ENV/#$RUNNER_TEMP//github/file_commands}" + -e "GITHUB_STATE=${GITHUB_STATE/#$RUNNER_TEMP//github/file_commands}" + -e "GITHUB_STEP_SUMMARY=${GITHUB_STEP_SUMMARY/#$RUNNER_TEMP//github/file_commands}" + -e "GITHUB_PATH=${GITHUB_PATH/#$RUNNER_TEMP//github/file_commands}" + ) + + # load user set environment variables + while IFS= read -r env; do + # insert if it doesn't override important variables that can't be overriden + if ! [[ -v env_vars["$env"] ]]; then argv+=(-e "$env") - done <<< "$(env | grep -o "^${prefix}[^=]*")" - done + env_vars["$env"]=1 + fi + done <<< "$(jq -r 'keys | .[]' <<< "$INPUT_ACTIONS_ENV")" - # load extra environment variables - argv+=(-e HOME -e CI=true -e GITHUB_ACTIONS=true) + # load GHA environment variables + while IFS= read -r env; do + # insert if it doesn't override important variables that can't be overriden + if [[ "$env" = GITHUB_* ]] \ + || [[ "$env" = RUNNER_* ]] \ + || [[ "$env" = ACTIONS_* ]] \ + && ! [[ -v env_vars["$env"] ]]; then + argv+=(-e "$env") + env_vars["$env"]=1 + fi + done <<< "$(env | grep -o "^[^=]*")" # add important volumes # some directories here are taken from action steps that uses docker:// protocols