Skip to content

Commit

Permalink
chore: Run shfmt and fix shellcheck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sondrelg committed Oct 6, 2022
1 parent b630456 commit 4d67864
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 73 deletions.
46 changes: 23 additions & 23 deletions .github/scripts/assert.sh
@@ -1,30 +1,30 @@
#!/bin/bash

assert_in_one() {
local option1="$1"
local option2="$2"
local option3="$3"
local long="$4"
local option1="$1"
local option2="$2"
local option3="$3"
local long="$4"

if [[ "$long" == *"$option1"* || "$long" == *"$option2"* || "$long" == *"$option3"* ]]; then
echo "assertion succeeded: one of the options were found in ${long}"
return 0
else
echo "assertion failed: none of the options were found in ${long}"
echo -e "options:\n- $option1\n- $option2\n- $option3"
return 1
fi
if [[ "$long" == *"$option1"* || "$long" == *"$option2"* || "$long" == *"$option3"* ]]; then
echo "assertion succeeded: one of the options were found in ${long}"
return 0
else
echo "assertion failed: none of the options were found in ${long}"
echo -e "options:\n- $option1\n- $option2\n- $option3"
return 1
fi
}
assert_in() {
local short="$1"
local long="$2"
# On windows paths use \ and unix uses /, so here we standardize
long="${long//\\//}"
if [[ "$long" == *"$short"* ]]; then
echo "assertion succeeded: ${short} was found in ${long}"
return 0
else
echo "assertion failed: ${short} not found in ${long}"
return 1
fi
local short="$1"
local long="$2"
# On windows paths use \ and unix uses /, so here we standardize
long="${long//\\//}"
if [[ "$long" == *"$short"* ]]; then
echo "assertion succeeded: ${short} was found in ${long}"
return 0
else
echo "assertion failed: ${short} not found in ${long}"
return 1
fi
}
17 changes: 10 additions & 7 deletions main.sh
Expand Up @@ -13,9 +13,12 @@ echo -e "\n\033[33mSetting Poetry installation path as $path\033[0m\n"
echo -e "\033[33mInstalling Poetry 👷\033[0m\n"

if [ "${VERSION}" == "latest" ]; then
POETRY_HOME=$path python3 $installation_script --yes ${INSTALLATION_ARGUMENTS}
# Note: If we quote installation arguments, the call below fails
# shellcheck disable=SC2086
POETRY_HOME=$path python3 "${installation_script}" --yes ${INSTALLATION_ARGUMENTS}
else
POETRY_HOME=$path python3 $installation_script --yes --version=${VERSION} ${INSTALLATION_ARGUMENTS}
# shellcheck disable=SC2086
POETRY_HOME=$path python3 "${installation_script}" --yes --version="${VERSION}" ${INSTALLATION_ARGUMENTS}
fi

echo "$path/bin" >>"$GITHUB_PATH"
Expand All @@ -30,14 +33,14 @@ fi
# Expand any "~" in VIRTUALENVS_PATH
VIRTUALENVS_PATH="${VIRTUALENVS_PATH/#\~/$HOME}"

$poetry_ config virtualenvs.create ${VIRTUALENVS_CREATE}
$poetry_ config virtualenvs.in-project ${VIRTUALENVS_IN_PROJECT}
$poetry_ config virtualenvs.path ${VIRTUALENVS_PATH}
"$poetry_" config virtualenvs.create "${VIRTUALENVS_CREATE}"
"$poetry_" config virtualenvs.in-project "${VIRTUALENVS_IN_PROJECT}"
"$poetry_" config virtualenvs.path "${VIRTUALENVS_PATH}"

config="$($poetry_ config --list)"
config="$("$poetry_" config --list)"

if echo "$config" | grep -q -c "installer.parallel"; then
$poetry_ config installer.parallel "${INSTALLER_PARALLEL}"
"$poetry_" config installer.parallel "${INSTALLER_PARALLEL}"
fi

