diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml index ca8a9601cf..85ea5f0dfe 100644 --- a/.github/workflows/release-drafter.yaml +++ b/.github/workflows/release-drafter.yaml @@ -88,19 +88,19 @@ jobs: fi echo "Auto-Collapsing release notes to reduce size" - echo $notes > $RUNNER_TEMP/release_notes.md + printf "%s\n" "$notes" > $RUNNER_TEMP/release_notes.md bash hack/collapse/auto_collapse.sh $RUNNER_TEMP/release_notes.md $RUNNER_TEMP/release_notes_processed.md ${{ env.COLLAPSE_THRESHOLD }} notes=$(cat $RUNNER_TEMP/release_notes_processed.md) echo "Release Notes generated for ${{env.RELEASE_VERSION}}:" - echo "${notes}" + printf "%s\n" "$notes" echo "Verifying if release ${{env.RELEASE_VERSION}} already exists" if [[ -z $(gh release list -R ${REPO} --json name -q '.[] | select(.name == "${{env.RELEASE_VERSION}}")') ]]; then echo "Release ${{env.RELEASE_VERSION}} does not exist yet, creating from scratch" gh release create ${{env.RELEASE_VERSION}} \ --title "${{env.RELEASE_VERSION}}" \ - --notes "${notes}" \ + --notes "$(printf "%s\n" "$notes")" \ --draft \ --latest=false \ --target ${{ github.ref }} \ diff --git a/hack/collapse/auto_collapse.sh b/hack/collapse/auto_collapse.sh index 6ba7eeedf2..31d7803238 100755 --- a/hack/collapse/auto_collapse.sh +++ b/hack/collapse/auto_collapse.sh @@ -24,16 +24,7 @@ true > "$OUTPUT_FILE" inside_section=false section_lines=() section_header="" - -input="$(cat "$INPUT_FILE")" -FULL_CHANGELOG=$(grep "Full Changelog" < "$INPUT_FILE") - -if [[ -z $FULL_CHANGELOG ]]; then - echo "Full Changelog not found in the input file." -else - echo "Full Changelog found in the input file." - input=$(sed '/Full Changelog/d' <<< "${input}") -fi +last_line="" # Function to count changes (lines starting with '*') count_changes() { @@ -51,6 +42,7 @@ count_changes() { write_section() { local header="$1" local lines=("${@:2}") + local num_changes num_changes=$(count_changes "${lines[@]}") # Write the section header as is @@ -73,15 +65,24 @@ write_section() { } # Read the Markdown file line by line -echo "${input}" | while IFS= read -r line || [[ -n $line ]]; do +while IFS= read -r line || [[ -n $line ]]; do + # Check if the line contains "Full Changelog" + if [[ $line =~ ^\*\*Full\ Changelog ]]; then + # Finalize any pending section + if [[ $inside_section == true ]]; then + write_section "$section_header" "${section_lines[@]:1}" # Exclude the header + inside_section=false + fi + last_line="$line" + continue + fi + # Preserve comment blocks if [[ $line =~ ^\