generated from openziti/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_client.sh
executable file
·68 lines (59 loc) · 1.84 KB
/
generate_client.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
#!/usr/bin/env bash
REPO="openziti/edge-api"
CONTAINER_TAG="v6.6.0"
function _generate {
local tag="$1"
echo "Generating client for tag: $tag"
docker run \
--cap-add ALL \
--rm \
--volume "${PWD}":/out:Z \
docker.io/openapitools/openapi-generator-cli:$CONTAINER_TAG generate \
--generator-name python-prior \
--git-host 'github.com' \
--git-repo-id 'openziti-edge-client-python' \
--git-user-id 'openziti-test-kitchen' \
--input-spec "https://raw.githubusercontent.com/$REPO/$tag/client.yml" \
--output '/out' \
--package-name 'openziti_edge_client' \
--additional-properties=packageVersion="${tag#v}" \
--additional-properties=packageUrl="https://github.com/openziti-test-kitchen/openziti-edge-client-python"
}
function _get_latest_tag {
curl -sSL "https://api.github.com/repos/$REPO/tags" \
| jq -r '[.[] | select(.name | startswith("v")) | .name][0]'
}
function _test_tag_exists {
local tag="$1"
local tags
tags="$(curl -sSL "https://api.github.com/repos/$REPO/tags")"
if ! jq --arg tag "$tag" '[.[] | select(.name == $tag)][0] or error("err")' <<< "$tags" &> /dev/null; then
echo "Tag does not exist: $tag" >&2
echo "Valid tags are:"
jq -r '.[].name' <<< "$tags"
exit 1
fi
}
function local_modify {
grep -q 'tags' .gitignore || echo 'tags' >> .gitignore
}
function _usage {
echo "usage: ./generate_client.sh v0.24.83" >&2
}
function _main {
local tag
if [ -z "$1" ]; then
tag="$(_get_latest_tag)"
else
tag="$1"
if ! [[ "$tag" =~ ^v([0-9]+\.){2}[0-9]+ ]]; then
echo "Tag is not a valid version" >&2
_usage
exit 1
fi
_test_tag_exists "$tag"
fi
_generate "$tag"
local_modify
}
_main "$@"