-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
79 lines (67 loc) · 1.78 KB
/
build
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
#!/usr/bin/env bash
BLACK="\e[30m"
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
BLUE="\e[34m"
MAGENTA="\e[35m"
CYAN="\e[36m"
LIGHT_GRAY="\e[37m"
GRAY="\e[91m"
LIGHT_RED="\e[91m"
LIGHT_GREEN="\e[92m"
LIGHT_YELLOW="\e[93m"
LIGHT_BLUE="\e[94m"
LIGHT_MAGENTA="\e[95m"
LIGHT_CYAN="\e[96m"
WHITE="\e[97m"
RESET="\e[0m"
function colorize {
local color="$1"
echo -e "${!color}$2${RESET}"
}
function pyproject_version {
echo $(grep 'version = ' pyproject.toml | sed 's/version = //; s/"//g')
}
function pseudocode_version {
echo $(grep '__version__ = ' pseudocode/__init__.py | sed "s/__version__ = //; s/'//g")
}
# Code checking
# Run unittest and mypy checks
if ! python -m unittest; then
colorize RED "Unit tests failed"
exit 1
elif ! python -m mypy pseudocode; then
colorize RED "mypy check failed"
exit 1
fi
# Build
# If version number is not provided, prompt user to build
# If response is 'y', proceed to build, then exit
# If version number is provided, build then proceed to publish
VERSION="$1"
if [[ -z "$VERSION" ]]; then
echo -n "Proceed to build pseudo (y/N)? "
read proceed
if [[ "${proceed,,}" != "y" ]]; then
exit 1
fi
poetry build
exit 1
else
poetry build
fi
# Publish
# Check for matching version numbers in pseudocode/__init__.py
# and pyproject.toml before publishing
if [[ "$VERSION" != $(pseudocode_version) ]]; then
colorize RED "pseudocode/__init__.py: Version is $(pseudocode_version), expected ${VERSION}"
exit 1
fi
if [[ "$VERSION" != $(pyproject_version) ]]; then
colorize RED "pyproject.toml: Version is $(pyproject_version), expected ${VERSION}"
exit 1
fi
# Configure credentials to avoid poetry's authentication prompt
# See https://python-poetry.org/docs/repositories/#configuring-credentials
poetry publish