|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Script to update CHANGELOG.md during release process |
| 5 | +# Usage: ./update-changelog.sh <version> |
| 6 | +# Example: ./update-changelog.sh 1.0.8 |
| 7 | + |
| 8 | +if [ -z "$1" ]; then |
| 9 | + echo "Error: Version argument required" |
| 10 | + echo "Usage: $0 <version>" |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
| 14 | +VERSION="$1" |
| 15 | +CHANGELOG_FILE="CHANGELOG.md" |
| 16 | +RELEASE_DATE=$(date +%Y-%m-%d) |
| 17 | + |
| 18 | +echo "Updating CHANGELOG.md for version ${VERSION} (${RELEASE_DATE})" |
| 19 | + |
| 20 | +# Check if CHANGELOG.md exists |
| 21 | +if [ ! -f "$CHANGELOG_FILE" ]; then |
| 22 | + echo "Error: CHANGELOG.md not found" |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +# Check if there's an [Unreleased] section |
| 27 | +if ! grep -q "## \[Unreleased\]" "$CHANGELOG_FILE"; then |
| 28 | + echo "Error: No [Unreleased] section found in CHANGELOG.md" |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +# Create a temporary file |
| 33 | +TEMP_FILE=$(mktemp) |
| 34 | + |
| 35 | +# Process the CHANGELOG |
| 36 | +awk -v version="$VERSION" -v date="$RELEASE_DATE" ' |
| 37 | +BEGIN { |
| 38 | + unreleased_found = 0 |
| 39 | + content_found = 0 |
| 40 | + links_section = 0 |
| 41 | + first_version_link = "" |
| 42 | +} |
| 43 | +
|
| 44 | +# Track if we are in the links section at the bottom |
| 45 | +/^\[/ { |
| 46 | + links_section = 1 |
| 47 | +} |
| 48 | +
|
| 49 | +# Replace [Unreleased] with the version and date |
| 50 | +/^## \[Unreleased\]/ { |
| 51 | + if (!unreleased_found) { |
| 52 | + print "## [Unreleased]" |
| 53 | + print "" |
| 54 | + print "## [" version "] - " date |
| 55 | + unreleased_found = 1 |
| 56 | + next |
| 57 | + } |
| 58 | +} |
| 59 | +
|
| 60 | +# Capture the first version link to get the previous version |
| 61 | +links_section && first_version_link == "" && /^\[[0-9]+\.[0-9]+\.[0-9]+\]:/ { |
| 62 | + match($0, /\[([0-9]+\.[0-9]+\.[0-9]+)\]:/, arr) |
| 63 | + if (arr[1] != "") { |
| 64 | + first_version_link = arr[1] |
| 65 | + # Insert Unreleased and new version links before first version link |
| 66 | + print "[Unreleased]: https://github.com/copilot-community-sdk/copilot-sdk-java/compare/v" version "...HEAD" |
| 67 | + print "[" version "]: https://github.com/copilot-community-sdk/copilot-sdk-java/compare/v" arr[1] "...v" version |
| 68 | + } |
| 69 | +} |
| 70 | +
|
| 71 | +# Update existing [Unreleased] link if present |
| 72 | +links_section && /^\[Unreleased\]:/ { |
| 73 | + # Get the previous version from the existing link |
| 74 | + match($0, /v([0-9]+\.[0-9]+\.[0-9]+)\.\.\.HEAD/, arr) |
| 75 | + if (arr[1] != "") { |
| 76 | + print "[Unreleased]: https://github.com/copilot-community-sdk/copilot-sdk-java/compare/v" version "...HEAD" |
| 77 | + print "[" version "]: https://github.com/copilot-community-sdk/copilot-sdk-java/compare/v" arr[1] "...v" version |
| 78 | + next |
| 79 | + } |
| 80 | +} |
| 81 | +
|
| 82 | +# Print all other lines unchanged |
| 83 | +{ print } |
| 84 | +' "$CHANGELOG_FILE" > "$TEMP_FILE" |
| 85 | + |
| 86 | +# Replace the original file |
| 87 | +mv "$TEMP_FILE" "$CHANGELOG_FILE" |
| 88 | + |
| 89 | +echo "✓ CHANGELOG.md updated successfully" |
| 90 | +echo " - Added version ${VERSION} with date ${RELEASE_DATE}" |
| 91 | +echo " - Created new [Unreleased] section" |
| 92 | +echo " - Updated version comparison links" |
0 commit comments