107 lines
2.9 KiB
Bash
Executable File
107 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# increment_build_push.sh
|
|
# Automates version increment, build, and git operations
|
|
|
|
set -e # Exit on any error
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m' # No Color
|
|
|
|
echo -e "${GREEN}🔄 Starting increment, build, and push process...${NC}"
|
|
|
|
# Function to get the latest git tag
|
|
get_latest_tag() {
|
|
# Get the latest tag that matches the pattern v*.*.*
|
|
git tag -l "v*.*.*" | sort -V | tail -n1
|
|
}
|
|
|
|
# Function to increment version
|
|
increment_version() {
|
|
local version=$1
|
|
# Remove 'v' prefix if present
|
|
version=${version#v}
|
|
|
|
# Split version into parts
|
|
IFS='.' read -ra VERSION_PARTS <<< "$version"
|
|
|
|
# Increment the patch version (last digit)
|
|
local major=${VERSION_PARTS[0]}
|
|
local minor=${VERSION_PARTS[1]}
|
|
local patch=${VERSION_PARTS[2]}
|
|
|
|
patch=$((patch + 1))
|
|
|
|
echo "$major.$minor.$patch"
|
|
}
|
|
|
|
# Step 1: Get current version
|
|
echo -e "${YELLOW}📋 Getting current version...${NC}"
|
|
current_tag=$(get_latest_tag)
|
|
if [ -z "$current_tag" ]; then
|
|
echo -e "${YELLOW}⚠️ No existing version tags found, starting with v0.1.0${NC}"
|
|
current_version="0.1.0"
|
|
else
|
|
echo -e "Current tag: ${current_tag}"
|
|
current_version=${current_tag#v}
|
|
fi
|
|
|
|
# Step 2: Increment version
|
|
new_version=$(increment_version "$current_version")
|
|
new_tag="v$new_version"
|
|
|
|
echo -e "${GREEN}📈 Incrementing version: $current_version → $new_version${NC}"
|
|
|
|
# Step 2.5: Save version to lite/VERSION file
|
|
echo -e "${YELLOW}💾 Saving version to lite/VERSION...${NC}"
|
|
echo "$new_version" > lite/VERSION
|
|
echo -e "Version saved: ${GREEN}$new_version${NC}"
|
|
|
|
# Step 2.5: Run build.js
|
|
echo -e "${YELLOW}🔧 Running build process...${NC}"
|
|
cd lite
|
|
node build.js
|
|
cd ..
|
|
echo -e "${GREEN}✅ Build completed${NC}"
|
|
|
|
# Step 3: Git add
|
|
echo -e "${YELLOW}📦 Adding files to git...${NC}"
|
|
git add .
|
|
|
|
# Step 4: Handle commit message and commit
|
|
commit_message=""
|
|
if [ $# -eq 0 ]; then
|
|
# No arguments provided, ask for commit message
|
|
echo -e "${YELLOW}💬 Please enter a commit message:${NC}"
|
|
read -p "> " commit_message
|
|
|
|
if [ -z "$commit_message" ]; then
|
|
echo -e "${RED}❌ Commit message cannot be empty${NC}"
|
|
exit 1
|
|
fi
|
|
else
|
|
# Use provided arguments as commit message
|
|
commit_message="$*"
|
|
fi
|
|
|
|
echo -e "${YELLOW}💬 Committing changes...${NC}"
|
|
git commit -m "$commit_message"
|
|
|
|
echo -e "${YELLOW}🏷️ Creating git tag: $new_tag${NC}"
|
|
git tag "$new_tag"
|
|
|
|
# Step 5: Git push
|
|
echo -e "${YELLOW}🚀 Pushing to remote...${NC}"
|
|
git push
|
|
git push --tags
|
|
|
|
echo -e "${GREEN}🎉 Successfully completed:${NC}"
|
|
echo -e " • Version incremented to: ${GREEN}$new_version${NC}"
|
|
echo -e " • VERSION file updated: ${GREEN}lite/VERSION${NC}"
|
|
echo -e " • Build completed: ${GREEN}lite/nostr-lite.js${NC}"
|
|
echo -e " • Git tag created: ${GREEN}$new_tag${NC}"
|
|
echo -e " • Changes pushed to remote${NC}"
|
|
echo -e "\n${GREEN}✨ Process complete!${NC}" |