-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcopy-sdks
executable file
·172 lines (137 loc) · 4.13 KB
/
copy-sdks
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
set -e
DIR=$(cd `dirname $0` && pwd)
SDKS=( dotnet java-v1 java-v2 node php python ruby )
SHOW_HELP=0
TARGET_SDK=
TARGET_VERSION=
REPO_DOTNET="https://github.com/hellosign/dropbox-sign-dotnet.git"
REPO_JAVA_V1="--branch v1 https://github.com/hellosign/dropbox-sign-java.git"
REPO_JAVA_V2="https://github.com/hellosign/dropbox-sign-java.git"
REPO_NODE="https://github.com/hellosign/dropbox-sign-node.git"
REPO_PHP="https://github.com/hellosign/dropbox-sign-php.git"
REPO_PYTHON="https://github.com/hellosign/dropbox-sign-python.git"
REPO_RUBY="https://github.com/hellosign/dropbox-sign-ruby.git"
REPO_MAIN_BRANCH="main"
while getopts ":t:v:h" opt; do
case $opt in
t) TARGET_SDK="$OPTARG"
;;
v) TARGET_VERSION="$OPTARG"
;;
h) SHOW_HELP=1
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
function main() {
if [[ -z ${TARGET_SDK} || -z ${TARGET_VERSION} ]]; then
show_help
exit 0
fi
validate_sdk_choice $TARGET_SDK
copy_files $TARGET_SDK $TARGET_VERSION
printf "Success! Ready for git commit!\n"
exit 0
}
function show_help() {
cat << EOF
Usage: copy-sdks [OPTION]
Copies build files for a given SDK into the repos/[SDK] directory.
**WARNING** All files and directories present in the repos/[SDK] directory will
be DELETED, except for the .git directory!
-t target SDK, "dotnet", "java-v2", "java-v1", "node", "php", "python", "ruby"
-v version of the SDK, ex: 1.4.0
-h display this help and exit
Example: copy-sdks -t php -v 1.4.0
EOF
exit 0
}
function validate_sdk_choice()
{
SDK="$1"
if [[
"${SDK}" != "dotnet" &&
"${SDK}" != "java-v1" &&
"${SDK}" != "java-v2" &&
"${SDK}" != "node" &&
"${SDK}" != "php" &&
"${SDK}" != "python" &&
"${SDK}" != "ruby"
]]; then
printf "Invalid SDK (-t) value: ${SDK}\n"
show_help
exit 1
fi
if [[ "${SDK}" == "java-v1" ]]; then
REPO_MAIN_BRANCH="v1"
fi
}
function copy_files()
{
SDK="$1"
VERSION="$2"
SDK_DIR="${DIR}/repos/${SDK}"
if [[ ! -d "${SDK_DIR}" ]] || [[ ! -d "${SDK_DIR}/.git" ]]; then
repo_not_cloned $SDK
fi
printf "Copying built files for the ${SDK} SDK to ${SDK_DIR}\n"
pushd "${SDK_DIR}/"
git reset --hard origin/${REPO_MAIN_BRANCH}
git pull origin ${REPO_MAIN_BRANCH}
git checkout -b "release-${VERSION}"
git rm -rf --cached .
popd
cp -r "${DIR}/sdks/${SDK}" "${SDK_DIR}-tmp"
cp -r "${SDK_DIR}/.git" "${SDK_DIR}-tmp/"
rm -rf "${SDK_DIR}"
mv "${SDK_DIR}-tmp" "${SDK_DIR}"
pushd "${SDK_DIR}/"
git add .
rm -f "${SDK_DIR}/openapi-sdk.yaml"
rm -rf "${SDK_DIR}/examples"
mkdir -p "${SDK_DIR}/examples"
cp -r "${DIR}/openapi-sdk.yaml" "${SDK_DIR}/openapi-sdk.yaml"
if [[ "${SDK}" == "dotnet" ]]; then
cp -r "${DIR}/examples/"*.cs "${SDK_DIR}/examples/"
elif [[ "${SDK}" == "java-v2" ]] || [[ "${SDK}" == "java-v1" ]]; then
cp -r "${DIR}/examples/"*.java "${SDK_DIR}/examples/"
elif [[ "${SDK}" == "node" ]]; then
cp -r "${DIR}/examples/"*.js "${SDK_DIR}/examples/"
cp -r "${DIR}/examples/"*.ts "${SDK_DIR}/examples/"
elif [[ "${SDK}" == "php" ]]; then
cp -r "${DIR}/examples/"*.php "${SDK_DIR}/examples/"
elif [[ "${SDK}" == "python" ]]; then
cp -r "${DIR}/examples/"*.py "${SDK_DIR}/examples/"
elif [[ "${SDK}" == "ruby" ]]; then
cp -r "${DIR}/examples/"*.rb "${SDK_DIR}/examples/"
fi
php "${DIR}/bin/update-sdk-version.php" ${SDK} ${VERSION}
popd
}
function repo_not_cloned()
{
SDK="$1"
SDK_DIR="${DIR}/repos/${SDK}"
if [[ "${SDK}" == "dotnet" ]]; then
REPO="${REPO_DOTNET}"
elif [[ "${SDK}" == "java-v1" ]]; then
REPO="${REPO_JAVA_V1}"
elif [[ "${SDK}" == "java-v2" ]]; then
REPO="${REPO_JAVA_V2}"
elif [[ "${SDK}" == "node" ]]; then
REPO="${REPO_NODE}"
elif [[ "${SDK}" == "php" ]]; then
REPO="${REPO_PHP}"
elif [[ "${SDK}" == "python" ]]; then
REPO="${REPO_PYTHON}"
elif [[ "${SDK}" == "ruby" ]]; then
REPO="${REPO_RUBY}"
fi
printf "This script expects to find SDK repo cloned at ${SDK_DIR}\n"
printf "Make sure to clone the SDK repo by using the following:\n\n"
printf "git clone ${REPO} ${SDK_DIR}\n"
exit 1
}
main