Skip to content

Commit 8f1c727

Browse files
authored
feat: use fixed sdk version commit ref from file (#127)
* feat: use fixed api version commit ref from file * fix: allow passing the branch of the go sdk * fix: shell issue
1 parent 0ed5b09 commit 8f1c727

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
ROOT_DIR ?= $(shell git rev-parse --show-toplevel)
22
SCRIPTS_BASE ?= $(ROOT_DIR)/scripts
3+
API_VERSION ?= $(shell cat api_version|grep -v '^\#'|head -n 1)
4+
SDK_BRANCH ?= main
35

46
# SETUP AND TOOL INITIALIZATION TASKS
57
project-help:
@@ -10,7 +12,8 @@ project-tools:
1012

1113
# GENERATE
1214
download-oas:
13-
@$(SCRIPTS_BASE)/download-oas.sh "$(OAS_REPO_NAME)" "$(OAS_REPO)" "$(ALLOW_ALPHA)"
15+
@$(SCRIPTS_BASE)/download-oas.sh "$(OAS_REPO_NAME)" "$(OAS_REPO)" "$(ALLOW_ALPHA)" "$(API_VERSION)"
16+
1417
generate-sdk:
15-
@$(SCRIPTS_BASE)/generate-sdk/generate-sdk.sh "$(GIT_HOST)" "$(GIT_USER_ID)" "$(GIT_REPO_ID)" "$(SDK_REPO_URL)" "$(LANGUAGE)"
18+
@$(SCRIPTS_BASE)/generate-sdk/generate-sdk.sh "$(GIT_HOST)" "$(GIT_USER_ID)" "$(GIT_REPO_ID)" "$(SDK_REPO_URL)" "$(LANGUAGE)" "$(SDK_BRANCH)"
1619

api_version

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 2e3768b7b65237391fc587eddd559451f2b183a6
2+
# comments are allowed!
3+
main

scripts/download-oas.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ROOT_DIR=$(git rev-parse --show-toplevel)
66
OAS_REPO_NAME=$1
77
OAS_REPO=$2
88
ALLOW_ALPHA=$3
9+
OAS_API_VERSION=$4
910

1011
if [[ -z ${OAS_REPO_NAME} ]]; then
1112
echo "Repo name is empty, default public OAS repo name will be used."
@@ -17,6 +18,11 @@ if [[ ! ${OAS_REPO} || -d ${OAS_REPO} ]]; then
1718
OAS_REPO="https://github.com/stackitcloud/${OAS_REPO_NAME}.git"
1819
fi
1920

21+
if [[ -z ${OAS_API_VERSION} ]]; then
22+
echo "No API version passed, main branch will be used"
23+
OAS_API_VERSION="main"
24+
fi
25+
2026
# Create temp directory to clone OAS repo
2127
work_dir=$(mktemp -d)
2228
if [[ ! ${work_dir} || -d {work_dir} ]]; then
@@ -35,6 +41,11 @@ mkdir ${ROOT_DIR}/oas
3541
cd ${work_dir}
3642
git clone ${OAS_REPO} --quiet
3743

44+
echo "Using api version ${OAS_API_VERSION}"
45+
cd ${OAS_REPO_NAME}
46+
git checkout --quiet ${OAS_API_VERSION}
47+
cd -
48+
3849
for service_dir in ${work_dir}/${OAS_REPO_NAME}/services/*; do
3950
max_version_dir=""
4051
max_version=-1

scripts/generate-sdk/generate-sdk.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ GIT_USER_ID=$2
99
GIT_REPO_ID=$3
1010
SDK_REPO_URL=$4
1111
LANGUAGE=$5
12+
SDK_BRANCH=$6
1213

1314
# Global variables
1415
ROOT_DIR=$(git rev-parse --show-toplevel)
@@ -32,6 +33,11 @@ if [[ -z ${LANGUAGE} ]]; then
3233
LANGUAGE="go"
3334
fi
3435

36+
if [[ -z ${SDK_BRANCH} ]]; then
37+
echo "SDK_BRANCH not specified, main branch will be used."
38+
SDK_BRANCH=main
39+
fi
40+
3541
# Check dependencies
3642
if type -p java >/dev/null; then
3743
:
@@ -78,7 +84,7 @@ go)
7884

7985
source ${LANGUAGE_GENERATORS_FOLDER_PATH}/${LANGUAGE}.sh
8086
# Usage: generate_go_sdk GENERATOR_PATH GIT_HOST GIT_USER_ID [GIT_REPO_ID] [SDK_REPO_URL]
81-
generate_go_sdk ${jar_path} ${GIT_HOST} ${GIT_USER_ID} ${GIT_REPO_ID} ${SDK_REPO_URL}
87+
generate_go_sdk "${jar_path}" "${GIT_HOST}" "${GIT_USER_ID}" "${GIT_REPO_ID}" "${SDK_REPO_URL}" "${SDK_BRANCH}"
8288
;;
8389
python)
8490
echo -e "\n>> Generating the Python SDK..."

scripts/generate-sdk/languages/go.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ generate_go_sdk() {
2727
# Optional parameters
2828
local GIT_REPO_ID=$4
2929
local SDK_REPO_URL=$5
30+
local SDK_BRANCH=$6
3031

3132
# Check required parameters
3233
if [[ -z ${GIT_HOST} ]]; then
@@ -75,6 +76,7 @@ generate_go_sdk() {
7576

7677
# Install SDK project tools
7778
cd ${SDK_REPO_LOCAL_PATH}
79+
git checkout ${SDK_BRANCH}
7880
make project-tools
7981

8082
# Backup of the current state of the SDK services dir (services/)

0 commit comments

Comments
 (0)