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

Move main script to main.sh #70

Merged
merged 6 commits into from Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions action.yml
Expand Up @@ -34,3 +34,10 @@ runs:
- name: Install and configure Poetry
run: /bin/bash $GITHUB_ACTION_PATH/main.sh
shell: bash
env:
VERSION: ${{ inputs.version }}
VIRTUALENVS_CREATE: ${{ inputs.virtualenvs-create }}
VIRTUALENVS_IN_PROJECT: ${{ inputs.virtualenvs-in-project }}
VIRTUALENVS_PATH: ${{ inputs.virtualenvs-path }}
INSTALLER_PARALLEL: ${{ inputs.installer-parallel }}
Comment on lines +38 to +42
Copy link
Member

@sondrelg sondrelg Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poetry supports environment variables for settings (docs). I wonder if we might be able to kill two birds with one stone here. Perhaps we can rename the env vars to POETRY_* and drop code like this from the shell script completely

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

Needs testing, but unless I'm mistaken this should be inferred by Poetry if we do this, so the extra specification will become redundant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this works out, I think it might also be worth checking if a user can overwrite our env vars using the env tag when specifying the action, like this:

- uses: snok/install-poetry@v1
  with:
    version: 1.1.10
  env:
    POETRY_VERSION: 1.1.13

It would be great if the POETRY_VERSION here would take precedence, but I'm guessing it wouldn't.

INSTALLATION_ARGUMENTS: ${{ inputs.installation-arguments }}
24 changes: 12 additions & 12 deletions main.sh
Expand Up @@ -3,7 +3,7 @@
installation_script="$(mktemp)"
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/48339106eb0d403a3c66519317488c8185844b32/install-poetry.py --output "$installation_script"

if [ "${{ runner.os }}" == "Windows" ]; then
if [ "${RUNNER_OS}" == "Windows" ]; then
path="C:/Users/runneradmin/AppData/Roaming/Python/Scripts"
else
path="$HOME/.local/"
Expand All @@ -12,32 +12,32 @@ fi
echo -e "\n\033[33mSetting Poetry installation path as $path\033[0m\n"
echo -e "\033[33mInstalling Poetry 👷\033[0m\n"

if [ "${{ inputs.version }}" == "latest" ]; then
POETRY_HOME=$path python3 $installation_script --yes ${{ inputs.installation-arguments}}
if [ "${VERSION}" == "latest" ]; then
POETRY_HOME=$path python3 $installation_script --yes ${INSTALLATION_ARGUMENTS}
else
POETRY_HOME=$path python3 $installation_script --yes --version=${{ inputs.version }} ${{ inputs.installation-arguments}}
POETRY_HOME=$path python3 $installation_script --yes --version=${VERSION} ${INSTALLATION_ARGUMENTS}
fi

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

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

$poetry_ config virtualenvs.create ${{ inputs.virtualenvs-create }}
$poetry_ config virtualenvs.in-project ${{ inputs.virtualenvs-in-project }}
$poetry_ config virtualenvs.path ${{ inputs.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)"

if echo "$config" | grep -q -c "installer.parallel"; then
$poetry_ config installer.parallel "${{ inputs.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"
else
Expand All @@ -48,10 +48,10 @@ fi
echo -e "\n\033[33mInstallation completed. Configuring settings 🛠\033[0m"
echo -e "\n\033[33mDone ✅\033[0m"

if [ "${{ inputs.virtualenvs-create }}" == true ] || [ "${{ inputs.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