|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Navigate to the zinit project directory |
| 4 | +cd /Users/despiegk/code/github/threefoldtech/zinit |
| 5 | + |
| 6 | +# Check if we're in the right directory |
| 7 | +if [ ! -f "Cargo.toml" ]; then |
| 8 | + echo "Error: Not in zinit project directory" |
| 9 | + exit 1 |
| 10 | +fi |
| 11 | + |
| 12 | +# Function to get the latest release tag from GitHub |
| 13 | +get_latest_release() { |
| 14 | + local latest_tag=$(curl -s "https://api.github.com/repos/threefoldtech/zinit/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') |
| 15 | + |
| 16 | + if [ "$latest_tag" = "null" ] || [ -z "$latest_tag" ]; then |
| 17 | + echo "v0.0.0" |
| 18 | + else |
| 19 | + echo "$latest_tag" |
| 20 | + fi |
| 21 | +} |
| 22 | + |
| 23 | +# Function to increment version |
| 24 | +increment_version() { |
| 25 | + local version=$1 |
| 26 | + # Remove 'v' prefix if present |
| 27 | + version=${version#v} |
| 28 | + |
| 29 | + # Split version into parts |
| 30 | + IFS='.' read -ra PARTS <<< "$version" |
| 31 | + major=${PARTS[0]:-0} |
| 32 | + minor=${PARTS[1]:-0} |
| 33 | + patch=${PARTS[2]:-0} |
| 34 | + |
| 35 | + # Increment patch (maintenance) version |
| 36 | + patch=$((patch + 1)) |
| 37 | + |
| 38 | + echo "v${major}.${minor}.${patch}" |
| 39 | +} |
| 40 | + |
| 41 | +echo "🔍 Checking latest release..." |
| 42 | +latest_release=$(get_latest_release) |
| 43 | +echo "Latest release: $latest_release" |
| 44 | + |
| 45 | +new_version=$(increment_version "$latest_release") |
| 46 | +echo "New version: $new_version" |
| 47 | + |
| 48 | +# Confirm with user |
| 49 | +read -p "Create release $new_version? (y/N): " -n 1 -r |
| 50 | +echo |
| 51 | +if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 52 | + echo "Release cancelled" |
| 53 | + exit 0 |
| 54 | +fi |
| 55 | + |
| 56 | +# Check if tag already exists locally and remove it |
| 57 | +if git tag -l | grep -q "^$new_version$"; then |
| 58 | + echo "⚠️ Local tag $new_version already exists, removing it..." |
| 59 | + git tag -d "$new_version" |
| 60 | +fi |
| 61 | + |
| 62 | +# Make sure we're on the right branch and up to date |
| 63 | +echo "🔄 Updating repository..." |
| 64 | +git fetch origin |
| 65 | + |
| 66 | +# Get current branch name |
| 67 | +current_branch=$(git branch --show-current) |
| 68 | + |
| 69 | +# If we're not on main or master, try to checkout one of them |
| 70 | +if [[ "$current_branch" != "main" && "$current_branch" != "master" ]]; then |
| 71 | + echo "Current branch: $current_branch" |
| 72 | + if git show-ref --verify --quiet refs/heads/main; then |
| 73 | + echo "Switching to main branch..." |
| 74 | + git checkout main |
| 75 | + current_branch="main" |
| 76 | + elif git show-ref --verify --quiet refs/heads/master; then |
| 77 | + echo "Switching to master branch..." |
| 78 | + git checkout master |
| 79 | + current_branch="master" |
| 80 | + else |
| 81 | + echo "⚠️ Neither main nor master branch found, staying on current branch: $current_branch" |
| 82 | + fi |
| 83 | +fi |
| 84 | + |
| 85 | +echo "Pulling latest changes from $current_branch..." |
| 86 | +git pull origin "$current_branch" |
| 87 | + |
| 88 | +# Create and push the tag |
| 89 | +echo "🏷️ Creating tag $new_version..." |
| 90 | +git tag "$new_version" |
| 91 | + |
| 92 | +echo "🚀 Pushing tag to trigger release..." |
| 93 | +git push origin "$new_version" |
| 94 | + |
| 95 | +echo "✅ Release $new_version has been triggered!" |
| 96 | +echo "🔗 Check the release at: https://github.com/threefoldtech/zinit/releases" |
| 97 | +echo "🔗 Monitor the build at: https://github.com/threefoldtech/zinit/actions" |
0 commit comments