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

fix: set proper scripts for for windows #1

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -16,6 +16,11 @@ env:
LATEST_PYTHON: "3.10"
LATEST_POETRY: "1.2.2"

concurrency:
# The concurrency section allows previous runs to be cancelled when commits are added or force pushed
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
# The set-env job translates our json variables to a format we
# can use in our workflow specifications. Without this step,
Expand Down Expand Up @@ -123,6 +128,7 @@ jobs:
source .github/scripts/assert.sh
echo "$output"
assert_in "/install-poetry/install-poetry/.venv" "$output"
echo "VENV=$VENV"
source $VENV
pytest --version

Expand Down
42 changes: 16 additions & 26 deletions main.sh
Expand Up @@ -5,61 +5,51 @@ set -eo pipefail
installation_script="$(mktemp)"
curl -sSL https://install.python-poetry.org/ --output "$installation_script"

if [ "${RUNNER_OS}" == "Windows" ]; then
path="C:/Users/runneradmin/AppData/Roaming/Python/Scripts"
else
path="$HOME/.local"
fi
path="$HOME/.local"

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

echo "$path/bin" >>"$GITHUB_PATH"
echo "$path/bin" >> $GITHUB_PATH
export PATH="$path/bin:$PATH"

if [ "${RUNNER_OS}" == "Windows" ]; then
poetry_="$path/bin/poetry.exe"
else
poetry_=poetry
fi

# Expand any "~" in VIRTUALENVS_PATH
VIRTUALENVS_PATH="${VIRTUALENVS_PATH/#\~/$HOME}"
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
if [ "$RUNNER_OS" == "Windows" ]; then
act="source .venv/scripts/activate"
echo "VENV=.venv/scripts/activate" >>"$GITHUB_ENV"
echo "VENV=.venv/scripts/activate" >> "$GITHUB_ENV"
else
act="source .venv/bin/activate"
echo "VENV=.venv/bin/activate" >>"$GITHUB_ENV"
echo "VENV=.venv/bin/activate" >> "$GITHUB_ENV"
fi

echo -e "\n\033[33mInstallation completed. Configuring settings 🛠\033[0m"
echo -e "\n\033[33mDone ✅\033[0m"

if [ "${VIRTUALENVS_CREATE}" == true ] || [ "${VIRTUALENVS_CREATE}" == "true" ]; then
if [ "$VIRTUALENVS_CREATE" == true ] || [ "$VIRTUALENVS_CREATE" == "true" ]; then
echo -e "\n\033[33mIf you are creating a venv in your project, you can activate it by running '$act'. If you're running this in an OS matrix, you can use 'source \$VENV' instead, as an OS agnostic option\033[0m"
fi
if [ "${RUNNER_OS}" == "Windows" ]; then
if [ "$RUNNER_OS" == "Windows" ]; then
echo -e "\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