forked from flosell/trailscraper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgo
executable file
·237 lines (193 loc) · 5.64 KB
/
go
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/bin/bash
set -e
SCRIPT_DIR=$(cd $(dirname $0) ; pwd -P)
VENV_DIR="${SCRIPT_DIR}/venvs/trailscraper-venv${VENV_POSTFIX}"
VERSIONS="3.5
3.6
3.7"
activate_venv() {
source "${VENV_DIR}/bin/activate"
}
goal_regenerate_iam_data_from_cloudonaut() {
tmp_dir=$(mktemp -d)
pushd ${tmp_dir} > /dev/null
git clone --depth 1 git@github.com:widdix/complete-aws-iam-reference.git
cd complete-aws-iam-reference/tools
node md2json.js | \
tee ${SCRIPT_DIR}/tests/iam-actions-from-cloudonaut.json | \
jq -r '.[] | .service+":"+.action' | \
sort | \
uniq > ${SCRIPT_DIR}/tests/iam-actions-from-cloudonaut.txt
popd > /dev/null
}
goal_regenerate_iam_data_from_policy_sim() {
curl https://raw.githubusercontent.com/rvedotrc/aws-iam-reference/master/all-actions.txt |\
sort | \
uniq > ${SCRIPT_DIR}/tests/iam-actions-from-policy-sim.txt
}
goal_merge_iam_data() {
cat ${SCRIPT_DIR}/tests/iam-actions-from-cloudonaut.txt \
${SCRIPT_DIR}/tests/iam-actions-from-policy-sim.txt | \
sort | uniq > ${SCRIPT_DIR}/tests/known-iam-actions.txt
}
goal_regenerate_iam_data() {
goal_regenerate_iam_data_from_cloudonaut
goal_regenerate_iam_data_from_policy_sim
goal_merge_iam_data
}
goal_unknown-actions() {
activate_venv
python3 "${SCRIPT_DIR}/tests/list_unknown_actions.py" > unknown_actions.txt
}
goal_in-version() {
python_version=$1
cmd="/code/go ${@:2}"
echo "=============== BEGIN Python ${python_version} ${cmd} ==============="
docker run -i \
-v $(pwd):/code \
-w /code \
-e VENV_POSTFIX=${python_version} \
python:${python_version} ${cmd}
echo "=============== END Python ${python_version} ${cmd} ==============="
}
goal_in-all-versions() {
if [ "${parallel}" == "parallel" ]; then
parallel --tag "./go in-version {} ${@}" ::: "$VERSIONS"
else
for version in ${VERSIONS}; do
goal_in-version ${version} ${@}
done
fi
}
create_venv() {
python3 --version
pip3 --version
which python3
if which virtualenv > /dev/null; then
virtualenv -p python3 "${VENV_DIR}"
else
pyvenv "${VENV_DIR}"
fi
}
goal_test() {
# make build not fail on travisci when working with boto and moto... https://github.com/spulec/moto/issues/1771
export BOTO_CONFIG=/dev/null
export AWS_SECRET_ACCESS_KEY=foobar_secret
export AWS_ACCESS_KEY_ID=foobar_key
pushd "${SCRIPT_DIR}" > /dev/null
activate_venv
python3 setup.py test
popd > /dev/null
}
goal_check() {
pushd "${SCRIPT_DIR}" > /dev/null
activate_venv
pylint trailscraper
popd > /dev/null
}
goal_trailscraper() {
activate_venv
${VENV_DIR}/bin/trailscraper "$@"
}
goal_generate-rst() {
pushd "${SCRIPT_DIR}" > /dev/null
for f in "README.md" "CHANGELOG.md"; do
output_file="$(basename ${f} .md).rst"
pandoc --from=markdown --to=rst --output="${output_file}" "${f}"
done
popd > /dev/null
}
goal_setup() {
if [ ! -d "${VENV_DIR}" ]; then
create_venv
fi
pushd "${SCRIPT_DIR}" > /dev/null
activate_venv
pip3 install -r requirements-dev.txt
python3 setup.py develop
popd > /dev/null
}
goal_clean() {
rm -rf "${VENV_DIR}"
pushd "${SCRIPT_DIR}" > /dev/null
set +e # It's OK if some of the things we want to delete aren't there
rm -fr build/
rm -fr dist/
rm -fr .eggs/
rm -f README.rst
rm -f CHANGELOG.rst
find . -name '*.egg-info' -exec rm -vfr {} +
find . -name '*.egg' -exec rm -vf {} +
find . -name '*.pyc' -exec rm -vf {} +
find . -name '*.pyo' -exec rm -vf {} +
find . -name '*~' -exec rm -vf {} +
find . -name '__pycache__' -exec rm -vfr {} +
set -e
popd > /dev/null
}
goal_create_github_release() {
# make sure you have the following:
# https://github.com/aktau/github-release
# https://github.com/mtdowling/chag
# $GITHUB_TOKEN is set
pushd "${SCRIPT_DIR}" > /dev/null
VERSION=$(chag latest)
CHANGELOG=$(chag contents)
USER="flosell"
REPO="trailscraper"
echo "Publishing Release to GitHub: "
echo "Version ${VERSION}"
echo "${CHANGELOG}"
echo
github-release release \
--user ${USER} \
--repo ${REPO} \
--tag ${VERSION} \
--name ${VERSION} \
--description "${CHANGELOG}"
echo "Published release on GitHub"
popd > /dev/null
}
goal_tag_version() {
VERSION=$(chag latest)
git tag -s ${VERSION} -m "Release ${VERSION}"
git push --tags
}
goal_bump_version() {
part=${1:-patch}
activate_venv
bumpversion ${part}
}
goal_release() {
goal_test
goal_check
goal_generate-rst
python3 setup.py sdist bdist_wheel upload --sign --identity 'florian.sellmayr@gmail.com'
goal_tag_version
goal_create_github_release
goal_bump_version
git push
}
goal_push() {
goal_test
goal_check
git push
}
if type -t "goal_$1" &>/dev/null; then
goal_$1 "${@:2}"
else
echo "usage: $0 <goal>
goal:
setup -- set up development environment
test -- run all tests
check -- run all style checks
trailscraper -- call the current development state
in-version -- run a go-command in a particular version of python
in-all-versions -- run a go-command in all supported versions of python
release -- create and publish a new release
bump_version -- bump version
regenerate_iam_data -- regenerate list of known iam actions
unknown-actions -- regenerate list of unknown actions
"
exit 1
fi