-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathgo
executable file
·353 lines (286 loc) · 9.17 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/bash
set -e
SCRIPT_DIR=$(cd $(dirname $0) ; pwd -P)
VENV_DIR="${SCRIPT_DIR}/venvs/trailscraper-venv${VENV_POSTFIX}"
VERSIONS="3.9
3.10
3.11
3.12
3.13"
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() {
venv_dir="$1"
python3 --version
pip3 --version
which python3
python3 -m venv "${venv_dir}"
}
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
pytest
popd > /dev/null
}
goal_test-setuptools() {
goal_clean
local last_python_version=$(echo "${VERSIONS}" | sort | tail -n 1)
local python_version="${TRAVIS_PYTHON_VERSION:-${last_python_version}}"
echo "Running Python ${python_version} in clean docker container..."
pushd "${SCRIPT_DIR}" > /dev/null
docker run -i -v $(pwd):/app python:${python_version} bash <<-EOF
cd /app
python setup.py install
echo '{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"s3:GetObject"
],
"Resource":"arn:aws:s3:::my_corporate_bucket/home/${aws:userid}/*"
}
]
}' | trailscraper guess
EOF
popd > /dev/null
}
goal_test-docker-build() {
goal_clean
cd ${SCRIPT_DIR}
docker build -t trailscraper-docker-test .
docker run --rm trailscraper-docker-test --version
}
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 "${VENV_DIR}"
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_bump-homebrew-release() {
local version="$1"
local venv_dir=$(mktemp -d)
local formula_dir="$(brew --repository homebrew/core)/Formula"
local formula_file="${formula_dir}/trailscraper.rb"
local branch_name=trailscraper-${version}-$(date +%s)
create_venv "${venv_dir}"
source "${venv_dir}/bin/activate"
pip install "trailscraper==${version}" homebrew-pypi-poet
export release_url="$(curl -sS https://pypi.org/simple/trailscraper/ | grep -o "https://.*/trailscraper-${version}.tar.gz")"
export release_sha=$(curl -sSLf "${release_url}" | openssl sha256)
export resources=$(poet --formula trailscraper | grep 'resource "' -A 4 | grep -v -- "--")
export old_bottles=$(sed -n '/bottle/,/end/p' ${formula_file})
export version="${version}" # make it available for envsubst
pushd ${formula_dir}
git checkout master
git pull --rebase
git checkout -b ${branch_name}
popd
envsubst < ${SCRIPT_DIR}/homebrew-formula.rb.tpl > ${formula_file}
pushd ${formula_dir}
git add trailscraper.rb
git commit -m "trailscraper ${version}"
git push fork ${branch_name}
hub pull-request --message "$(envsubst < ${SCRIPT_DIR}/pr-message.txt.tpl)" \
--browse \
--draft
git checkout master
popd
}
goal_create_github_container_registry_release() {
local version="$1"
echo $GITHUB_TOKEN | docker login ghcr.io -u flosell --password-stdin
pushd "${SCRIPT_DIR}" > /dev/null
docker build -t ghcr.io/flosell/trailscraper:latest \
-t ghcr.io/flosell/trailscraper:${version} \
.
docker push ghcr.io/flosell/trailscraper:latest
docker push ghcr.io/flosell/trailscraper:${version}
popd > /dev/null
}
goal_release() {
if [ -z "${GITHUB_TOKEN}" ]; then
echo "needs GITHUB_TOKEN"
exit 1
fi
VERSION=$(chag latest)
echo "Version to release is ${VERSION}."
echo
echo "A few things to check:"
echo "* Is this really the version you want to release? Have there been major changes that require a different version?"
echo "* Are you sure that CHANGELOG.md, setup.cfg, setup.py and __init__.py all show this version?"
echo
(cd ${SCRIPT_DIR} && grep ${VERSION} setup.cfg \
setup.py \
CHANGELOG.md \
trailscraper/__init__.py | sed 's/^/ /')
echo
echo "Hit ENTER if you are ok and want to continue"
read
goal_test
goal_check
goal_generate-rst
python3 setup.py sdist bdist_wheel
twine upload --sign --identity 'florian.sellmayr@gmail.com' dist/*
goal_tag_version
goal_create_github_release
goal_create_github_container_registry_release ${VERSION}
goal_bump_version
git push
goal_bump-homebrew-release ${VERSION}
}
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 functional tests
test-setuptools -- run a smoke-test after installing in a clean environment
test-docker-build -- run a smoke-test after building a clean docker container
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