Skip to content

Commit

Permalink
Merge pull request #91 from snok/lint
Browse files Browse the repository at this point in the history
Lint shell scripts
  • Loading branch information
sondrelg authored Oct 7, 2022
2 parents 5812725 + c5011cb commit e3dbfd3
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.sh]
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .github/scripts/assert.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

set -eo pipefail

assert_in_one() {
local option1="$1"
local option2="$2"
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ repos:
hooks:
- id: check-github-actions
- id: check-github-workflows

- repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0
hooks:
- id: shfmt
- id: shellcheck
files: 'main\/.sh'
41 changes: 23 additions & 18 deletions main.sh
Original file line number Diff line number Diff line change
@@ -1,60 +1,65 @@
#!/usr/bin/env bash

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"
path="C:/Users/runneradmin/AppData/Roaming/Python/Scripts"
else
path="$HOME/.local/"
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}
# 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"
export PATH="$path/bin:$PATH"

if [ "${RUNNER_OS}" == "Windows" ]; then
poetry_="$path/bin/poetry.exe"
poetry_="$path/bin/poetry.exe"
else
poetry_=poetry
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}
"$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
act="source .venv/scripts/activate"
echo "VENV=.venv/scripts/activate" >>"$GITHUB_ENV"
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"
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"
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"
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
4 changes: 2 additions & 2 deletions scripts/v1.1/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ venv_path=$4
if [ "$os" == "Windows" ]; then
conf="\033[33mConfiguring Poetry for Windows!\033[0m"
act="source .venv/scripts/activate"
echo "VENV=.venv/scripts/activate" >> "$GITHUB_ENV"
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"
echo "VENV=.venv/bin/activate" >>"$GITHUB_ENV"
fi

# Echo help texts
Expand Down

0 comments on commit e3dbfd3

Please sign in to comment.