Skip to content

Commit

Permalink
merge: merge branch 'development' into release-2.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gampnico committed Dec 3, 2024
2 parents 3728937 + bd07bb0 commit dedd444
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ build: --install-build-deps ## Build COSIPY package
$(PYTHON) -m build
@twine check dist/*

# .PHONY
# bump-version:
# @grep -Po '\bversion\s*=\s*"\K.*?(?=")' pyproject.toml
bump-version:
@bash bump_version.sh

.PHONY:
upload-pypi: # Private: upload COSIPY package
Expand Down
102 changes: 102 additions & 0 deletions bump_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash
# 2024 Nicolas Gampierakis.

# Applies semantic versioning across project

DIRECTORY=""
VERBOSE=0
BRANCH=""

DisplayHelp() {
intro_tag="$(basename "$0") [-h] -- semantic versioning tool"
options="OPTIONS
-h, --help Display help.
-d, --directory [path] Path to target directory, relative to current
working directory.
-v, --verbose Verbosity flag.
"
printf "\n%s\n\n%s\n" "$intro_tag" "$options"
}

#######################################
# Get project version number
#
# Arguments:
# Keyword for version number in file.
# File path.
#######################################
get_version_number() {
match_string="${1}"
file_name="${2}"
version_number=$(grep -oP '\b'"${match_string}"'\s*=\s*"\K.*?(?=")' "${file_name}")
}

#######################################
# Set project version number
#
# Arguments:
# Project root directory.
#######################################
set_version_number() {
toml_file="${1}pyproject.toml"
docs_file="${1}docs/source/conf.py"
version_number=""
get_version_number "version" "${toml_file}"
current_py_version="${version_number}"
get_version_number "release" "${docs_file}"
current_docs_version="${version_number}"
current_version="${current_py_version}"

new_version=${BRANCH#"release-"}
if [ "${new_version}" != "${current_version}" ]; then
printf "%s\n" "Current branch: ${BRANCH}" >&2
printf "%s\n" "Previous version number: ${current_version}" >&2
printf "%s\n" "New version number: ${new_version}" >&2
sed -i "s/${current_py_version}/${new_version}/g" "${toml_file}"
sed -i "s/${current_docs_version}/${new_version}/g" "${docs_file}"
git add "${toml_file}" "${docs_file}"
git commit -m "build: bump version number to ${new_version}"
else
printf "%s\n" "Current and new version numbers are identical: ${current_version}" >&2
fi
}

ARGS=$(getopt -o "hd:v" --long "help,directory:,verbose" -- "$@") || exit
eval "set -- $ARGS"
while true; do
case $1 in
-h | --help)
DisplayHelp
exit 0
;;
-d | --directory)
DIRECTORY=$2
shift 2
;;
-v | --verbose)
((VERBOSE++))
shift
;;
--)
shift
break
;;
*) exit 1 ;; # error
esac
done
remaining=("$@")

if [[ ! $DIRECTORY ]]; then
DIRECTORY="${PWD}/"
else
DIRECTORY="${PWD}/${DIRECTORY}"
fi
readonly DIRECTORY

BRANCH="$(git rev-parse --abbrev-ref HEAD)"
if [[ "$BRANCH" != *"release-"* ]]; then
echo "Please switch to a release branch."
exit 1
fi

set_version_number "${DIRECTORY}"

0 comments on commit dedd444

Please sign in to comment.