|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Generate comprehensive release notes from git history |
| 5 | +# This captures ALL commits since last release, not just chart updates |
| 6 | + |
| 7 | +CHANGELOG_FILE="CHANGELOG.md" |
| 8 | +RELEASE_NOTES_FILE=".release-notes.md" |
| 9 | +COMMON_HIERA_FILE="modules/enableit/common/data/common.yaml" |
| 10 | +OPENVOX_ENVIRONMENT="common::openvox::environment" |
| 11 | +# Run this when the helm chart update PR is merged into master |
| 12 | +NEW_TAG=$1 |
| 13 | + |
| 14 | +# Get the previous tag |
| 15 | +PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 16 | + |
| 17 | +if [ -z "$NEW_TAG" ]; then |
| 18 | + echo "$0 need new tag version, current tag is $PREVIOUS_TAG" |
| 19 | + exit |
| 20 | +fi |
| 21 | + |
| 22 | +if [ -z "$PREVIOUS_TAG" ]; then |
| 23 | + echo "No previous tag found, using all commits" |
| 24 | + COMMIT_RANGE="HEAD" |
| 25 | +else |
| 26 | + echo "Generating release notes since $PREVIOUS_TAG..$NEW_TAG" |
| 27 | + COMMIT_RANGE="$PREVIOUS_TAG..HEAD" |
| 28 | +fi |
| 29 | + |
| 30 | +# Initialize arrays for categorization |
| 31 | +declare -a FEATURES |
| 32 | +declare -a BUG_FIXES |
| 33 | +declare -a CONFIG_CHANGES |
| 34 | +declare -a OTHER_CHANGES |
| 35 | + |
| 36 | +# Process commits |
| 37 | +while IFS= read -r commit; do |
| 38 | + # Get commit message (first line only) |
| 39 | + message=$(git log --format=%s -n 1 "$commit") |
| 40 | + short_hash=$(git log --format=%h -n 1 "$commit") |
| 41 | + |
| 42 | + # Skip merge commits |
| 43 | + if [[ $message =~ ^Merge ]]; then |
| 44 | + continue |
| 45 | + fi |
| 46 | + |
| 47 | + formatted_message="- $short_hash $message" |
| 48 | + |
| 49 | + # Categorize commits |
| 50 | + if [[ $message =~ ^feat ]]; then |
| 51 | + FEATURES+=("$formatted_message") |
| 52 | + elif [[ $message =~ ^fix ]]; then |
| 53 | + BUG_FIXES+=("$formatted_message") |
| 54 | + elif [[ $message =~ ^chore ]]; then |
| 55 | + CONFIG_CHANGES+=("$formatted_message") |
| 56 | + else |
| 57 | + OTHER_CHANGES+=("$formatted_message") |
| 58 | + fi |
| 59 | +done < <(git rev-list "$COMMIT_RANGE") |
| 60 | + |
| 61 | +cat $CHANGELOG_FILE | tail -n +5 > $CHANGELOG_FILE.tmp |
| 62 | + |
| 63 | +# Generate release notes file |
| 64 | +{ |
| 65 | + printf '%s\n' "## LinuxAid Release Version ${NEW_TAG}" |
| 66 | + echo "" |
| 67 | + |
| 68 | + if [ ${#FEATURES[@]} -gt 0 ]; then |
| 69 | + echo "### Features" |
| 70 | + printf '%s\n' "${FEATURES[@]}" |
| 71 | + echo "" |
| 72 | + fi |
| 73 | + |
| 74 | + if [ ${#BUG_FIXES[@]} -gt 0 ]; then |
| 75 | + echo "### Bug Fixes" |
| 76 | + printf '%s\n' "${BUG_FIXES[@]}" |
| 77 | + echo "" |
| 78 | + fi |
| 79 | + |
| 80 | + if [ ${#CONFIG_CHANGES[@]} -gt 0 ]; then |
| 81 | + echo "### Configuration Changes" |
| 82 | + printf '%s\n' "${CONFIG_CHANGES[@]}" |
| 83 | + echo "" |
| 84 | + fi |
| 85 | + |
| 86 | + if [ ${#OTHER_CHANGES[@]} -gt 0 ]; then |
| 87 | + echo "### Other Changes" |
| 88 | + printf '%s\n' "${OTHER_CHANGES[@]}" |
| 89 | + echo "" |
| 90 | + fi |
| 91 | + |
| 92 | + # If no commits categorized, add a note |
| 93 | + total=$((${#FEATURES[@]} + ${#BUG_FIXES[@]} + ${#CONFIG_CHANGES[@]} + ${#OTHER_CHANGES[@]})) |
| 94 | + if [ $total -eq 0 ]; then |
| 95 | + echo "No changes in this release." |
| 96 | + fi |
| 97 | +} > "$RELEASE_NOTES_FILE" |
| 98 | + |
| 99 | +{ |
| 100 | + printf '%s\n' "# Changelog" |
| 101 | + echo "" |
| 102 | + printf '%s\n' "All releases and the changes included in them (pulled from git commits added since last release) will be detailed in this file." |
| 103 | + echo "" |
| 104 | +} > "$CHANGELOG_FILE" |
| 105 | + |
| 106 | + |
| 107 | +# Prepend the new release note in the changelog.md file |
| 108 | +cat "$RELEASE_NOTES_FILE" "$CHANGELOG_FILE.tmp" >> "$CHANGELOG_FILE" |
| 109 | + |
| 110 | +echo "Release notes generated: $CHANGELOG_FILE" |
| 111 | +rm -fr $CHANGELOG_FILE.tmp |
| 112 | + |
| 113 | +# yq ends up removing the blank lines |
| 114 | +#yq eval -i -P ".[\"common::openvox::environment\"] = \"$NEW_TAG\"" "$COMMON_HIERA_FILE" |
| 115 | +sed -i "s/$OPENVOX_ENVIRONMENT: \"$PREVIOUS_TAG\"/$OPENVOX_ENVIRONMENT: \"$NEW_TAG\"/g" "$COMMON_HIERA_FILE" |
| 116 | +echo "Openvox environment is updated to $NEW_TAG" |
| 117 | + |
| 118 | +exit |
| 119 | +if [[ -n "$(git status --porcelain)" ]]; then |
| 120 | + git add -A "$CHANGELOG_FILE" "$RELEASE_NOTES_FILE" "$COMMON_HIERA_FILE" |
| 121 | + git commit -m "chore(doc): Update changelog" |
| 122 | +fi |
| 123 | + |
| 124 | +git tag -a "$NEW_TAG" -m "Linuxaid Release $NEW_TAG" |
| 125 | + |
| 126 | +echo "Pushing changelog changes to Gitea" |
| 127 | +git push origin master |
| 128 | + |
| 129 | +echo "Pushing tag to Gitea" |
| 130 | +git push origin "$NEW_TAG" |
| 131 | + |
| 132 | +echo "Pushing changelog changes to Github" |
| 133 | +git push github master |
| 134 | + |
| 135 | +echo "Pushing tag to Github" |
| 136 | +git push github "$NEW_TAG" |
0 commit comments