if [ "${RUNNER_OS}" == "Windows" ]; then
Expand Down
40 changes: 20 additions & 20 deletions scripts/v1.1/main.sh
Expand Up @@ -8,38 +8,38 @@ venv_path=$4

# Define OS specific help text
if [ "$os" == "Windows" ]; then
conf="\033[33mConfiguring Poetry for Windows!\033[0m"
act="source .venv/scripts/activate"
echo "VENV=.venv/scripts/activate" >> "$GITHUB_ENV"
conf="\033[33mConfiguring Poetry for Windows!\033[0m"
act="source .venv/scripts/activate"
echo "VENV=.venv/scripts/activate" >>"$GITHUB_ENV"
else
conf="\033[33mConfiguring Poetry!\033[0m"
act="source .venv/bin/activate"
echo "VENV=.venv/bin/activate" >> "$GITHUB_ENV"
conf="\033[33mConfiguring Poetry!\033[0m"
act="source .venv/bin/activate"
echo "VENV=.venv/bin/activate" >>"$GITHUB_ENV"
fi

# Echo help texts
echo -e "\n\n-------------------------------------------------------------------------------\n\n$conf 🎉"
if [ "$venv_create" == true ] || [ "$venv_create" == "true" ]; then
# If user is creating a venv in-project we tell them how to activate venv
echo -e "\n\n\033[33mIf you are creating a venv in your project, you can activate it by running '$act'\033[0m"
echo -e "\n\033[33mIf you're running this in an OS matrix, use 'source \$VENV'\033[0m"
# If user is creating a venv in-project we tell them how to activate venv
echo -e "\n\n\033[33mIf you are creating a venv in your project, you can activate it by running '$act'\033[0m"
echo -e "\n\033[33mIf you're running this in an OS matrix, use 'source \$VENV'\033[0m"
fi
if [ "$os" == "Windows" ]; then
# If $SHELL isn't some variation of bash, output a yellow-texted warning
echo -e "\n\n\033[33mMake sure to set your default shell to bash when on Windows.\033[0m"
echo -e "\n\033[33mSee the package docs for more information and examples.\033[0m"
# If $SHELL isn't some variation of bash, output a yellow-texted warning
echo -e "\n\n\033[33mMake sure to set your default shell to bash when on Windows.\033[0m"
echo -e "\n\033[33mSee the package docs for more information and examples.\033[0m"
fi
echo -e '\n-------------------------------------------------------------------------------\n'

# Configure Poetry
if [ "$os" == "Windows" ]; then
ln -s "$HOME/.poetry/bin/poetry.bat" "poetry"
"$HOME/.poetry/bin/poetry.bat" config virtualenvs.create "$venv_create"
"$HOME/.poetry/bin/poetry.bat" config virtualenvs.in-project "$venv_in_project"
"$HOME/.poetry/bin/poetry.bat" config virtualenvs.path "$venv_path"
ln -s "$HOME/.poetry/bin/poetry.bat" "poetry"
"$HOME/.poetry/bin/poetry.bat" config virtualenvs.create "$venv_create"
"$HOME/.poetry/bin/poetry.bat" config virtualenvs.in-project "$venv_in_project"
"$HOME/.poetry/bin/poetry.bat" config virtualenvs.path "$venv_path"
else
source "$HOME"/.poetry/env
poetry config virtualenvs.create "$venv_create"
poetry config virtualenvs.in-project "$venv_in_project"
poetry config virtualenvs.path "$venv_path"
source "$HOME"/.poetry/env
poetry config virtualenvs.create "$venv_create"
poetry config virtualenvs.in-project "$venv_in_project"
poetry config virtualenvs.path "$venv_path"
fi
46 changes: 23 additions & 23 deletions scripts/v1.2/main.sh
Expand Up @@ -11,9 +11,9 @@ installation_script=$6
# Set path for each OS - done because Poetry inference is inconsistent
# on mac-runners, and we need to know the install path so we can add it to $GITHUB_PATH
if [ "$os" == "Windows" ]; then
path="C:/Users/runneradmin/AppData/Roaming/Python/Scripts/"
path="C:/Users/runneradmin/AppData/Roaming/Python/Scripts/"
else
path="$HOME/.local/"
path="$HOME/.local/"
fi

