Skip to content

Commit 41cfcfb

Browse files
committed
Address Qodo code review suggestions
Improve PG version check robustness and efficiency per Qodo feedback: 1. Struct detection: Use sed/grep pipeline to better filter comments and whitespace, reducing false positives. Isolates struct body boundaries more reliably before checking for modifications. 2. File iteration: Use while/read loop instead of for loop to correctly handle filenames that contain spaces. 3. Workflow efficiency: Capture script output once and pass between steps using GITHUB_OUTPUT multiline strings, eliminating redundant execution. Changes reduce false positives and improve compatibility while maintaining the same detection logic.
1 parent 5eae507 commit 41cfcfb

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

.github/scripts/check-pg-versions.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@ check_file_for_pg_changes() {
9595

9696
# Check if this struct's typedef was modified
9797
local struct_pattern="typedef struct ${struct_type%_t}_s"
98-
local struct_changes=$(echo "$diff_output" | grep -A50 "$struct_pattern" | grep -E "^[-+]" | grep -v "^[-+]typedef struct" | grep -v "^[-+]}" | grep -v "^[-+]//" | grep -v "^[-+] \*" || true)
98+
# Isolate struct body from diff, remove comments and empty lines, then check for remaining changes
99+
local struct_body_diff=$(echo "$diff_output" | sed -n "/${struct_pattern}/,/\}.*${struct_type};/p")
100+
local struct_changes=$(echo "$struct_body_diff" | grep -E "^[-+]" \
101+
| grep -v -E "^[-+]\s*(typedef struct|}|//|\*)" \
102+
| sed -E 's://.*$::' \
103+
| sed -E 's:/\*.*\*/::' \
104+
| tr -d '[:space:]')
99105

100106
if [ -n "$struct_changes" ]; then
101107
echo " ⚠️ Struct definition modified"
@@ -145,9 +151,9 @@ EOF
145151
}
146152

147153
# Check each changed file
148-
for file in $CHANGED_FILES; do
154+
while IFS= read -r file; do
149155
check_file_for_pg_changes "$file"
150-
done
156+
done <<< "$CHANGED_FILES"
151157

152158
# Check if any issues were found
153159
if [ -s $ISSUES_FILE ]; then

.github/workflows/pg-version-check.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ jobs:
3131
id: pg_check
3232
run: |
3333
set +e # Don't fail the workflow, just capture exit code
34-
bash .github/scripts/check-pg-versions.sh
35-
echo "exit_code=$?" >> $GITHUB_OUTPUT
34+
# Run script and capture output. Exit code 1 is expected for issues.
35+
# The output is captured and encoded to be passed between steps.
36+
output=$(bash .github/scripts/check-pg-versions.sh 2>&1)
37+
exit_code=$?
38+
echo "exit_code=${exit_code}" >> $GITHUB_OUTPUT
39+
echo "output<<EOF" >> $GITHUB_OUTPUT
40+
echo "$output" >> $GITHUB_OUTPUT
41+
echo "EOF" >> $GITHUB_OUTPUT
3642
env:
3743
GITHUB_BASE_REF: ${{ github.base_ref }}
3844
GITHUB_HEAD_REF: ${{ github.head_ref }}
@@ -42,16 +48,11 @@ jobs:
4248
uses: actions/github-script@v7
4349
with:
4450
script: |
45-
const fs = require('fs');
46-
47-
// Find the issues file (created by the script)
48-
const { execSync } = require('child_process');
51+
// Use the captured output from the previous step
52+
const output = `${{ steps.pg_check.outputs.output }}`;
4953
let issuesContent = '';
5054
5155
try {
52-
// Re-run script to get issues output
53-
const output = execSync('bash .github/scripts/check-pg-versions.sh 2>&1 || true', { encoding: 'utf-8' });
54-
5556
// Extract issues from output (everything after the warning line)
5657
const lines = output.split('\n');
5758
let capturing = false;

0 commit comments

Comments
 (0)