-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b31de5
commit b8df617
Showing
8 changed files
with
178 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
examples/lib/tour/0* | ||
docs/reference | ||
docs/pluginreference | ||
hack/collapse/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test_example_collapsible.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/bin/bash | ||
|
||
# Auto Collapse | ||
#This is a script that takes in | ||
# - a markdown file | ||
# - a designated output file | ||
# - the number of lines as a threshold on when to collapse a section. | ||
# | ||
# Sample | ||
# ./auto_collapse.sh test_example.md test_example_collapsible.md 10 | ||
|
||
# Input and output files | ||
INPUT_FILE=${1:-"README.md"} | ||
OUTPUT_FILE=${2:-"README_collapsible.md"} | ||
THRESHOLD=${3:-10} | ||
|
||
# Ensure output file is empty initially | ||
rm -f "$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") | ||
|
||
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') | ||
fi | ||
|
||
# Function to process and write a section | ||
write_section() { | ||
local header="$1" | ||
local lines=("${@:2}") | ||
local num_lines=$((${#lines[@]}-1)) | ||
|
||
# Write the section header as is | ||
echo "$header" >> "$OUTPUT_FILE" | ||
|
||
if [[ $num_lines -gt $THRESHOLD ]]; then | ||
# Collapse only the content with a dynamic summary | ||
{ | ||
echo "<details>" | ||
echo "<summary>${num_lines} changes</summary>" | ||
echo "" | ||
printf "%s\n" "${lines[@]}" | ||
echo "</details>" | ||
} >> "$OUTPUT_FILE" | ||
else | ||
# Write the content as is if it's below the threshold | ||
printf "%s\n" "${lines[@]}" >> "$OUTPUT_FILE" | ||
fi | ||
} | ||
|
||
# Read the Markdown file line by line | ||
echo "${INPUT}" | while IFS= read -r line || [[ -n $line ]]; do | ||
# 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 | ||
|
||
if [[ $line =~ ^#+\ ]]; then # New section starts | ||
if [[ $inside_section == true ]]; then | ||
# Write the previous section | ||
write_section "$section_header" "${section_lines[@]:1}" # Exclude the header | ||
fi | ||
# Start a new section | ||
section_header="$line" | ||
section_lines=("$line") # Initialize section with the header | ||
inside_section=true | ||
else | ||
# Collect lines of the current section | ||
section_lines+=("$line") | ||
fi | ||
done | ||
|
||
# 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" | ||
fi | ||
|
||
echo "Collapsible Markdown written to $OUTPUT_FILE" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
||
# Paths to files | ||
export INPUT_FILE="$SCRIPT_DIR/test_example.md" | ||
export OUTPUT_FILE="$SCRIPT_DIR/test_example_collapsible.md" | ||
export EXPECTED_FILE="$SCRIPT_DIR/test_example_expected_collapsible.md" | ||
export SCRIPT="$SCRIPT_DIR/auto_collapse.sh" | ||
|
||
# Run the script | ||
bash "$SCRIPT" "$INPUT_FILE" "$OUTPUT_FILE" 5 | ||
|
||
if [ ! -f "$OUTPUT_FILE" ]; then | ||
echo "Test failed: Output file not found." | ||
exit 1 | ||
fi | ||
|
||
# Compare output with expected file | ||
if diff -q "$OUTPUT_FILE" "$EXPECTED_FILE" > /dev/null; then | ||
echo "Test passed: Output matches expected result." | ||
else | ||
echo "Test failed: Output does not match expected result." | ||
echo "Differences:" | ||
diff "$OUTPUT_FILE" "$EXPECTED_FILE" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!-- Release notes generated using configuration in .github/config/release.yml at refs/heads/releases/v0.19 --> | ||
<!-- markdown-link-check-disable --> | ||
## What's Changed | ||
### 🚀 Features | ||
* feat(log): log http requests for OCI and docker based on trace level by injecting a logger by @author in https://github.com/open-component-model/ocm/pull/1118 | ||
### 🧰 Maintenance | ||
* chore: change guide for 0.18.0 by @author in https://github.com/open-component-model/ocm/pull/1066 | ||
* chore: allow publishing to Brew via custom script by @author in https://github.com/open-component-model/ocm/pull/1059 | ||
* chore: remove ocm inception during build CTF aggregation by @author in https://github.com/open-component-model/ocm/pull/1065 | ||
* chore: release branches as `releases/vX.Y` instead of `releases/vX.Y.Z` by @author in https://github.com/open-component-model/ocm/pull/1071 | ||
* chore: cleanup release action by @author in https://github.com/open-component-model/ocm/pull/1076 | ||
* chore: bump version to 0.19.0-dev by @author in https://github.com/open-component-model/ocm/pull/1084 | ||
* chore: disable mandatory period comments by @author in https://github.com/open-component-model/ocm/pull/1079 | ||
|
||
**Full Changelog**: https://github.com/open-component-model/ocm/compare/v0.18...v0.19.0 | ||
<!-- markdown-link-check-enable --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!-- Release notes generated using configuration in .github/config/release.yml at refs/heads/releases/v0.19 --> | ||
<!-- markdown-link-check-disable --> | ||
## What's Changed | ||
|
||
### 🚀 Features | ||
* feat(log): log http requests for OCI and docker based on trace level by injecting a logger by @author in https://github.com/open-component-model/ocm/pull/1118 | ||
### 🧰 Maintenance | ||
<details> | ||
<summary>7 changes</summary> | ||
|
||
* chore: change guide for 0.18.0 by @author in https://github.com/open-component-model/ocm/pull/1066 | ||
* chore: allow publishing to Brew via custom script by @author in https://github.com/open-component-model/ocm/pull/1059 | ||
* chore: remove ocm inception during build CTF aggregation by @author in https://github.com/open-component-model/ocm/pull/1065 | ||
* chore: release branches as `releases/vX.Y` instead of `releases/vX.Y.Z` by @author in https://github.com/open-component-model/ocm/pull/1071 | ||
* chore: cleanup release action by @author in https://github.com/open-component-model/ocm/pull/1076 | ||
* chore: bump version to 0.19.0-dev by @author in https://github.com/open-component-model/ocm/pull/1084 | ||
* chore: disable mandatory period comments by @author in https://github.com/open-component-model/ocm/pull/1079 | ||
|
||
</details> | ||
<!-- markdown-link-check-enable --> | ||
|
||
**Full Changelog**: https://github.com/open-component-model/ocm/compare/v0.18...v0.19.0 |