# Install Poetry
Expand All @@ -25,39 +25,39 @@ export PATH="$path/bin:$PATH"

# Configure Poetry
if [ "$os" == "Windows" ]; then
# Adding to path on windows doesn't immediately take effect
# so calling the executable directly here - should be available
# in next steps regardless.
"$path/bin/poetry.exe" config virtualenvs.create "$venv_create"
"$path/bin/poetry.exe" config virtualenvs.in-project "$venv_in_project"
"$path/bin/poetry.exe" config virtualenvs.path "$venv_path"
# Adding to path on windows doesn't immediately take effect
# so calling the executable directly here - should be available
# in next steps regardless.
"$path/bin/poetry.exe" config virtualenvs.create "$venv_create"
"$path/bin/poetry.exe" config virtualenvs.in-project "$venv_in_project"
"$path/bin/poetry.exe" config virtualenvs.path "$venv_path"
else
poetry config virtualenvs.create "$venv_create"
poetry config virtualenvs.in-project "$venv_in_project"
poetry config virtualenvs.path "$venv_path"
poetry config virtualenvs.create "$venv_create"
poetry config virtualenvs.in-project "$venv_in_project"
poetry config virtualenvs.path "$venv_path"
fi

# Define OS specific help texts
if [ "$os" == "Windows" ]; then
conf="\033[33mConfiguring Poetry for Windows!\033[0m"
act="source .venv/scripts/activate"
echo "VENV=.venv/scripts/activate" >>"$GITHUB_ENV"
conf="\033[33mConfiguring Poetry for Windows!\033[0m"
act="source .venv/scripts/activate"
echo "VENV=.venv/scripts/activate" >>"$GITHUB_ENV"
else
conf="\033[33mConfiguring Poetry!\033[0m"
act="source .venv/bin/activate"
echo "VENV=.venv/bin/activate" >>"$GITHUB_ENV"
conf="\033[33mConfiguring Poetry!\033[0m"
act="source .venv/bin/activate"
echo "VENV=.venv/bin/activate" >>"$GITHUB_ENV"
fi

# Output help texts
echo -e "\n\n-------------------------------------------------------------------------------\n\n$conf 🎉"
if [ "$venv_create" == true ] || [ "$venv_create" == "true" ]; then
# If user is creating a venv in-project we tell them how to activate venv
echo -e "\n\n\033[33mIf you are creating a venv in your project, you can activate it by running '$act'\033[0m"
echo -e "\n\033[33mIf you're running this in an OS matrix, use 'source \$VENV'\033[0m"
# If user is creating a venv in-project we tell them how to activate venv
echo -e "\n\n\033[33mIf you are creating a venv in your project, you can activate it by running '$act'\033[0m"
echo -e "\n\033[33mIf you're running this in an OS matrix, use 'source \$VENV'\033[0m"
fi
if [ "$os" == "Windows" ]; then
# If $SHELL isn't some variation of bash, output a yellow-texted warning
echo -e "\n\n\033[33mMake sure to set your default shell to bash when on Windows.\033[0m"
echo -e "\n\033[33mSee the github action docs for more information and examples.\033[0m"
# If $SHELL isn't some variation of bash, output a yellow-texted warning
echo -e "\n\n\033[33mMake sure to set your default shell to bash when on Windows.\033[0m"
echo -e "\n\033[33mSee the github action docs for more information and examples.\033[0m"
fi
echo -e '\n-------------------------------------------------------------------------------\n'

0 comments on commit 4d67864

Please sign in to comment.