-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathcheck-pg-versions.sh
More file actions
executable file
Β·169 lines (139 loc) Β· 5.84 KB
/
check-pg-versions.sh
File metadata and controls
executable file
Β·169 lines (139 loc) Β· 5.84 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/bin/bash
#
# Check if parameter group struct modifications include version increments
# This prevents settings corruption when struct layout changes without version bump
#
# Exit codes:
# 0 - No issues found
# 1 - Potential issues detected (will post comment)
# 2 - Script error
set -euo pipefail
# Output file for issues found
ISSUES_FILE=$(mktemp)
trap "rm -f $ISSUES_FILE" EXIT
# Color output for local testing
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
else
RED=''
GREEN=''
YELLOW=''
NC=''
fi
echo "π Checking for Parameter Group version updates..."
# Get base and head commits
BASE_REF=${GITHUB_BASE_REF:-}
HEAD_REF=${GITHUB_HEAD_REF:-}
if [ -z "$BASE_REF" ] || [ -z "$HEAD_REF" ]; then
echo "β οΈ Warning: Not running in GitHub Actions PR context"
echo "Using git diff against HEAD~1 for local testing"
BASE_COMMIT="HEAD~1"
HEAD_COMMIT="HEAD"
else
BASE_COMMIT="origin/$BASE_REF"
HEAD_COMMIT="HEAD"
fi
# Get list of changed files
CHANGED_FILES=$(git diff --name-only $BASE_COMMIT..$HEAD_COMMIT | grep -E '\.(c|h)$' || true)
if [ -z "$CHANGED_FILES" ]; then
echo "β
No C/H files changed"
exit 0
fi
echo "π Changed files:"
echo "$CHANGED_FILES" | sed 's/^/ /'
# Function to extract PG info from a file
check_file_for_pg_changes() {
local file=$1
local diff_output=$(git diff $BASE_COMMIT..$HEAD_COMMIT -- "$file")
# Check if file contains PG_REGISTER (in either old or new version)
if ! echo "$diff_output" | grep -q "PG_REGISTER"; then
return 0
fi
echo " π Checking $file (contains PG_REGISTER)"
# Extract all PG_REGISTER lines from the diff (both old and new)
local pg_registers=$(echo "$diff_output" | grep -E "^[-+].*PG_REGISTER" || true)
if [ -z "$pg_registers" ]; then
# PG_REGISTER exists but wasn't changed
# Still need to check if the struct changed
pg_registers=$(git show $HEAD_COMMIT:"$file" | grep "PG_REGISTER" || true)
fi
# Process each PG registration
while IFS= read -r pg_line; do
[ -z "$pg_line" ] && continue
# Extract struct name and version
# Pattern: PG_REGISTER.*\((\w+),\s*(\w+),\s*PG_\w+,\s*(\d+)\)
if [[ $pg_line =~ PG_REGISTER[^(]*\(([^,]+),([^,]+),([^,]+),([^)]+)\) ]]; then
local struct_type="${BASH_REMATCH[1]}"
local pg_name="${BASH_REMATCH[2]}"
local pg_id="${BASH_REMATCH[3]}"
local version="${BASH_REMATCH[4]}"
# Clean up whitespace
struct_type=$(echo "$struct_type" | xargs)
version=$(echo "$version" | xargs)
echo " π Found: $struct_type (version $version)"
# Check if this struct's typedef was modified
local struct_pattern="typedef struct ${struct_type%_t}_s"
# Isolate struct body from diff, remove comments and empty lines, then check for remaining changes
local struct_body_diff=$(echo "$diff_output" | sed -n "/${struct_pattern}/,/\}.*${struct_type};/p")
local struct_changes=$(echo "$struct_body_diff" | grep -E "^[-+]" \
| grep -v -E "^[-+]\s*(typedef struct|}|//|\*)" \
| sed -E 's://.*$::' \
| sed -E 's:/\*.*\*/::' \
| tr -d '[:space:]')
if [ -n "$struct_changes" ]; then
echo " β οΈ Struct definition modified"
# Check if version was incremented in this diff
local old_version=$(echo "$diff_output" | grep "^-.*PG_REGISTER.*$struct_type" | grep -oP ',\s*\K\d+(?=\s*\))' || echo "")
local new_version=$(echo "$diff_output" | grep "^+.*PG_REGISTER.*$struct_type" | grep -oP ',\s*\K\d+(?=\s*\))' || echo "")
if [ -n "$old_version" ] && [ -n "$new_version" ]; then
if [ "$new_version" -le "$old_version" ]; then
echo " β Version NOT incremented ($old_version β $new_version)"
# Find line number of PG_REGISTER
local line_num=$(git show $HEAD_COMMIT:"$file" | grep -n "PG_REGISTER.*$struct_type" | cut -d: -f1 | head -1)
# Add to issues list
cat >> $ISSUES_FILE << EOF
### \`$struct_type\` ($file:$line_num)
- **Struct modified:** Field changes detected
- **Version status:** β Not incremented (version $version)
- **Recommendation:** Review changes and increment version if needed
EOF
else
echo " β
Version incremented ($old_version β $new_version)"
fi
elif [ -z "$old_version" ] || [ -z "$new_version" ]; then
# Couldn't determine version change, but struct was modified
echo " β οΈ Could not determine if version was incremented"
local line_num=$(git show $HEAD_COMMIT:"$file" | grep -n "PG_REGISTER.*$struct_type" | cut -d: -f1 | head -1)
cat >> $ISSUES_FILE << EOF
### \`$struct_type\` ($file:$line_num)
- **Struct modified:** Field changes detected
- **Version status:** β οΈ Unable to verify version increment
- **Current version:** $version
- **Recommendation:** Verify version was incremented if struct layout changed
EOF
fi
else
echo " β
Struct unchanged"
fi
fi
done <<< "$pg_registers"
}
# Check each changed file
while IFS= read -r file; do
check_file_for_pg_changes "$file"
done <<< "$CHANGED_FILES"
# Check if any issues were found
if [ -s $ISSUES_FILE ]; then
echo ""
echo "${YELLOW}β οΈ Potential PG version issues detected${NC}"
echo "Output saved to: $ISSUES_FILE"
cat $ISSUES_FILE
exit 1
else
echo ""
echo "${GREEN}β
No PG version issues detected${NC}"
exit 0
fi