forked from kedacore/keda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate-changelog.sh
executable file
·73 lines (55 loc) · 2.57 KB
/
validate-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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env bash
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
# Define filename
filename="$SCRIPT_ROOT/CHANGELOG.md"
# Check if file exists
if [[ ! -f "$filename" ]]; then
echo "Error: $filename does not exist."
exit 1
fi
# Storing the version to be checked
mapfile -t versions < <(awk '/## History/{flag=1;next}/## /{flag=0}flag' "$filename" | grep -o '\[[^]]*\]' | grep -v "v1." | sed 's/[][]//g')
# Define a function to extract and sort sections
function extract_and_check() {
local section=$1
local content_block=$2
local content=$(awk "/### $section/{flag=1;next}/### /{flag=0}flag" <<< "$content_block" | grep '^- \*\*')
# Skip if content does not exist
if [[ -z "$content" ]]; then
return
fi
# Separate and sort the **General**: lines
local sorted_general_lines=$(echo "$content" | grep '^- \*\*General\*\*:' | LC_ALL=en_US sort --ignore-case --dictionary-order)
# Sort the remaining lines
local sorted_content=$(echo "$content" | grep -v '^- \*\*General\*\*:' | LC_ALL=en_US sort --ignore-case --dictionary-order)
# Check if sorted_general_lines is not empty, then concatenate
if [[ -n "$sorted_general_lines" ]]; then
sorted_content=$(printf "%s\n%s" "$sorted_general_lines" "$sorted_content")
fi
# Check pattern and throw error if wrong pattern found
while IFS= read -r line; do
echo "Error: Wrong pattern found in section: $section , line: $line"
exit 1
done < <(grep -Pv '^(-\s\*\*[^*]+\*\*: .*\(\[#(\d+|XXX)\]\(https:\/\/github\.com\/kedacore\/(keda|charts|governance)\/(pull|issues|discussions)\/\2\)(?:\|\[#(\w+)\]\(https:\/\/github\.com\/kedacore\/(keda|charts|governance)\/(pull|issues|discussions)\/(?:\5)\)){0,}\))$' <<< "$content")
if [ "$content" != "$sorted_content" ]; then
echo "Error: Section: $section is not sorted correctly. Correct order:"
echo "$sorted_content"
exit 1
fi
}
# Extract release sections, including "Unreleased", and check them
for version in "${versions[@]}"; do
release_content=$(awk "/## $version/{flag=1;next}/## v[0-9\.]+/{flag=0}flag" "$filename")
if [[ -z "$release_content" ]]; then
echo "No content found for $version Skipping."
continue
fi
echo "Checking section: $version"
# Separate content into different sections and check sorting for each release
extract_and_check "New" "$release_content"
extract_and_check "Experimental" "$release_content"
extract_and_check "Improvements" "$release_content"
extract_and_check "Fixes" "$release_content"
extract_and_check "Deprecations" "$release_content"
extract_and_check "Other" "$release_content"
done