-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy_tests.sh
More file actions
executable file
·153 lines (121 loc) · 2.87 KB
/
Copy pathdeploy_tests.sh
File metadata and controls
executable file
·153 lines (121 loc) · 2.87 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
# == Failure handling (fast-fail and warnings)
set -euo pipefail
shopt -s inherit_errexit
ok=1
check(){
if [ $ok -ne 0 ]
then
cat $_log
printf "\033[31mPackage is not ready to deploy."
printf " See error(s) above.\033[0m\n"
else
printf "\033[32mPackage checks out.\033[0m\n"
fi
}
trap check exit
# == Prepare work place
wd=$(pwd)
base=../__amaze_deploy_test__/
mkdir -pv $base
download_cache=$(realpath $base/download_cache)
mkdir -pv $download_cache
_log="$base/global.log"
log(){
if [ $# -gt 1 ]
then
color=$1
shift
else
color=32
fi
printf "\033[${color}m$1\033[0m\n" | tee -a $_log
}
log "$(date)"
log 35 "working directory: $wd"
log 35 "download cache = $download_cache"
cols=$(($(tput cols) - 2))
short_output(){
tee -a $_log - 2>&1 | stdbuf -o0 awk -vc=$cols '
{
printf "%s", substr($0, 0, c);
for (i=length; i<c; i++) printf " ";
printf "\r";
}'
printf " %.0s" $(seq $cols)
printf "\r"
}
# == Sanity checks
if grep -rn 'from amaze' src
then
log 31 "Absolute imports in sources"
exit 2
fi
black src tests examples
flake8 src tests examples
# Worker
deploy(){
type=$1
type_name=$(tr "," "_" <<< $type)
if [ -z "$type_name" ]
then
type_name=default
spec=""
else
spec="[$type]"
fi
line
folder=$base/$type_name
rm -rf $folder
mkdir -pv $folder
folder=$(realpath $wd/$folder)
_log=$folder.log
log 35 "deploy folder = $folder"
log 35 "Processing spec '$spec'"
install(){
python -m pip download -d $download_cache $@ | short_output
python -m pip install --upgrade --find-links=$download_cache $@ | short_output
}
git ls-files | tar Tc - | tar Cx $folder
cd $folder
# git clone --depth 1 https://github.com/kgd-al/amaze.git .
date > $_log
log Copied
python -m venv _venv
source _venv/bin/activate
log "Created virtual environment"
install pip setuptools
log "Installed build essentials"
if [ "$type" == "docs" ]
then
install sphinx readthedocs-sphinx-ext
log "Installed docs build essentials"
fi
log "Installing package and dependencies for spec '$spec'"
install .$spec
r=$?
log "Installed package and dependencies: $r"
pip list | tee -a $_log
if [ "$type" == "docs" ]
then
log "Building documentation"
./commands.sh docs 2>&1 | short_output
log "Documentation built"
cd -
elif [[ "$type" =~ "tests" ]]
then
pytest --small-scale --test-examples --test-extension sb3
fi
deactivate
cd $wd
rm -rf $folder && echo "Cleared test folder" | tee -a $_log
line
}
# Work
for type in '' 'full' 'docs' 'tests,dev'
#for type in 'tests,dev'
do
deploy "$type"
done
# Got to the end without error!
ok=0