Skip to content

Commit a867960

Browse files
Fix Changelog Verification
Currently does not flatten the content so word wraps are missed such as: "any additionnal GN must be manually reconfigured." Also only checks between 2 matches firmware versions, which won't exist between firmware jumps in changelog 388.8 and 3006. This commit addresses these both by flattening the new lines and also checking for the date format instead of the firmware versions.
1 parent 1cf1add commit a867960

File tree

1 file changed

+36
-51
lines changed

1 file changed

+36
-51
lines changed

MerlinAU.sh

Lines changed: 36 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7214,13 +7214,20 @@ _Toggle_ScriptAutoUpdate_Config_()
72147214
}
72157215

72167216
##------------------------------------------##
7217-
## Modified by ExtremeFiretop [2025-Apr-11] ##
7217+
## Modified by ExtremeFiretop [2025-May-21] ##
72187218
##------------------------------------------##
72197219
_high_risk_phrases_interactive_()
72207220
{
72217221
local changelog_contents="$1"
7222+
local changelog_flat
7223+
7224+
changelog_flat="$(
7225+
printf '%s' "$changelog_contents" \
7226+
| tr '\n' ' ' \
7227+
| tr -s ' '
7228+
)"
72227229

7223-
if echo "$changelog_contents" | grep -Eiq "$high_risk_terms"
7230+
if echo "$changelog_flat" | grep -Eiq "$high_risk_terms"
72247231
then
72257232
ChangelogApproval="$(Get_Custom_Setting "FW_New_Update_Changelog_Approval")"
72267233

@@ -7260,13 +7267,20 @@ _high_risk_phrases_interactive_()
72607267
}
72617268

72627269
##------------------------------------------##
7263-
## Modified by ExtremeFiretop [2024-May-26] ##
7270+
## Modified by ExtremeFiretop [2025-May-21] ##
72647271
##------------------------------------------##
72657272
_high_risk_phrases_nointeractive_()
72667273
{
72677274
local changelog_contents="$1"
7275+
local changelog_flat
7276+
7277+
changelog_flat="$(
7278+
printf '%s' "$changelog_contents" \
7279+
| tr '\n' ' ' \
7280+
| tr -s ' '
7281+
)"
72687282

7269-
if echo "$changelog_contents" | grep -Eiq "$high_risk_terms"
7283+
if echo "$changelog_flat" | grep -Eiq "$high_risk_terms"
72707284
then
72717285
_SendEMailNotification_ STOP_FW_UPDATE_APPROVAL
72727286
Update_Custom_Settings "FW_New_Update_Changelog_Approval" "BLOCKED"
@@ -7332,60 +7346,31 @@ _ChangelogVerificationCheck_()
73327346
_DoCleanUp_
73337347
return 1
73347348
else
7335-
# Use awk to format the version based on the number of initial digits #
7336-
formatted_current_version=$(echo "$current_version" | awk -F. '{
7337-
if ($1 ~ /^[0-9]{4}$/) { # Check for a four-digit prefix
7338-
if (NF == 4) {
7339-
# Remove any non-digit characters from the fourth field
7340-
sub(/[^0-9].*/, "", $4)
7341-
if ($4 == "0") {
7342-
printf "%s.%s", $2, $3 # For version like 3004.388.5.0, remove the last .0
7343-
} else {
7344-
printf "%s.%s.%s", $2, $3, $4 # For version like 3004.388.5.2, keep the last digit
7345-
}
7346-
}
7347-
} else if (NF == 3) { # For version without a four-digit prefix
7348-
if ($3 == "0") {
7349-
printf "%s.%s", $1, $2 # For version like 388.5.0, remove the last .0
7350-
} else {
7351-
printf "%s.%s.%s", $1, $2, $3 # For version like 388.5.2, keep the last digit
7352-
}
7353-
}
7354-
}')
7355-
7356-
formatted_release_version=$(echo "$release_version" | awk -F. '{
7357-
if ($1 ~ /^[0-9]{4}$/) { # Check for a four-digit prefix
7358-
if (NF == 4 && $4 == "0") {
7359-
printf "%s.%s", $2, $3 # For version like 3004.388.5.0, remove the last .0
7360-
} else if (NF == 4) {
7361-
printf "%s.%s.%s", $2, $3, $4 # For version like 3004.388.5.2, keep the last digit
7362-
}
7363-
} else if (NF == 3) { # For version without a four-digit prefix
7364-
if ($3 == "0") {
7365-
printf "%s.%s", $1, $2 # For version like 388.5.0, remove the last .0
7366-
} else {
7367-
printf "%s.%s.%s", $1, $2, $3 # For version like 388.5.2, keep the last digit
7368-
}
7369-
}
7370-
}')
7371-
73727349
# Define regex patterns for both versions #
7373-
release_version_regex="${formatted_release_version//./[._]}\s*\([0-9]{1,2}-[A-Za-z]+-[0-9]{4}\)"
7374-
current_version_regex="${formatted_current_version//./[._]}\s*\([0-9]{1,2}-[A-Za-z]+-[0-9]{4}\)"
7350+
local date_pattern='[0-9]{1,2}-[A-Za-z]+-[0-9]{4}'
73757351

73767352
if "$isGNUtonFW"
73777353
then
73787354
# For Gnuton, the whole file is relevant as it only contains the current version #
73797355
changelog_contents="$(cat "$changeLogFPath")"
73807356
else
7381-
if ! grep -Eq "$current_version_regex" "$changeLogFPath"
7382-
then
7383-
Say "Current version NOT found in changelog file. Bypassing changelog verification for this run."
7384-
return 0
7385-
fi
7386-
# Extract log contents between two firmware versions from RMerlin #
7387-
changelog_contents="$(awk "/$release_version_regex/,/$current_version_regex/" "$changeLogFPath")"
7388-
fi
7357+
# find the first two matching line numbers
7358+
match1=$(grep -nE "$date_pattern" "$changeLogFPath" | head -1)
7359+
match2=$(grep -nE "$date_pattern" "$changeLogFPath" | head -2 | tail -1)
7360+
7361+
# split on the first colon
7362+
line1=${match1%%:*}
7363+
line2=${match2%%:*}
7364+
7365+
if [ -n "$line1" ] && [ -n "$line2" ] && [ "$line1" -le "$line2" ]; then
7366+
changelog_contents="$(
7367+
sed -n "${line1},${line2}p" "$changeLogFPath"
7368+
)"
7369+
else
7370+
Say "Could not find two date markers in changelog. Using entire file"
7371+
changelog_contents="$(cat "$changeLogFPath")"
7372+
fi
7373+
fi
73897374

73907375
if [ "$mode" = "interactive" ]
73917376
then

0 commit comments

Comments
 (0)