Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,40 @@ To rebuild all SDKs run `./generate-sdks -t all`.

Changes will appear against the [/sdks](sdks) directory. Make sure to include these changes in your pull requests!

### Releasing SDKs

The [copy-sdks](copy-sdks) script copies built SDK files from [/sdks](sdks) into the [/repos](repos) directory, updates version numbers, commits, and pushes a release branch.

You can release a single SDK with an explicit version:

```bash
./copy-sdks -t php -v 1.4.0
```

Or release multiple SDKs at once, with automatic version bumps (reads the current version from `repos/[SDK]/VERSION`):

```bash
./copy-sdks -t python,node,ruby # specific SDKs, auto-bump minor
./copy-sdks -t all # all SDKs, auto-bump minor
./copy-sdks -t all -b patch # all SDKs, auto-bump patch
./copy-sdks -t all -b major # all SDKs, auto-bump major
./copy-sdks -t all -v 2.0.0 # all SDKs, explicit version
```

The `-b` flag accepts `major`, `minor` (default), or `patch`.

The script shows a summary table of current and new versions and asks for confirmation before proceeding.

### Resetting SDK Repos

The [reset-sdks](reset-sdks) script resets SDK repos in [/repos](repos) back to their main branch (pulling latest from origin). Useful before starting a new release cycle.

```bash
./reset-sdks # reset all SDK repos
./reset-sdks ruby # reset a single SDK
./reset-sdks python,node,ruby # reset specific SDKs
```

### Changes to Generated SDK Code

We generate our SDKs using the [OpenAPI Generator](https://openapi-generator.tech/) tool. This tool reads the contents of the [openapi-sdk.yaml](openapi-sdk.yaml) file. It also reads related examples from the [/examples](examples) directory and embeds the contents into the generated documentation.
Expand Down
136 changes: 118 additions & 18 deletions copy-sdks
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SDKS=( dotnet java-v1 java-v2 node php python ruby )
SHOW_HELP=0
TARGET_SDK=
TARGET_VERSION=
BUMP_TYPE=minor

REPO_DOTNET="https://github.com/hellosign/dropbox-sign-dotnet.git"
REPO_JAVA_V1="--branch v1 https://github.com/hellosign/dropbox-sign-java.git"
Expand All @@ -18,30 +19,118 @@ REPO_RUBY="https://github.com/hellosign/dropbox-sign-ruby.git"

REPO_MAIN_BRANCH="main"

while getopts ":t:v:h" opt; do
while getopts ":t:v:b:h" opt; do
case $opt in
t) TARGET_SDK="$OPTARG"
;;
v) TARGET_VERSION="$OPTARG"
;;
b) BUMP_TYPE="$OPTARG"
;;
h) SHOW_HELP=1
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done

function get_current_version()
{
local sdk="$1"
local version_file="${DIR}/repos/${sdk}/VERSION"

if [[ ! -f "${version_file}" ]]; then
printf "ERROR: VERSION file not found at %s\n" "${version_file}" >&2
exit 1
fi

grep -oE '[0-9]+\.[0-9]+\.[0-9]+' "${version_file}" | head -1
}

function bump_version()
{
local current="$1"
local type="$2"
local major minor patch
major=$(echo "$current" | cut -d. -f1)
minor=$(echo "$current" | cut -d. -f2)
patch=$(echo "$current" | cut -d. -f3)

case "$type" in
major) echo "$((major + 1)).0.0" ;;
minor) echo "${major}.$((minor + 1)).0" ;;
patch) echo "${major}.${minor}.$((patch + 1))" ;;
*)
printf "Invalid bump type: %s (must be major, minor, or patch)\n" "$type" >&2
exit 1
;;
esac
}

function main() {
if [[ -z ${TARGET_SDK} || -z ${TARGET_VERSION} ]]; then
if [[ -z ${TARGET_SDK} ]]; then
show_help
exit 0
fi

# Parse target SDKs: "all", comma-separated, or single
local sdk_list=()
if [[ "${TARGET_SDK}" == "all" ]]; then
sdk_list=("${SDKS[@]}")
else
IFS=',' read -ra sdk_list <<< "${TARGET_SDK}"
fi

for sdk in "${sdk_list[@]}"; do
validate_sdk_choice "$sdk"
done

# Resolve versions and build summary
local versions=()
local current_versions=()
for sdk in "${sdk_list[@]}"; do
local current_ver
current_ver=$(get_current_version "$sdk")
current_versions+=("$current_ver")

if [[ -n "${TARGET_VERSION}" ]]; then
versions+=("${TARGET_VERSION}")
else
versions+=("$(bump_version "$current_ver" "$BUMP_TYPE")")
fi
done

# Show summary table
printf "\n%-12s %-15s %-15s\n" "SDK" "Current" "New Version"
printf "%-12s %-15s %-15s\n" "---" "-------" "-----------"
for i in "${!sdk_list[@]}"; do
printf "%-12s %-15s %-15s\n" "${sdk_list[$i]}" "${current_versions[$i]}" "${versions[$i]}"
done
printf "\n"

read -p "Proceed? [y/N] " confirm
if [[ "${confirm}" != "y" && "${confirm}" != "Y" ]]; then
printf "Aborted.\n"
exit 0
fi

validate_sdk_choice $TARGET_SDK
copy_files $TARGET_SDK $TARGET_VERSION
# Process each SDK
for i in "${!sdk_list[@]}"; do
local sdk="${sdk_list[$i]}"
local ver="${versions[$i]}"

printf "\n=== Processing %s %s ===\n" "$sdk" "$ver"

REPO_MAIN_BRANCH="main"
if [[ "${sdk}" == "java-v1" ]]; then
REPO_MAIN_BRANCH="v1"
fi

printf "Success! Ready for git commit!\n"
copy_files "$sdk" "$ver"
printf "Done: %s %s\n" "$sdk" "$ver"
done

printf "\nSuccess! All SDKs committed and pushed.\n"
exit 0
}

