Skip to content

Commit

Permalink
Merge PR #84 (Add script to change version numbers)
Browse files Browse the repository at this point in the history
This merge brings PR #84 (Add script to change version numbers
before a KPP release, by @yantosca) into the KPP development
stream (aka "dev" branch).

PR #84 adds a convenience script to change version numbers in
the appropriate locations before a new KPP version is released.

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
  • Loading branch information
yantosca committed Dec 4, 2023
2 parents 2978aa4 + 9387531 commit cd4b679
Showing 1 changed file with 121 additions and 0 deletions.
121 changes: 121 additions & 0 deletions .release/changeVersionNumbers.sh
@@ -0,0 +1,121 @@
#!/bin/bash

#EOC
#------------------------------------------------------------------------------
# The Kinetic PreProcessor (KPP) !
#------------------------------------------------------------------------------
#BOP
#
# !MODULE: changeVersionNumbers.sh
#
# !DESCRIPTION: Bash script to change the version numbers in the appropriate
# files in the KPP directory structure. Run this before releasing a new
# KPP version.
#\\
#\\
# !CALLING SEQUENCE:
# $ ./changeVersionNumbers.sh X.Y.Z # X.Y.Z = KPP version number
#EOP
#------------------------------------------------------------------------------
#BOC

function replace() {
#========================================================================
# Replacement for `sed -i -e` that works on both MacOS and Linux
#
# 1st argument = regular expression
# 2nd argument = file to be edited
#========================================================================
regex="s/${1}/${2}/g"
file="${3}"
if [[ "x$(uname -s)" == "xDarwin" ]]; then
sed -i '' -e "${regex}" "${file}" # MacOS/Darwin
else
sed -i -e "${regex}" "${file}" # GNU/Linux
fi
}


function exitWithError() {

#========================================================================
# Display and error message and exit
#========================================================================

echo "Could not update version numbers in ${1}... Exiting!"
exit 1
}


function main() {

#========================================================================
# Replaces the version number in the files listed.
#
# 1st argument: New version number to use
#========================================================================

# New version number
version="${1}"

# Save this directory path and change to root directory
thisDir=$(pwd -P)
cd ..

#========================================================================
# Update version numbers in various files
#========================================================================

# Pattern to match: X.Y.Z
pattern='[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*'

# List of files to replace
files=( \
"src/gdata.h" \
"docs/source/conf.py" \
)

# Replace version numbers in files
for file in ${files[@]}; do
replace "${pattern}" "${version}" "${file}"
[[ $? -ne 0 ]] && exitWithError "${file}"
echo "KPP version updated to ${version} in ${file}"
done

#========================================================================
# Update version number and date in CHANGELOG.md
#========================================================================

# Pattern to match: "[Unreleased] - TBD"
pattern='\[.*Unreleased.*\].*'
date=$(date -Idate)

# List of files to replace
files=( \
"CHANGELOG.md" \
)

# Replace version numbers in files
for file in ${files[@]}; do
replace "${pattern}" "\[${version}\] - ${date}" "${file}"
[[ $? -ne 0 ]] && exitWithError "${file}"
echo "KPP version updated to ${version} in ${file}"
done

# Return to the starting directory
cd "${thisDir}"
}

# ---------------------------------------------------------------------------

# Expect 1 argument, or exit with error
if [[ $# -ne 1 ]]; then
echo "Usage: ./changeVersionNumbers.sh VERSION"
exit 1
fi

# Replace version numbers
main "${1}"

# Return status
exit $?

0 comments on commit cd4b679

Please sign in to comment.