Last active
February 14, 2022 18:34
-
-
Save klutchell/dfcb71fcc3056f17fd343c509b71400c to your computer and use it in GitHub Desktop.
Bump a submodule to the provided tag using commits in versionist syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
module_path="${1}" | |
tag="${2}" | |
tag() { | |
if [[ $1 == v* ]] | |
then | |
echo "${1/v/}" | |
else | |
echo "${1}" | |
fi | |
} | |
tagv() { | |
if [[ $1 != v* ]] && [[ $1 =~ ^[0-9] ]] | |
then | |
echo "v${1}" | |
else | |
echo "${1}" | |
fi | |
} | |
create_branch() { | |
local module_path="${1}" | |
local tag="${2}" | |
local module_name | |
local prev_tag | |
module_name="$(basename "${module_path}")" | |
prev_tag="$(git submodule status "${module_path}" | grep -Po '\(\K[^)]*')" | |
git checkout -b "${module_name}-${tag//[^[:alnum:]_]/-}" | |
} | |
checkout_submodule() { | |
local module_path="${1}" | |
local tag="${2}" | |
local module_name | |
local prev_tag | |
git submodule update --init --recursive "${module_path}" | |
module_name="$(basename "${module_path}")" | |
prev_tag="$(git submodule status "${module_path}" | grep -Po '\(\K[^)]*')" | |
[ -n "${prev_tag}" ] || { echo "Failed to determine previous tag"; exit 1 ; } | |
(cd "${module_path}" || exit 1 | |
git fetch | |
git checkout "$(tagv "${tag}")" | |
) | |
git add "${module_path}" | |
git commit -m "${module_path}: Update ${module_name} to $(tagv "${tag}") | |
Update ${module_name} from $(tag "${prev_tag}") to $(tag "${tag}") | |
Changelog-entry: Update ${module_name} from $(tagv "${prev_tag}") to $(tagv "${tag}") | |
Change-type: patch | |
" | |
} | |
create_branch "${module_path}" "${tag}" | |
checkout_submodule "${module_path}" "${tag}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment