forked from dvndrsn/M3uParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·90 lines (74 loc) · 2 KB
/
release.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
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
# shellcheck disable=SC2046,SC2086,SC2162
cat << 'DESCRIPTION' >/dev/null
release.sh
Reads .env for PyPi token and publishes to PyPi or TestPyPi
USAGE
./release.sh
NOTES
- Requires poetry
- Requires pyproject.toml in project root
- Requires .env file in project root
- POETRY_PYPI_TOKEN_PYPI is the PyPi token (prod)
- POETRY_TEST_PYPI_TOKEN_PYPI is the TestPyPi token (dev)
- REPO can be either "dev" (TestPyPi) or "prod" (PyPi)
DESCRIPTION
GIT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)"
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
# get the root directory
if [ -n "$GIT_ROOT" ]; then
TLD="$(git rev-parse --show-toplevel)"
else
TLD="${SCRIPT_DIR}"
fi
ENV_FILE="${TLD}/.env"
# source .env file skipping commented lines
if [ -f "${ENV_FILE}" ]; then
export $(grep -v '^#' ${ENV_FILE} | xargs)
else
echo ".env file not found in ${TLD}"
exit 1
fi
# verify pyproject.toml is present
if [ ! -f "${TLD}/pyproject.toml" ]; then
echo "pyproject.toml not found in ${TLD}"
exit 1
fi
# get pypi token
if [[ -z "$POETRY_PYPI_TOKEN_PYPI" ]]; then
read -s -p "Please enter your PyPi auth token: " POETRY_PYPI_TOKEN_PYPI
fi
# add testpypi repo if test pypi token is present (optional)
if [[ -n "$POETRY_TEST_PYPI_TOKEN_PYPI" ]]; then
poetry config repositories.testpypi "https://test.pypi.org/legacy/"
fi
# get repo
if [[ -z "$REPO" ]]; then
read -p "Please enter the repo to publish to (dev/prod): " REPO
fi
# build (if older than n minutes)
if find ./dist -mmin -30 2> /dev/null | grep -q dist; then
echo "Skipping build"
else
echo "Building..."
poetry run build # binary
poetry build # source (uploads to pypi)
fi
# publish
case "$REPO" in
dev)
poetry publish -u "__token__" -p "$POETRY_TEST_PYPI_TOKEN_PYPI" -r "testpypi"
;;
prod)
poetry publish -u "__token__" -p "$POETRY_PYPI_TOKEN_PYPI"
;;
"")
echo "No repo specified"
exit 1
;;
*)
echo "Invalid repo specified"
exit 1
;;
esac
exit 0