]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - scripts/openapi-clients.sh
Try to fix openapi script
[github/Chocobozzz/PeerTube.git] / scripts / openapi-clients.sh
1 #!/bin/bash
2 # Required environment vars
3 # =========================
4 # API_LANGS
5 # A ':' delimited list of the client lib languages to be generated
6 # API_GIT_USER
7 # The user that will be used to push/pull from the APIs repos
8 # API_GIT_EMAIL
9 # The git email
10 # GIT_TOKEN
11 # A personal access token for github or gilab for pushing to repos
12 # !!!This is a secret and shouldn't be logged publicly!!!
13
14 # (Optional environment vars)
15 # ===========================
16 # API_COMMIT_MSG
17 # A message to use when committing to the lib repo
18 # API_PATH_PREFIX
19 # Will be used for building the URL to the repo and path to checkout.
20 # !!! End with a slash "/", otherwise the prefix will be tacked onto the language
21 # API_URL_USERNAME
22 # The username to use building the URL to the git repo.
23 # Default: API_GIT_USER
24 # API_REPO_HOST
25 # Whoever's hosting the repo e.g gitlab.com, github.com, etc.
26 # Default: framagit.org
27
28 # Unofficial bash strict mode
29 # https://web.archive.org/web/20190115051613/https://redsymbol.net/articles/unofficial-bash-strict-mode/
30 set -euo pipefail
31 IFS=$'\n\t '
32
33 # Set default values
34 API_URL_USERNAME="${API_URL_USERNAME:-$API_GIT_USER}"
35 API_PATH_PREFIX="${API_PATH_PREFIX:-}"
36 API_REPO_HOST=${API_REPO_HOST:-framagit.org}
37
38 echo "API_GIT_USER='${API_GIT_USER}'"
39 echo "API_URL_USERNAME='${API_URL_USERNAME}'"
40 echo "API_LANGS='${API_LANGS}'"
41
42 git config --global user.email "${API_GIT_EMAIL}"
43 git config --global user.name "${API_GIT_USER}"
44
45 for lang in ${API_LANGS//:/ } ; do
46 (
47 echo "Generating client API libs for $lang"
48
49 lang_dir="support/openapi/${lang}"
50
51 out_dir_prefix="dist/api/${API_PATH_PREFIX}"
52 out_dir="${out_dir_prefix}/${lang}"
53 git_repo_id="${API_PATH_PREFIX}${lang}"
54 host_path="${API_REPO_HOST}/${API_URL_USERNAME}/${git_repo_id}.git"
55 git_remote="https://${API_GIT_USER}:${GIT_TOKEN}@${host_path}"
56 if ! [ -e "$out_dir" ] ; then
57 # Make sure the prefix exists before cloning the repo
58 mkdir -p "${out_dir_prefix}"
59 git clone "https://${host_path}" "$out_dir"
60 fi
61
62 npx @openapitools/openapi-generator-cli generate \
63 -i support/doc/api/openapi.yaml \
64 -c "${lang_dir}/def.yaml" \
65 -t "${lang_dir}" \
66 -g "$lang" \
67 --skip-validate-spec
68 --git-host "${API_REPO_HOST}" \
69 --git-user-id "${API_URL_USERNAME}" \
70 --git-repo-id "${git_repo_id}" \
71 -o "${out_dir}"
72
73 # Commit and push changes to the remote
74 cd "$out_dir"
75 git remote set-url origin "$git_remote"
76 # Make sure something has changed
77 if [[ $(git status -s | wc -l) = 0 ]] ; then
78 echo "No changes from previous version"
79 continue
80 fi
81 git add .
82 git commit -m "${API_COMMIT_MSG:-"Minor update $lang"}"
83 git push
84 )
85 done