-
Notifications
You must be signed in to change notification settings - Fork 5
/
helper.sh
executable file
·74 lines (61 loc) · 2.44 KB
/
helper.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
#!/usr/bin/env bash
# This script will generate a python library from the openapi definition file.
# Note: if running into this error: library initialization failed - unable to allocate file descriptor table - out of memory
# Edit docker systemd service file and add "--default-ulimit nofile=65536:65536" on the ExecStart line
# then systemctl daemon-reload and systemctl restart docker
# the docker image used to generate the client code
# pinning version to avoid unexpected bugs
# see https://github.com/swagger-api/swagger-codegen/releases for updating version below
docker_image="swaggerapi/swagger-codegen-cli-v3:3.0.54"
# where to grab the definition file
openapi_yaml_url="https://raw.githubusercontent.com/elabftw/elabftw/master/apidoc/v2/openapi.yaml"
# folder with the generated python code
lib="generated"
html="html"
function cleanup {
rm -rfv "$lib"
rm -rfv "$html"
}
# generate the lib from remote spec
function generate {
cleanup
docker run --user "$(id -u)":"$(id -u)" --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" -l python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
}
function generate-html {
cleanup
docker run --user "$(id -u)":"$(id -u)" --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" -l html2 -o /local/"$html" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
}
# don't use user/group ids in GH actions
function generate-ci {
docker run --rm -v "${PWD}":/local "$docker_image" generate -i "$openapi_yaml_url" -l python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
# fix permissions
sudo chown -R "$(id -u)":"$(id -gn)" "$lib"
}
# generate the lib from a local file in current directory
function generate-from-local {
cleanup
docker run --user "$(id -u)":"$(id -g)" --rm -v "${PWD}":/local "$docker_image" generate -i /local/openapi.yaml -l python -o /local/"$lib" -c /local/config.json --git-user-id elabftw --git-repo-id elabapi-python
}
function build {
cd "$lib" || exit 1
python setup.py sdist bdist_egg bdist_wheel
cd ..
}
function publish {
generate
build
cd "$lib" || exit 1
twine upload dist/*
cd ..
}
function install-dev {
cd "$lib" || exit 1
python setup.py develop --user
cd ..
}
function build-ci {
generate-ci
cd "$lib" || exit 1
python -m build --sdist --wheel --outdir ../dist
}
"$1"