|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Check if the correct number of arguments is provided |
| 4 | +if [ "$#" -ne 2 ]; then |
| 5 | + echo "Usage: $0 <path_to_Chart.yaml> <path_to_CHANGELOG.md>" |
| 6 | + exit 1 |
| 7 | +fi |
| 8 | + |
| 9 | +# Assign input arguments to variables |
| 10 | +CHART_YAML="$1" |
| 11 | +CHANGELOG_FILE="$2" |
| 12 | + |
| 13 | +# Check if the Chart.yaml file exists |
| 14 | +if [ ! -f "$CHART_YAML" ]; then |
| 15 | + echo "Error: Chart.yaml file not found at $CHART_YAML" |
| 16 | + exit 1 |
| 17 | +fi |
| 18 | + |
| 19 | +# Extract the artifacthub.io/changes section from the Chart.yaml |
| 20 | +CHANGES=$(sed -n '/artifacthub.io\/changes: |/,/^dependencies:/p' "$CHART_YAML" | sed '1d;$d') |
| 21 | + |
| 22 | +echo $CHANGES |
| 23 | + |
| 24 | +# Create associative arrays to store changes by kind |
| 25 | +declare -A changes_by_kind |
| 26 | + |
| 27 | +# Iterate through the changes and group them by kind |
| 28 | +current_kind="" |
| 29 | +while read -r line; do |
| 30 | + if [[ $line == *"- kind:"* ]]; then |
| 31 | + current_kind=$(echo "$line" | sed 's/.*kind: //') |
| 32 | + # Initialize an empty array for the kind if it doesn't exist |
| 33 | + if [[ -z "${changes_by_kind[$current_kind]}" ]]; then |
| 34 | + changes_by_kind[$current_kind]="" |
| 35 | + fi |
| 36 | + elif [[ $line == *"description:"* ]]; then |
| 37 | + description=$(echo "$line" | sed 's/.*description: "//;s/"//') |
| 38 | + # Append the description to the corresponding kind |
| 39 | + changes_by_kind[$current_kind]+="- $description"$'\n' |
| 40 | + fi |
| 41 | +done <<< "$CHANGES" |
| 42 | + |
| 43 | +# Create the CHANGELOG.md file and write the header |
| 44 | +echo "# Changelog" > "$CHANGELOG_FILE" |
| 45 | +echo "" >> "$CHANGELOG_FILE" |
| 46 | + |
| 47 | +# Write the changes grouped by kind to the CHANGELOG.md file |
| 48 | +for kind in "${!changes_by_kind[@]}"; do |
| 49 | + if [[ -n "${changes_by_kind[$kind]}" ]]; then |
| 50 | + echo "## $kind" >> "$CHANGELOG_FILE" |
| 51 | + echo "${changes_by_kind[$kind]}" >> "$CHANGELOG_FILE" |
| 52 | + fi |
| 53 | +done |
0 commit comments