|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Script to rebuild a specific tag and trigger a new release |
| 5 | +# This script will: |
| 6 | +# 1. Delete the existing tag locally and remotely |
| 7 | +# 2. Create a new tag at the current commit |
| 8 | +# 3. Push the new tag to trigger the GitHub Actions workflow |
| 9 | + |
| 10 | +# Default values |
| 11 | +TAG_NAME="v1.0.11" |
| 12 | +REMOTE_NAME="origin" |
| 13 | +FORCE=false |
| 14 | + |
| 15 | +# Parse command line arguments |
| 16 | +while [[ $# -gt 0 ]]; do |
| 17 | + case $1 in |
| 18 | + -t|--tag) |
| 19 | + TAG_NAME="$2" |
| 20 | + shift 2 |
| 21 | + ;; |
| 22 | + -r|--remote) |
| 23 | + REMOTE_NAME="$2" |
| 24 | + shift 2 |
| 25 | + ;; |
| 26 | + -f|--force) |
| 27 | + FORCE=true |
| 28 | + shift |
| 29 | + ;; |
| 30 | + -h|--help) |
| 31 | + echo "Usage: $0 [-t|--tag TAG_NAME] [-r|--remote REMOTE_NAME] [-f|--force]" |
| 32 | + echo "Options:" |
| 33 | + echo " -t, --tag TAG_NAME Specify the tag name (default: v1.0.0)" |
| 34 | + echo " -r, --remote REMOTE Specify the remote name (default: origin)" |
| 35 | + echo " -f, --force Skip confirmation prompts" |
| 36 | + echo " -h, --help Show this help message" |
| 37 | + exit 0 |
| 38 | + ;; |
| 39 | + *) |
| 40 | + echo "Unknown option: $1" |
| 41 | + exit 1 |
| 42 | + ;; |
| 43 | + esac |
| 44 | +done |
| 45 | + |
| 46 | +echo "🔄 Rebuilding tag: $TAG_NAME" |
| 47 | + |
| 48 | +# Check if we're in the root of the repository |
| 49 | +if [ ! -d ".git" ]; then |
| 50 | + echo "❌ Error: This script must be run from the root of the repository." |
| 51 | + exit 1 |
| 52 | +fi |
| 53 | + |
| 54 | +# Check if there are uncommitted changes |
| 55 | +if ! git diff-index --quiet HEAD --; then |
| 56 | + echo "⚠️ Warning: You have uncommitted changes." |
| 57 | + if [ "$FORCE" = false ]; then |
| 58 | + read -p "Do you want to continue anyway? (y/n) " -n 1 -r |
| 59 | + echo |
| 60 | + if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 61 | + echo "Operation cancelled." |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | + else |
| 65 | + echo "Proceeding with uncommitted changes due to --force flag." |
| 66 | + fi |
| 67 | +fi |
| 68 | + |
| 69 | +# Run operations in parallel where possible |
| 70 | + |
| 71 | +# Delete the local tag |
| 72 | +echo "🗑️ Deleting local tag $TAG_NAME..." |
| 73 | +git tag -d $TAG_NAME 2>/dev/null || echo "Local tag $TAG_NAME doesn't exist, continuing..." |
| 74 | + |
| 75 | +# Delete the remote tag with --no-verify to skip hooks |
| 76 | +echo "🗑️ Deleting remote tag $TAG_NAME..." |
| 77 | +git push --no-verify $REMOTE_NAME :refs/tags/$TAG_NAME 2>/dev/null || echo "Remote tag $TAG_NAME doesn't exist or couldn't be deleted, continuing..." |
| 78 | + |
| 79 | +# Create a new tag at the current commit |
| 80 | +echo "✨ Creating new tag $TAG_NAME at current commit..." |
| 81 | +git tag $TAG_NAME |
| 82 | + |
| 83 | +# Push the new tag to trigger the GitHub Actions workflow |
| 84 | +# Use --atomic and --no-verify for faster pushing |
| 85 | +echo "📤 Pushing new tag to remote..." |
| 86 | +git push --atomic --no-verify $REMOTE_NAME $TAG_NAME |
| 87 | + |
| 88 | +echo "✅ Tag $TAG_NAME has been rebuilt and pushed to $REMOTE_NAME." |
| 89 | + |
| 90 | +echo "🎉 Done!" |
| 91 | +echo "🚀 GitHub Actions workflow should start soon at: https://github.com/ruslanlap/PowerToysRun-CheatSheets/actions" |
| 92 | + |
| 93 | +# Display estimated completion time |
| 94 | +echo "⏱️ Estimated completion time: ~5 minutes" |
0 commit comments