Skip to content

Commit

Permalink
chore: autocollapse release notes
Browse files Browse the repository at this point in the history
Co-authored-by: Frederic Wilhelm <[email protected]>
  • Loading branch information
jakobmoellerdev and frewilhelm committed Nov 27, 2024
1 parent eb8b089 commit 9e678ba
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions hack/collapse/auto_collapse.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# allow > to overwrite files
set +o noclobber

# Auto Collapse
#This is a script that takes in
# - a markdown file
Expand All @@ -15,21 +18,21 @@ OUTPUT_FILE=${2:-"README_collapsible.md"}
THRESHOLD=${3:-10}

# Ensure output file is empty initially
rm -f "$OUTPUT_FILE"
true > "$OUTPUT_FILE"

# Variables to track sections
inside_section=false
section_lines=()
section_header=""

INPUT="$(cat "$INPUT_FILE")"
FULL_CHANGELOG=$(grep -E "Full Changelog" < "$INPUT_FILE")
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=$(echo "$INPUT" | sed '/Full Changelog/d')
input=$(sed '/Full Changelog/d' <<< "${input}")
fi

# Function to count changes (lines starting with '*')
Expand Down Expand Up @@ -70,7 +73,7 @@ write_section() {
}

# Read the Markdown file line by line
echo "${INPUT}" | while IFS= read -r line || [[ -n $line ]]; do
echo "${input}" | while IFS= read -r line || [[ -n $line ]]; do
# Preserve comment blocks
if [[ $line =~ ^\<!-- ]] || [[ $line =~ ^--\> ]]; then
# Finalize the current section if inside one
Expand Down
2 changes: 1 addition & 1 deletion hack/collapse/test_auto_collapse.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"

# Paths to files
export INPUT_FILE="$SCRIPT_DIR/test_example.md"
Expand Down

0 comments on commit 9e678ba

Please sign in to comment.