Expand All @@ -53,10 +142,19 @@ 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"
-t target SDK(s): a single SDK, comma-separated list, or "all"
valid: dotnet, java-v1, java-v2, node, php, python, ruby, all
-v version of the SDK, ex: 1.4.0
if omitted, auto-bumps version from repos/[SDK]/VERSION
-b bump type when -v is omitted: major, minor (default), or patch
-h display this help and exit
Example: copy-sdks -t php -v 1.4.0

Examples:
copy-sdks -t php -v 1.4.0 # single SDK, explicit version
copy-sdks -t python,node,ruby # multiple SDKs, auto-bump minor
copy-sdks -t all # all SDKs, auto-bump minor
copy-sdks -t all -b patch # all SDKs, auto-bump patch
copy-sdks -t all -v 2.0.0 # all SDKs, same explicit version
EOF

exit 0
Expand All @@ -80,10 +178,6 @@ function validate_sdk_choice()

exit 1
fi

if [[ "${SDK}" == "java-v1" ]]; then
REPO_MAIN_BRANCH="v1"
fi
}

function copy_files()
Expand All @@ -101,7 +195,7 @@ function copy_files()

git reset --hard origin/${REPO_MAIN_BRANCH}
git pull origin ${REPO_MAIN_BRANCH}
git checkout -b "release-${VERSION}"
git checkout "release-${VERSION}" 2>/dev/null || git checkout -b "release-${VERSION}"
git rm -rf --cached .

popd
Expand All @@ -121,22 +215,28 @@ function copy_files()

cp -r "${DIR}/openapi-sdk.yaml" "${SDK_DIR}/openapi-sdk.yaml"

local EXAMPLES_SRC="${DIR}/sdks/${SDK}/examples"

if [[ "${SDK}" == "dotnet" ]]; then
"${DIR}/bin/copy-examples-filtered" "${DIR}/examples" "${SDK_DIR}/examples" cs
"${DIR}/bin/copy-examples-filtered" "${EXAMPLES_SRC}" "${SDK_DIR}/examples" cs
elif [[ "${SDK}" == "java-v2" ]] || [[ "${SDK}" == "java-v1" ]]; then
"${DIR}/bin/copy-examples-filtered" "${DIR}/examples" "${SDK_DIR}/examples" java
"${DIR}/bin/copy-examples-filtered" "${EXAMPLES_SRC}" "${SDK_DIR}/examples" java
elif [[ "${SDK}" == "node" ]]; then
"${DIR}/bin/copy-examples-filtered" "${DIR}/examples" "${SDK_DIR}/examples" ts
"${DIR}/bin/copy-examples-filtered" "${EXAMPLES_SRC}" "${SDK_DIR}/examples" ts
elif [[ "${SDK}" == "php" ]]; then
"${DIR}/bin/copy-examples-filtered" "${DIR}/examples" "${SDK_DIR}/examples" php
"${DIR}/bin/copy-examples-filtered" "${EXAMPLES_SRC}" "${SDK_DIR}/examples" php
elif [[ "${SDK}" == "python" ]]; then
"${DIR}/bin/copy-examples-filtered" "${DIR}/examples" "${SDK_DIR}/examples" py
"${DIR}/bin/copy-examples-filtered" "${EXAMPLES_SRC}" "${SDK_DIR}/examples" py
elif [[ "${SDK}" == "ruby" ]]; then
"${DIR}/bin/copy-examples-filtered" "${DIR}/examples" "${SDK_DIR}/examples" rb
"${DIR}/bin/copy-examples-filtered" "${EXAMPLES_SRC}" "${SDK_DIR}/examples" rb
fi

php "${DIR}/bin/update-sdk-version.php" ${SDK} ${VERSION}

git add -A
git commit -m "Release ${VERSION}"
git push -u origin "release-${VERSION}"

popd
}

Expand Down
40 changes: 40 additions & 0 deletions reset-sdks
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -e

DIR=$(cd `dirname $0` && pwd)
ALL_SDKS=( dotnet java-v1 java-v2 node php python ruby )
TARGET="${1:-all}"

if [[ "${TARGET}" == "all" ]]; then
SDKS=("${ALL_SDKS[@]}")
else
IFS=',' read -ra SDKS <<< "${TARGET}"
fi

for SDK in "${SDKS[@]}"; do
SDK_DIR="${DIR}/repos/${SDK}"
BRANCH="main"

if [[ "${SDK}" == "java-v1" ]]; then
BRANCH="v1"
fi

if [[ ! -d "${SDK_DIR}/.git" ]]; then
printf "SKIP: %s (not cloned at %s)\n" "$SDK" "$SDK_DIR"
continue
fi

printf "Resetting %s to %s...\n" "$SDK" "$BRANCH"
pushd "${SDK_DIR}/" > /dev/null

git checkout "$BRANCH"
git reset --hard "origin/${BRANCH}"
git pull origin "$BRANCH"
git fetch --prune

popd > /dev/null
printf "Done: %s\n\n" "$SDK"
done

printf "All SDK repos reset.\n"
Loading