Skip to content

Commit

Permalink
Merge pull request #70 from connortann/linting
Browse files Browse the repository at this point in the history
Move main script to main.sh
  • Loading branch information
sondrelg committed Feb 12, 2022
2 parents 881124a + 46d7fcb commit 70666d3
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 58 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
@@ -0,0 +1,7 @@

# Ensure git handles line endings correctly
# Set the default behavior, in case core.autocrlf is not set.
* text=auto

# Ensure shell scripts are strictly linux-style
*.sh text eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -139,7 +139,7 @@ jobs:
# feel free to update it
- run: |
source .github/scripts/assert.sh
assert_in "1.1.12" "$(poetry --version)"
assert_in "1.1.13" "$(poetry --version)"
# Make sure scripts are not deleted.
# If we deleted the scripts folder (or subfolders) by accident,
Expand Down
65 changes: 8 additions & 57 deletions action.yml
Expand Up @@ -32,61 +32,12 @@ runs:
using: "composite"
steps:
- name: Install and configure Poetry
run: |
installation_script="$(mktemp)"
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/48339106eb0d403a3c66519317488c8185844b32/install-poetry.py --output "$installation_script"
if [ "${{ runner.os }}" == "Windows" ]; then
path="C:/Users/runneradmin/AppData/Roaming/Python/Scripts"
else
path="$HOME/.local/"
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}}
else
POETRY_HOME=$path python3 $installation_script --yes --version=${{ inputs.version }} ${{ inputs.installation-arguments}}
fi
echo "$path/bin" >>$GITHUB_PATH
export PATH="$path/bin:$PATH"
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 }}
config="$($poetry_ config --list)"
if echo "$config" | grep -q -c "installer.parallel"; then
$poetry_ config installer.parallel "${{ inputs.installer-parallel }}"
fi
if [ "${{ runner.os }}" == "Windows" ]; then
act="source .venv/scripts/activate"
echo "VENV=.venv/scripts/activate" >>"$GITHUB_ENV"
else
act="source .venv/bin/activate"
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 [ "${{ inputs.virtualenvs-create }}" == true ] || [ "${{ inputs.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
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
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 }}
INSTALLATION_ARGUMENTS: ${{ inputs.installation-arguments }}
60 changes: 60 additions & 0 deletions main.sh
@@ -0,0 +1,60 @@
#!/usr/bin/env bash

installation_script="$(mktemp)"
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/48339106eb0d403a3c66519317488c8185844b32/install-poetry.py --output "$installation_script"

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

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}
else
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
poetry_="$path/bin/poetry.exe"
else
poetry_=poetry
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}

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

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

if [ "${RUNNER_OS}" == "Windows" ]; then
act="source .venv/scripts/activate"
echo "VENV=.venv/scripts/activate" >>"$GITHUB_ENV"
else
act="source .venv/bin/activate"
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
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
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

0 comments on commit 70666d3

Please sign in to comment.