-
Notifications
You must be signed in to change notification settings - Fork 53
/
main.sh
executable file
·77 lines (60 loc) · 2.77 KB
/
main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
set -eo pipefail
download_script() {
python3 -c 'import urllib.request, sys; print(urllib.request.urlopen(f"{sys.argv[1]}").read().decode("utf8"))' $1
}
INSTALL_PATH="${POETRY_HOME:-$HOME/.local}"
YELLOW="\033[33m"
RESET="\033[0m"
INSTALLATION_SCRIPT="$(mktemp)"
if [ "${RUNNER_OS}" == "Windows" ]; then
download_script https://raw.githubusercontent.com/python-poetry/poetry/48339106eb0d403a3c66519317488c8185844b32/install-poetry.py >"$INSTALLATION_SCRIPT"
else
download_script https://install.python-poetry.org/ >"$INSTALLATION_SCRIPT"
fi
echo -e "\n${YELLOW}Setting Poetry installation path as $INSTALL_PATH${RESET}\n"
echo -e "${YELLOW}Installing Poetry 👷${RESET}\n"
if [ "$VERSION" == "latest" ]; then
# Note: If we quote installation arguments, the call below fails
# shellcheck disable=SC2086
POETRY_HOME=$INSTALL_PATH python3 "$INSTALLATION_SCRIPT" --yes $INSTALLATION_ARGUMENTS
else
# shellcheck disable=SC2086
POETRY_HOME=$INSTALL_PATH python3 "$INSTALLATION_SCRIPT" --yes --version="$VERSION" $INSTALLATION_ARGUMENTS
fi
echo "$INSTALL_PATH/bin" >>"$GITHUB_PATH"
export PATH="$INSTALL_PATH/bin:$PATH"
# 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"
# Parse plugin array from string, handle whitespace or newline delimiters
if ! [ -z "$POETRY_PLUGINS" ]; then
plugins="$(echo $POETRY_PLUGINS | tr -s ' ')" # Replace linesep to space
if [[ "$plugins" && "$plugins" != " " ]]; then
echo "Installing plugins: ${plugins}"
poetry self add ${plugins} || exit 1
fi
fi
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
# When inside a virtualenv, python uses the scripts dir, with no shortcut
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${YELLOW}Installation completed. Configuring settings 🛠${RESET}"
echo -e "\n${YELLOW}Done ✅${RESET}"
if [ "$VIRTUALENVS_CREATE" == true ] || [ "$VIRTUALENVS_CREATE" == "true" ]; then
echo -e "\n${YELLOW}If 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${RESET}"
fi
if [ "$RUNNER_OS" == "Windows" ]; then
echo -e "\n${YELLOW}Make sure to set your default shell to bash when on Windows.${RESET}"
echo -e "\n${YELLOW}See the github action docs for more information and examples.${RESET}"
fi