|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Prompt for the version number |
| 4 | +prompt_for_version() { |
| 5 | + read -p "Enter the version number (default: $1): " version |
| 6 | + echo "${version:-$1}" # Return the entered version number or the default if none was entered |
| 7 | +} |
| 8 | + |
| 9 | +# Increment version number |
| 10 | +increment_version() { |
| 11 | + local IFS='.' |
| 12 | + read -a version_parts <<< "$1" |
| 13 | + # Increment the minor version and reset patch version |
| 14 | + local next_version="${version_parts[0]}.$((version_parts[1] + 1)).0" |
| 15 | + |
| 16 | + # Prompt for the version number, using the next version as the default |
| 17 | + read -p "Enter the version number (default: $next_version): " version |
| 18 | + echo "${version:-$next_version}" # Return the entered version number or the default if none was entered |
| 19 | +} |
| 20 | + |
| 21 | +# Get the latest version tag |
| 22 | +get_latest_version() { |
| 23 | + git describe --tags "$(git rev-list --tags --max-count=1)" |
| 24 | +} |
| 25 | + |
| 26 | +# Prepend the tickets to the CHANGELOG.md |
| 27 | +prepend_to_changelog() { |
| 28 | + local version=$1 |
| 29 | + local tickets=$2 |
| 30 | + local date=$(date +"%b %d, %Y") |
| 31 | + local changelog="CHANGELOG.md" |
| 32 | + |
| 33 | + # Create a backup of the CHANGELOG.md |
| 34 | + cp "$changelog" "$changelog.bak" |
| 35 | + |
| 36 | + # Prepend the new content to the CHANGELOG.md |
| 37 | + { |
| 38 | + echo "# v$version ($date)" |
| 39 | + for ticket in $tickets; do |
| 40 | + echo "* $ticket - " |
| 41 | + done |
| 42 | + echo "" |
| 43 | + cat "$changelog.bak" |
| 44 | + } > "$changelog" |
| 45 | + |
| 46 | + rm "$changelog.bak" |
| 47 | +} |
| 48 | + |
| 49 | +# Check if the --dry flag is set |
| 50 | +DRY_RUN=false |
| 51 | +if [ "$1" == "--dry" ]; then |
| 52 | + DRY_RUN=true |
| 53 | +fi |
| 54 | + |
| 55 | +# Get the latest tag and suggest the next version number |
| 56 | +LATEST_TAG=$(get_latest_version) |
| 57 | +NEXT_VERSION=$(increment_version ${LATEST_TAG#v}) # Assuming the tag is in the 'v1.2.3' format |
| 58 | + |
| 59 | +if $DRY_RUN; then |
| 60 | + # Perform a dry run |
| 61 | + echo "This is a dry run. The release branch will not be created." |
| 62 | + echo "The next version number would be: ${NEXT_VERSION}" |
| 63 | + git tickets | grep -Eo '(\w+)-([0-9]+)' |
| 64 | +else |
| 65 | + # Perform the actual release process |
| 66 | + # Capture the output of git-tickets |
| 67 | + TICKETS_OUTPUT=$(git tickets --update) |
| 68 | + |
| 69 | + # Use grep to filter the output |
| 70 | + TICKET_IDS=$(echo "$TICKETS_OUTPUT" | grep -Eo '(\w+)-([0-9]+)') |
| 71 | + |
| 72 | + # Prepend the tickets to the CHANGELOG.md |
| 73 | + prepend_to_changelog "$NEXT_VERSION" "$TICKET_IDS" |
| 74 | + |
| 75 | + # Checkout a new branch with the pattern release-### |
| 76 | + git checkout -b "release-${NEXT_VERSION}" |
| 77 | + |
| 78 | + # Add the CHANGELOG.md to the staging area |
| 79 | + git add CHANGELOG.md |
| 80 | + |
| 81 | + echo "Tickets to be included in this release:" |
| 82 | + echo "$TICKET_IDS" |
| 83 | +fi |
0 commit comments