Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
WIP: allow bumping version according to type (major,minor,build,revis…
…ion)
  • Loading branch information
jimschubert committed Jun 5, 2019
commit f1a0fe3e16258d5f7544e7b7eb86b93bd550fbbd
71 changes: 54 additions & 17 deletions bin/utils/release/bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ declare start="<!-- RELEASE_VERSION -->"
declare end="<!-- \/RELEASE_VERSION -->"
declare from="${version_regex}"
declare to=""
declare file=""
declare debug=${debug:-false}
declare -a from_parts=()
declare -a to_parts=()
declare -ar inc=(major minor build snapshot)

USAGE="
USAGE: $0 OPTIONS input_file
Expand All @@ -39,6 +39,7 @@ OPTIONS:
default: $start
-e The end tag regex
default: $end
-i Increase by one of: ${inc[@]}
-h Print this message

EXAMPLES:
Expand Down Expand Up @@ -100,7 +101,7 @@ version()
fi
}

while getopts "hf:t:s:e:" OPTION
while getopts "hf:t:s:e:i:" OPTION
do
case ${OPTION} in
f)
Expand All @@ -115,31 +116,64 @@ do
e)
end=${OPTARG}
;;
i)
increase=${OPTARG}
if [[ ! "${inc[@]}" =~ ${increase} ]];then
err "Only support increasing by one of: ${inc[@]}"
fi
;;
h)
usage
;;
esac
done

shift $((OPTIND-1))
file="${1}"
file=( "$@" )

if [[ -z "${file}" ]];then
if [[ ${#file[@]} -eq 0 ]];then
echo "No file specified" >&2
usage
fi

if [[ -z "${from}" ]]; then
err "No 'from' version specified."
fi
if [[ -z "${to}" ]]; then
err "No 'to' version specified."
fi

# TODO: compare steps in from_parts and to_parts.
# This could be further automated to support bump levels (major/minor/build/SNAPSHOT)
version "${from}" from_parts
version "${to}" to_parts

if [[ -z "${to}" ]]; then
if [[ -z "${increase}" ]]; then
err "No 'to' version specified."
else
case ${increase} in
major)
to="$(( ${from_parts[0]} + 1 )).0.0"
version "$to" to_parts
;;
minor)
to="${from_parts[0]}.$(( ${from_parts[1]} + 1 )).0"
version "$to" to_parts
;;
build)
to="${from_parts[0]}.${from_parts[1]}.$(( ${from_parts[2]} + 1 ))"
version "$to" to_parts
;;
snapshot)
if [[ true = ${from_parts[3]} ]]; then
err "Can't move from SNAPSHOT to SNAPSHOT (from=${from})."
else
to="${from_parts[0]}.${from_parts[1]}.$(( ${from_parts[2]} + 1 ))-SNAPSHOT"
version "$to" to_parts
fi
;;
esac
fi
else
version "${to}" to_parts
fi

if [[ ${from_parts[3]} = true && ${to_parts[3]} = true ]]; then
err "Moving from SNAPSHOT to SNAPSHOT is not supported."
Expand All @@ -151,18 +185,21 @@ cat <<EOF > sedscript.sed
}
EOF

d "Moving from=${from} to=${to}"

trap 'rm -f sedscript.sed' EXIT

sed_cross () {
# Cross-platform sed invocation
sed --version >/dev/null 2>&1 && sed -E -i '' -f sedscript.sed "$@" || sed -i '' -f sedscript.sed "$@"
# Cross-platform sed invocation. OSX has no option to show a version number in sed.
local target=$1
sed --version >/dev/null 2>&1 && sed -e -i '' -f sedscript.sed "$target" || sed -i '' -E -f sedscript.sed "$target"
}

d "Moving from ${from} to ${to}: $file"

if sed_cross $file; then
echo "Updated $file successfully!"
else
echo "ERROR: Failed to update $file to target version ${to}" >&2
fi
for filename in "${file[@]}"; do
if sed_cross ${filename}; then
echo "Updated $filename successfully!"
else
echo "ERROR: Failed to update $filename to target version ${to}" >&2
fi
done

62 changes: 43 additions & 19 deletions bin/utils/release/release_version_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,51 @@

declare cwd=$(cd $(dirname "${BASH_SOURCE}") && pwd)

if [[ "$1" != "" ]]; then
FROM="$1"
else
echo "Missing argument. Usage e.g.: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1"
exit 1;
fi
USAGE="
USAGE: $0 target

This script will convert the current version in target files to the specified 'target'
where target is one of:

major
minor
build
snapshot

EXAMPLES:

if [[ "$2" != "" ]]; then
TO="$2"
Update to new snapshot (1.0.0 -> 1.0.1-SNAPSHOT):
$0 snapshot
Update build version (1.0.0 -> 1.0.1)
$0 build
Update minor version (1.2.3 -> 1.3.0)
$0 minor
Update major version (1.2.3 -> 2.0.0)
$0 major
"

version=$(ruby -r rexml/document -e 'include REXML;
p XPath.first(Document.new($stdin), "/project/version/text()")' < ${cwd}/../../../pom.xml)

if [[ -n "$1" ]]; then
case $1 in
--help|-h)
echo -e "$USAGE" >&2
exit 1
;;
major|minor|build|snapshot)
inc="$1"
;;
*)
echo "Invalid target.Must be one of: major minor build or snapshot" >&2
exit 1
;;
esac
else
echo "Missing argument. Usage e.g.: ./bin/utils/release_version_update.sh 3.0.1-SNAPSHOT 3.0.1"
exit 1;
inc="snapshot"
fi

echo "Release preparation: replacing $FROM with $TO in different files"
echo "Release preparation: Moving from $version to next $inc version."

# These files should wrap target version replacement blocks with <!-- RELEASE_VERSION --> and <!-- /RELEASE_VERSION -->
# We can include xml and md files here.
Expand All @@ -54,11 +84,5 @@ declare -a properties_files=(
"modules/openapi-generator-gradle-plugin/gradle.properties"
)

for filename in "${xml_files[@]}"; do
${cwd}/bump.sh -f $FROM -t $TO $filename
done

for filename in "${properties_files[@]}"; do
${cwd}/bump.sh -f $FROM -t $TO -s '# RELEASE_VERSION' -e '# \/RELEASE_VERSION' $filename
done

${cwd}/bump.sh -f ${version} -i ${inc} ${xml_files[@]}
${cwd}/bump.sh -f ${version} -t ${inc} -s '# RELEASE_VERSION' -e '# \/RELEASE_VERSION' ${properties_files[@]}