aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts
diff options
context:
space:
mode:
authorAverage Dude <loveisgrief@tuta.io>2020-02-14 14:14:14 +0100
committerRigel Kent <sendmemail@rigelk.eu>2020-02-14 14:14:14 +0100
commit002df3813d13c5accd36d7943af2b17376a6d1ac (patch)
tree58729dae12b53c0f368212ce334826b8093c6f4a /scripts
parent68ca61941e3a7ca4c018566d2c496afd27dbd76d (diff)
downloadPeerTube-002df3813d13c5accd36d7943af2b17376a6d1ac.tar.gz
PeerTube-002df3813d13c5accd36d7943af2b17376a6d1ac.tar.zst
PeerTube-002df3813d13c5accd36d7943af2b17376a6d1ac.zip
OpenAPI clients generation
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/openapi-clients.sh81
-rwxr-xr-xscripts/openapi-peertube-version.sh5
2 files changed, 86 insertions, 0 deletions
diff --git a/scripts/openapi-clients.sh b/scripts/openapi-clients.sh
new file mode 100755
index 000000000..b031ceac1
--- /dev/null
+++ b/scripts/openapi-clients.sh
@@ -0,0 +1,81 @@
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/
30set -euo pipefail
31IFS=$'\n\t '
32
33# Set default values
34API_URL_USERNAME="${API_URL_USERNAME:-$API_GIT_USER}"
35API_PATH_PREFIX="${API_PATH_PREFIX:-}"
36API_REPO_HOST=${API_REPO_HOST:-framagit.org}
37
38echo "API_GIT_USER='${API_GIT_USER}'"
39echo "API_URL_USERNAME='${API_URL_USERNAME}'"
40echo "API_LANGS='${API_LANGS}'"
41
42git config --global user.email "${API_GIT_EMAIL}"
43git config --global user.name "${API_GIT_USER}"
44
45for lang in ${API_LANGS//:/ } ; do
46(
47 echo "Generating client API libs for $lang"
48
49 out_dir_prefix="dist/api/${API_PATH_PREFIX}"
50 out_dir="${out_dir_prefix}/${lang}"
51 git_repo_id="${API_PATH_PREFIX}${lang}"
52 host_path="${API_REPO_HOST}/${API_URL_USERNAME}/${git_repo_id}.git"
53 git_remote="https://${API_GIT_USER}:${GIT_TOKEN}@${host_path}"
54 if ! [ -e "$out_dir" ] ; then
55 # Make sure the prefix exists before cloning the repo
56 mkdir -p "${out_dir_prefix}"
57 git clone "https://${host_path}" "$out_dir"
58 fi
59
60 npx openapi-generator generate \
61 -i support/doc/api/openapi.yaml \
62 -c "support/openapi/${lang}.yaml" \
63 -g "$lang" \
64 --git-host "${API_REPO_HOST}" \
65 --git-user-id "${API_URL_USERNAME}" \
66 --git-repo-id "${git_repo_id}" \
67 -o "${out_dir}"
68
69 # Commit and push changes to the remote
70 cd "$out_dir"
71 git remote set-url origin "$git_remote"
72 # Make sure something has changed
73 if [[ $(git status -s | wc -l) = 0 ]] ; then
74 echo "No changes from previous version"
75 continue
76 fi
77 git add .
78 git commit -m "${API_COMMIT_MSG:-"Minor update $lang"}"
79 git push
80)
81done
diff --git a/scripts/openapi-peertube-version.sh b/scripts/openapi-peertube-version.sh
index 4eb481e64..49154a5f3 100755
--- a/scripts/openapi-peertube-version.sh
+++ b/scripts/openapi-peertube-version.sh
@@ -4,3 +4,8 @@
4PACKAGE_VERSION=$(node -p "require('./package.json').version") 4PACKAGE_VERSION=$(node -p "require('./package.json').version")
5 5
6sed -i "s/\(^\s*\)version: .*/\1version: $PACKAGE_VERSION/" ./support/doc/api/openapi.yaml 6sed -i "s/\(^\s*\)version: .*/\1version: $PACKAGE_VERSION/" ./support/doc/api/openapi.yaml
7
8# Sets the package version for libs
9echo "packageVersion: $PACKAGE_VERSION" >> ./support/openapi/go.yaml
10echo "artifactVersion: $PACKAGE_VERSION" >> ./support/openapi/kotlin.yaml
11echo "packageVersion: $PACKAGE_VERSION" >> ./support/openapi/python.yaml