169 lines
4.0 KiB
Bash
Executable File
169 lines
4.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# increment_and_push.sh
|
|
#
|
|
# Automates version bumping based on git tags, then commits, tags, pushes,
|
|
# and uploads the website to the server.
|
|
#
|
|
# Git tag is the authoritative source of truth for the version.
|
|
#
|
|
# Usage:
|
|
# ./increment_and_push.sh "Your commit message here" # Bump patch (default)
|
|
# ./increment_and_push.sh --minor "Your commit message" # Bump minor
|
|
# ./increment_and_push.sh --major "Your commit message" # Bump major
|
|
#
|
|
# What this script does:
|
|
# 1. Reads the latest git tag to determine the current version
|
|
# 2. Increments the version (patch/minor/major)
|
|
# 3. Updates www/js/version.json with the new version + build date
|
|
# 4. Updates package.json with the new version number
|
|
# 5. Rebuilds the PQ crypto bundle
|
|
# 6. Stages all changes, commits with the provided message
|
|
# 7. Creates a new git tag for the version
|
|
# 8. Pushes commits + tags to remote
|
|
# 9. Uploads the website to the server via upload.sh
|
|
|
|
set -e
|
|
|
|
VERSION_FILE="www/js/version.json"
|
|
PACKAGE_FILE="package.json"
|
|
BUMP_TYPE="patch"
|
|
COMMIT_MSG=""
|
|
|
|
# Parse arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--minor)
|
|
BUMP_TYPE="minor"
|
|
shift
|
|
;;
|
|
--major)
|
|
BUMP_TYPE="major"
|
|
shift
|
|
;;
|
|
--patch)
|
|
BUMP_TYPE="patch"
|
|
shift
|
|
;;
|
|
-*|--*)
|
|
echo "Unknown option: $1"
|
|
echo "Usage: $0 [--major|--minor|--patch] [commit message]"
|
|
exit 1
|
|
;;
|
|
*)
|
|
COMMIT_MSG="$1"
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Get the latest git tag (authoritative version)
|
|
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
|
echo "🔒 Nostr Quantum Preparation — Version Increment"
|
|
echo "=========================================="
|
|
echo "Latest tag: $LATEST_TAG"
|
|
echo "Bump type: $BUMP_TYPE"
|
|
echo ""
|
|
|
|
# Parse version components
|
|
VERSION=${LATEST_TAG#v} # Remove 'v' prefix
|
|
MAJOR=$(echo "$VERSION" | cut -d. -f1)
|
|
MINOR=$(echo "$VERSION" | cut -d. -f2)
|
|
PATCH=$(echo "$VERSION" | cut -d. -f3)
|
|
|
|
# Handle missing components
|
|
MAJOR=${MAJOR:-0}
|
|
MINOR=${MINOR:-0}
|
|
PATCH=${PATCH:-0}
|
|
|
|
# Increment version based on bump type
|
|
case $BUMP_TYPE in
|
|
major)
|
|
MAJOR=$((MAJOR + 1))
|
|
MINOR=0
|
|
PATCH=0
|
|
;;
|
|
minor)
|
|
MINOR=$((MINOR + 1))
|
|
PATCH=0
|
|
;;
|
|
patch)
|
|
PATCH=$((PATCH + 1))
|
|
;;
|
|
esac
|
|
|
|
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
|
|
NEW_TAG="v${NEW_VERSION}"
|
|
echo "New version: $NEW_TAG ($BUMP_TYPE bump)"
|
|
echo ""
|
|
|
|
# Prompt for commit message if not provided
|
|
if [ -z "$COMMIT_MSG" ]; then
|
|
echo "Enter commit message (or press Enter for default: \"Release $NEW_TAG\"):"
|
|
read -r COMMIT_MSG
|
|
if [ -z "$COMMIT_MSG" ]; then
|
|
COMMIT_MSG="Release $NEW_TAG"
|
|
fi
|
|
fi
|
|
|
|
echo "Commit message: $COMMIT_MSG"
|
|
echo ""
|
|
|
|
# Update version.json
|
|
cat > "$VERSION_FILE" << EOF
|
|
{
|
|
"VERSION": "$NEW_TAG",
|
|
"VERSION_NUMBER": "$NEW_VERSION",
|
|
"BUILD_DATE": "$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")"
|
|
}
|
|
EOF
|
|
echo "✅ Updated $VERSION_FILE"
|
|
|
|
# Update package.json version field
|
|
if [ -f "$PACKAGE_FILE" ]; then
|
|
# Use sed to replace the version line (works on both macOS and Linux)
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
sed -i '' "s/\"version\": \"[^\"]*\"/\"version\": \"$NEW_VERSION\"/" "$PACKAGE_FILE"
|
|
else
|
|
sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"$NEW_VERSION\"/" "$PACKAGE_FILE"
|
|
fi
|
|
echo "✅ Updated $PACKAGE_FILE version to $NEW_VERSION"
|
|
fi
|
|
|
|
# Rebuild the PQ crypto bundle
|
|
echo ""
|
|
echo "📦 Rebuilding PQ crypto bundle..."
|
|
node build-pq-bundle.js
|
|
echo "✅ Bundle rebuilt"
|
|
echo ""
|
|
|
|
# Stage all changes (version files + any other modified/new files)
|
|
git add .
|
|
|
|
# Commit with the provided message
|
|
git commit -m "$COMMIT_MSG"
|
|
|
|
# Create new tag
|
|
git tag "$NEW_TAG"
|
|
|
|
echo ""
|
|
echo "✅ Committed and tagged: $NEW_TAG"
|
|
echo ""
|
|
|
|
# Push commits + tags to remote
|
|
git push origin master --tags
|
|
echo "✅ Pushed to remote"
|
|
echo ""
|
|
|
|
# Upload the website to the server
|
|
echo "📤 Uploading website to server..."
|
|
if [ -f "./upload.sh" ]; then
|
|
chmod +x ./upload.sh
|
|
./upload.sh
|
|
else
|
|
echo "⚠️ upload.sh not found — skipping website upload"
|
|
fi
|
|
|
|
echo ""
|
|
echo "🎉 Done! Version $NEW_TAG deployed."
|