-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_changelog.sh
40 lines (33 loc) · 1.22 KB
/
parse_changelog.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# Default changelog file path
DEFAULT_CHANGELOG_FILE="CHANGELOG.md"
# Function to extract changelog section based on the version number
extract_changelog_section() {
local version="$1"
local file="$2"
# Escape the period for grep to interpret it as a literal period
local version_escaped=$(echo "$version" | sed 's/\./\\./g')
# Find the section for the given version, including the heading
awk -v version="$version_escaped" '
BEGIN { capture=0 }
# Match the beginning of the section with the specified version, including the first line (heading)
$0 ~ "^#+[[:space:]]"version {
capture=1
}
# Stop capturing when the next version section is encountered
capture && $0 ~ "^#+[[:space:]][0-9]+\\.[0-9]+\\.[0-9]+" && !($0 ~ "^#+[[:space:]]"version) {
exit
}
# Print the lines when capture is enabled
capture { print }
' "$file"
}
# Ensure a version number is provided
if [ -z "$1" ]; then
echo "Usage: $0 <version> [changelog_file]"
exit 1
fi
# Use the provided changelog file or the default if not provided
changelog_file="${2:-$DEFAULT_CHANGELOG_FILE}"
# Call the function with provided arguments
extract_changelog_section "$1" "$changelog_file"