Skip to content

Commit

Permalink
chore: fixup release notes
Browse files Browse the repository at this point in the history
the release notes that were fixed up require a small adjustment to be able to deal with properly multilined files.

This is because the notes are stored in bash variables which removes newlines by default. Now they are properly formatted in again and we also fixup the script so that the line count is correct
  • Loading branch information
jakobmoellerdev committed Nov 27, 2024
1 parent 1a5ff47 commit 6ddb66c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release-drafter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }} \
Expand Down
36 changes: 18 additions & 18 deletions hack/collapse/auto_collapse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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 =~ ^\<!-- ]] || [[ $line =~ ^--\> ]]; then
# Finalize the current section if inside one
if [[ $inside_section == true ]]; then
write_section "$section_header" "${section_lines[@]:1}" # Exclude the header
inside_section=false
fi
# Write the comment directly
echo "$line" >> "$OUTPUT_FILE"
continue
fi
Expand All @@ -99,17 +100,16 @@ echo "${input}" | while IFS= read -r line || [[ -n $line ]]; do
# Collect lines of the current section
section_lines+=("$line")
fi
done
done < "$INPUT_FILE"

# Process the last section
if [[ $inside_section == true ]]; then
write_section "$section_header" "${section_lines[@]:1}" # Exclude the header
fi

if [[ ! -z $FULL_CHANGELOG ]]; then
echo "Appending Full Changelog to the end of the file."
printf "\n%s" "$FULL_CHANGELOG" >> "$OUTPUT_FILE"
# Write the "Full Changelog" line if it exists
if [[ -n $last_line ]]; then
printf "\n%s" "$last_line" >> "$OUTPUT_FILE"
fi

echo "Collapsible Markdown written to $OUTPUT_FILE"

0 comments on commit 6ddb66c

Please sign in to comment.