Add 7 and update 2 files
Some checks failed
Test and Publish Templates / test-and-publish (push) Failing after 14s
Some checks failed
Test and Publish Templates / test-and-publish (push) Failing after 14s
This commit is contained in:
162
bump-version.sh
Executable file
162
bump-version.sh
Executable file
@@ -0,0 +1,162 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
SCRIPT_DIR=$(dirname "$0")
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
function die() {
|
||||
echo "ERROR: $1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
function info() {
|
||||
echo "INFO: $1"
|
||||
}
|
||||
|
||||
function usage() {
|
||||
cat << EOF
|
||||
Usage: $0 <template> <version-type|version>
|
||||
|
||||
Arguments:
|
||||
template Name of the template to version
|
||||
version-type One of: major, minor, patch
|
||||
version Specific version number (e.g., 2.1.0)
|
||||
|
||||
Examples:
|
||||
$0 caddy patch # Bump patch version (1.0.0 -> 1.0.1)
|
||||
$0 caddy minor # Bump minor version (1.0.0 -> 1.1.0)
|
||||
$0 caddy major # Bump major version (1.0.0 -> 2.0.0)
|
||||
$0 caddy 2.5.3 # Set specific version
|
||||
|
||||
Options:
|
||||
--all <version-type> Bump all templates
|
||||
|
||||
Examples with --all:
|
||||
$0 --all patch # Bump patch version for all templates
|
||||
$0 --all 2.0.0 # Set all templates to version 2.0.0
|
||||
EOF
|
||||
exit 1
|
||||
}
|
||||
|
||||
function get_current_version() {
|
||||
local template="$1"
|
||||
if [ -f "versions.json" ]; then
|
||||
if which jq >/dev/null 2>&1; then
|
||||
jq -r ".\"$template\" // \"1.0.0\"" versions.json
|
||||
elif which python3 >/dev/null 2>&1; then
|
||||
python3 -c "import json; data=json.load(open('versions.json')); print(data.get('$template', '1.0.0'))"
|
||||
else
|
||||
echo "1.0.0"
|
||||
fi
|
||||
else
|
||||
echo "1.0.0"
|
||||
fi
|
||||
}
|
||||
|
||||
function bump_version() {
|
||||
local current="$1"
|
||||
local bump_type="$2"
|
||||
|
||||
# Split version into components
|
||||
IFS='.' read -r major minor patch <<< "$current"
|
||||
|
||||
case "$bump_type" in
|
||||
major)
|
||||
echo "$((major + 1)).0.0"
|
||||
;;
|
||||
minor)
|
||||
echo "${major}.$((minor + 1)).0"
|
||||
;;
|
||||
patch)
|
||||
echo "${major}.${minor}.$((patch + 1))"
|
||||
;;
|
||||
*)
|
||||
# Assume it's a specific version
|
||||
echo "$bump_type"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function update_version() {
|
||||
local template="$1"
|
||||
local new_version="$2"
|
||||
|
||||
# Check if template exists
|
||||
if [ ! -d "$template" ]; then
|
||||
die "Template '$template' does not exist"
|
||||
fi
|
||||
|
||||
# Update versions.json
|
||||
if which jq >/dev/null 2>&1; then
|
||||
# Use jq to update
|
||||
jq ".\"$template\" = \"$new_version\"" versions.json > versions.json.tmp && mv versions.json.tmp versions.json
|
||||
elif which python3 >/dev/null 2>&1; then
|
||||
# Use python to update
|
||||
python3 << EOF
|
||||
import json
|
||||
with open('versions.json', 'r') as f:
|
||||
data = json.load(f)
|
||||
data['$template'] = '$new_version'
|
||||
with open('versions.json', 'w') as f:
|
||||
json.dump(data, f, indent=2)
|
||||
EOF
|
||||
else
|
||||
die "Neither jq nor python3 is available for JSON manipulation"
|
||||
fi
|
||||
|
||||
info "Updated $template from $(get_current_version "$template") to $new_version"
|
||||
}
|
||||
|
||||
# Parse arguments
|
||||
if [ $# -lt 2 ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
if [ "$1" == "--all" ]; then
|
||||
# Bump all templates
|
||||
VERSION_TYPE="$2"
|
||||
|
||||
if [ -z "$VERSION_TYPE" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
# Get all templates
|
||||
TEMPLATES=$(find . -maxdepth 1 -type d ! -name ".*" ! -name "." | sed 's|^\./||' | grep -v ".gitea")
|
||||
|
||||
for TEMPLATE in $TEMPLATES; do
|
||||
if [ ! -f "$TEMPLATE/install.sh" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
CURRENT_VERSION=$(get_current_version "$TEMPLATE")
|
||||
NEW_VERSION=$(bump_version "$CURRENT_VERSION" "$VERSION_TYPE")
|
||||
update_version "$TEMPLATE" "$NEW_VERSION"
|
||||
done
|
||||
|
||||
info "All templates updated"
|
||||
else
|
||||
# Bump specific template
|
||||
TEMPLATE="$1"
|
||||
VERSION_ARG="$2"
|
||||
|
||||
CURRENT_VERSION=$(get_current_version "$TEMPLATE")
|
||||
NEW_VERSION=$(bump_version "$CURRENT_VERSION" "$VERSION_ARG")
|
||||
update_version "$TEMPLATE" "$NEW_VERSION"
|
||||
fi
|
||||
|
||||
# Show the updated versions
|
||||
echo ""
|
||||
echo "Current versions:"
|
||||
if which jq >/dev/null 2>&1; then
|
||||
jq . versions.json
|
||||
else
|
||||
cat versions.json
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "To commit these changes:"
|
||||
echo " git add versions.json"
|
||||
echo " git commit -m 'Bump version(s)'"
|
||||
echo ""
|
||||
echo "After committing and pushing, the CI will automatically publish the updated templates."
|
Reference in New Issue
Block a user