@@ -51,3 +51,133 @@ jobs:
51
51
env :
52
52
PHP_VERSION : ${{ matrix.php-versions }}
53
53
WP_ENVIRONMENT_TYPE : production
54
+
55
+ coverage :
56
+ runs-on : ubuntu-latest
57
+ services :
58
+ mysql :
59
+ image : mariadb:10.4
60
+ env :
61
+ MYSQL_ROOT_PASSWORD : root
62
+ ports :
63
+ - 3306:3306
64
+ options : --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10
65
+ steps :
66
+ - name : Install svn
67
+ run : |
68
+ sudo apt-get update
69
+ sudo apt-get install subversion
70
+ - name : Checkout
71
+ uses : actions/checkout@v5
72
+
73
+ - name : Setup PHP with Xdebug
74
+ uses : shivammathur/setup-php@v2
75
+ with :
76
+ php-version : ' 8.4'
77
+ coverage : xdebug
78
+ tools : composer, phpunit-polyfills, cs2pr
79
+ extensions : mysql
80
+
81
+ - name : Install Composer dependencies for PHP
82
+ uses : ramsey/composer-install@v3
83
+
84
+ - name : Setup Test Environment
85
+ run : bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 latest
86
+
87
+ - name : Unit Testing with Coverage
88
+ run : ./vendor/bin/phpunit --coverage-text --coverage-clover coverage.xml --log-junit junit.xml 2>&1 | tee coverage-output.log
89
+ env :
90
+ WP_ENVIRONMENT_TYPE : production
91
+
92
+ - name : Generate Checkstyle Report for Coverage Warnings
93
+ if : always()
94
+ run : |
95
+ echo "Generating checkstyle report for coverage warnings..."
96
+
97
+ # Create checkstyle XML header
98
+ cat > coverage-warnings.xml << 'EOF'
99
+ <?xml version="1.0" encoding="UTF-8"?>
100
+ <checkstyle version="4.3">
101
+ EOF
102
+
103
+ # Check for PHPUnit warnings and process them
104
+ if grep -q "WARNINGS!\|There was.*warning" coverage-output.log; then
105
+ echo "Processing coverage warnings for checkstyle report..."
106
+
107
+ # Show warnings section for debugging
108
+ echo "--- Warnings Found ---"
109
+ sed -n '/There was.*warning/,/WARNINGS!/p' coverage-output.log | head -10
110
+ echo "--- End Warnings ---"
111
+
112
+ # Extract warnings to temporary file to avoid subshell issues
113
+ sed -n '/There was.*warning/,/WARNINGS!/p' coverage-output.log > temp-warnings.txt
114
+
115
+ # Process each line
116
+ while IFS= read -r line; do
117
+ echo "Processing line: $line"
118
+ # Look for @covers warnings
119
+ if [[ "$line" =~ \"@covers.*\"\ is\ invalid ]]; then
120
+ echo "Found @covers warning line: $line"
121
+ # Extract the @covers target - everything between quotes
122
+ if [[ "$line" =~ \"@covers\ ([^\"]+)\" ]]; then
123
+ COVERS_TARGET="${BASH_REMATCH[1]}"
124
+ echo "Processing @covers warning for: $COVERS_TARGET"
125
+
126
+ # Find test file and line number
127
+ echo "Searching for @covers annotation with target: $COVERS_TARGET"
128
+ # Extract just the method name from the full class::method
129
+ METHOD_NAME=$(echo "$COVERS_TARGET" | sed 's/.*:://')
130
+ echo "Extracted method name: $METHOD_NAME"
131
+ if TEST_FILE=$(find tests/ -name "*.php" -type f -exec grep -l "@covers.*$METHOD_NAME" {} \; | head -1); then
132
+ echo "Found test file: $TEST_FILE"
133
+ if LINE_NUM=$(grep -n "@covers.*$METHOD_NAME" "$TEST_FILE" | head -1 | cut -d: -f1); then
134
+ echo "Found line number: $LINE_NUM"
135
+ # Escape XML characters and add checkstyle entry
136
+ MESSAGE=$(echo "Invalid @covers annotation: $COVERS_TARGET" | sed 's/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'"'"'/\'/g')
137
+ cat >> coverage-warnings.xml << EOF
138
+ <file name="$TEST_FILE">
139
+ <error line="$LINE_NUM" column="1" severity="warning" message="$MESSAGE" source="phpunit.coverage"/>
140
+ </file>
141
+ EOF
142
+ fi
143
+ fi
144
+ fi
145
+ # Look for deprecation warnings
146
+ elif [[ "$line" =~ (deprecated|will\ no\ longer\ be\ possible) ]]; then
147
+ echo "::warning::PHPUnit deprecation warning: ${line}"
148
+ fi
149
+ done < temp-warnings.txt
150
+
151
+ rm -f temp-warnings.txt
152
+ WARNINGS_FOUND=true
153
+ else
154
+ echo "No coverage warnings found"
155
+ WARNINGS_FOUND=false
156
+ fi
157
+
158
+ # Close the checkstyle XML
159
+ echo '</checkstyle>' >> coverage-warnings.xml
160
+
161
+ # Debug: show the generated checkstyle content
162
+ echo "Generated checkstyle report:"
163
+ cat coverage-warnings.xml
164
+
165
+ # Exit with error if warnings were found
166
+ if [ "$WARNINGS_FOUND" = true ]; then
167
+ echo "::error::Coverage analysis produced warnings"
168
+ exit 1
169
+ fi
170
+
171
+ - name : Annotate Coverage Warnings in PR
172
+ if : always() && github.event_name == 'pull_request'
173
+ run : |
174
+ # Check if we have any errors in the checkstyle report
175
+ if grep -q '<error' coverage-warnings.xml; then
176
+ echo "Found coverage warnings to annotate"
177
+ echo "Converting checkstyle report to PR annotations..."
178
+ cs2pr --graceful-warnings coverage-warnings.xml
179
+ else
180
+ echo "No coverage warnings found in checkstyle report"
181
+ fi
182
+ env :
183
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments