aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/release.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/release.sh')
-rwxr-xr-xscripts/release.sh132
1 files changed, 132 insertions, 0 deletions
diff --git a/scripts/release.sh b/scripts/release.sh
new file mode 100755
index 0000000..9e49433
--- /dev/null
+++ b/scripts/release.sh
@@ -0,0 +1,132 @@
+#!/usr/bin/env bash
+#
+# Release script for ssg
+# Updates version in CHANGELOG.md, creates git tag, and pushes
+
+set -euo pipefail
+
+# shellcheck disable=SC2155
+readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+# shellcheck disable=SC2155
+readonly PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
+readonly CHANGELOG="${PROJECT_ROOT}/CHANGELOG.md"
+
+usage() {
+ cat <<EOF
+Usage: $(basename "$0") VERSION
+
+Create a new release with the specified version.
+
+Arguments:
+ VERSION Semantic version number (e.g., 1.0.0, 0.2.1)
+
+Examples:
+ $(basename "$0") 1.0.0
+ $(basename "$0") 0.2.1
+EOF
+ exit 1
+}
+
+main() {
+ if [[ $# -ne 1 ]]; then
+ usage
+ fi
+
+ local version="$1"
+
+ validate_version "$version"
+ check_clean_working_tree
+
+ echo "Release plan:"
+ echo " Version: $version"
+ echo " Update: $CHANGELOG"
+ echo " Create: git commit"
+ echo " Create: git tag v${version}"
+ echo " Push: commit and tag to origin/main"
+ echo
+
+ if ! confirm "Proceed with release?"; then
+ echo "Release cancelled."
+ exit 0
+ fi
+
+ update_changelog "$version"
+ create_commit "$version"
+ create_tag "$version"
+
+ echo
+ if confirm "Push to remote?"; then
+ push_changes "$version"
+ echo
+ echo "v${version} released!"
+ else
+ echo
+ echo "Changes committed and tagged locally."
+ echo "To push manually, run:"
+ echo " git push origin main"
+ echo " git push origin v${version}"
+ fi
+}
+
+validate_version() {
+ local ver="$1"
+ if [[ ! "$ver" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
+ error "Invalid version format: $ver (expected: X.Y.Z)"
+ fi
+}
+
+error() {
+ echo "Error: $*" >&2
+ exit 1
+}
+
+confirm() {
+ local prompt="$1"
+ local response
+ read -r -p "$prompt [y/N] " response
+ [[ "$response" =~ ^[Yy]$ ]]
+}
+
+check_clean_working_tree() {
+ if ! git diff-index --quiet HEAD --; then
+ error "Working tree has uncommitted changes. Please commit or stash them first."
+ fi
+}
+
+update_changelog() {
+ local ver="$1"
+ local date
+ date="$(date +%Y-%m-%d)"
+
+ if ! grep -q "## \[Unreleased\]" "$CHANGELOG"; then
+ error "Could not find [Unreleased] section in $CHANGELOG"
+ fi
+
+ echo "Updating $CHANGELOG..."
+ sed -i.bak "s/## \[Unreleased\]/## [Unreleased]\n\n## [$ver] - $date/" "$CHANGELOG"
+ rm "${CHANGELOG}.bak"
+}
+
+create_commit() {
+ local ver="$1"
+
+ echo "Creating git commit..."
+ git add "$CHANGELOG"
+ git commit -m "Release v${ver}"
+}
+
+create_tag() {
+ local ver="$1"
+
+ echo "Creating git tag v${ver}..."
+ git tag -a "v${ver}" -m "Release v${ver}"
+}
+
+push_changes() {
+ local ver="$1"
+ echo "Pushing commit and tag to remote..."
+ git push origin main
+ git push origin "v${ver}"
+}
+
+main "$@"