Skip to content

Commit dbf0d11

Browse files
authored
Prevent duplicate checkstyle annotations in PHPUnit workflow (#2224)
1 parent 00c30c7 commit dbf0d11

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

.github/workflows/phpunit.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,25 @@ jobs:
115115
EOF
116116
117117
# Check for PHPUnit warnings and process them
118-
if grep -q "WARNINGS!\|There was.*warning" coverage-output.log; then
118+
if grep -q "WARNINGS!" coverage-output.log; then
119119
echo "Processing coverage warnings for checkstyle report..."
120120
121121
# Show warnings section for debugging
122122
echo "--- Warnings Found ---"
123-
sed -n '/There was.*warning/,/WARNINGS!/p' coverage-output.log | head -10
123+
sed -n '/There w.*warning/,/WARNINGS!/p' coverage-output.log | head -10
124124
echo "--- End Warnings ---"
125125
126126
# Extract warnings to temporary file to avoid subshell issues
127-
sed -n '/There was.*warning/,/WARNINGS!/p' coverage-output.log > temp-warnings.txt
127+
sed -n '/There w.*warning/,/WARNINGS!/p' coverage-output.log > temp-warnings.txt
128+
129+
# Track processed file:line combinations to avoid duplicates
130+
declare -A processed_annotations
128131
129132
# Process each line
130133
while IFS= read -r line; do
131134
echo "Processing line: $line"
132135
# Look for @covers warnings
133-
if [[ "$line" =~ \"@covers.*\"\ is\ invalid ]]; then
136+
if [[ "$line" =~ \"@covers[^\"]*\"\ is\ invalid ]]; then
134137
echo "Found @covers warning line: $line"
135138
# Extract the @covers target - everything between quotes
136139
if [[ "$line" =~ \"@covers\ ([^\"]+)\" ]]; then
@@ -146,13 +149,25 @@ jobs:
146149
echo "Found test file: $TEST_FILE"
147150
if LINE_NUM=$(grep -n "@covers.*$METHOD_NAME" "$TEST_FILE" | head -1 | cut -d: -f1); then
148151
echo "Found line number: $LINE_NUM"
149-
# Escape XML characters and add checkstyle entry
150-
MESSAGE=$(echo "Invalid @covers annotation: $COVERS_TARGET" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g')
151-
cat >> coverage-warnings.xml << EOF
152+
153+
# Create unique key for this file:line combination
154+
FILE_LINE_KEY="$TEST_FILE:$LINE_NUM"
155+
156+
# Only process if we haven't seen this file:line before
157+
if [[ -z "${processed_annotations[$FILE_LINE_KEY]}" ]]; then
158+
echo "Adding annotation for $FILE_LINE_KEY"
159+
processed_annotations[$FILE_LINE_KEY]=1
160+
161+
# Escape XML characters and add checkstyle entry
162+
MESSAGE=$(echo "Invalid @covers annotation: $COVERS_TARGET" | sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g')
163+
cat >> coverage-warnings.xml << EOF
152164
<file name="$TEST_FILE">
153165
<error line="$LINE_NUM" column="1" severity="warning" message="$MESSAGE" source="phpunit.coverage"/>
154166
</file>
155167
EOF
168+
else
169+
echo "Skipping duplicate annotation for $FILE_LINE_KEY"
170+
fi
156171
fi
157172
fi
158173
fi

0 commit comments

Comments
 (0)