Skip to content

Commit 17a4d8b

Browse files
authored
Update CI Tooling (#70)
* Fix issue with stable tag replacement in the release prep script * Add phpstan to GH actions * Check for uncommitted work before continuing * Prepend ? on phpstan sometimes-absent excluded paths * Trying phpstan optional exclude files after reading the docs :)
1 parent aa24337 commit 17a4d8b

File tree

7 files changed

+89
-16
lines changed

7 files changed

+89
-16
lines changed

.github/workflows/phpcs.yml

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
name: Code Standards
22
on:
3+
push:
4+
branches:
5+
- trunk
6+
- 'branch/*'
37
pull_request:
8+
branches:
9+
- trunk
10+
- 'branch/*'
411

512
jobs:
613
phpcs:

.github/workflows/phpstan.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Static Analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- trunk
7+
- 'branch/*'
8+
pull_request:
9+
branches:
10+
- trunk
11+
- 'branch/*'
12+
13+
jobs:
14+
phpstan:
15+
name: PHPStan
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: '8.4'
26+
coverage: none
27+
tools: composer:v2
28+
29+
- name: Install dependencies
30+
run: composer install --no-progress --prefer-dist --no-interaction
31+
32+
- name: Run PHPStan
33+
run: composer test:phpstan

.github/workflows/phpunit.yml

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ name: PHPUnit Tests
22

33
on:
44
push:
5-
branches: [ trunk ]
5+
branches:
6+
- trunk
7+
- 'branch/*'
68
pull_request:
7-
branches: [ trunk ]
9+
branches:
10+
- trunk
11+
- 'branch/*'
812

913
jobs:
1014
test:

bin/prepare-release.php

+34-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class Release_Preparation {
4343
* Run the release preparation
4444
*/
4545
public function run() {
46+
$this->check_uncommitted_changes();
47+
$this->format_packages();
4648
$this->check_requirements();
4749
$this->build_assets();
4850
$this->run_tests();
@@ -90,6 +92,36 @@ public function run() {
9092
echo "\nRelease preparation complete!\n";
9193
}
9294

95+
/**
96+
* Format package files
97+
*/
98+
private function format_packages() {
99+
echo "Formatting package files...\n";
100+
passthru( 'composer normalize', $return );
101+
if ( 0 !== $return ) {
102+
exit( $return );
103+
}
104+
passthru( 'npm run sort-package-json', $return );
105+
if ( 0 !== $return ) {
106+
exit( $return );
107+
}
108+
}
109+
110+
/**
111+
* Check for uncommitted changes and abort if found
112+
*/
113+
private function check_uncommitted_changes() {
114+
exec( 'git status --porcelain', $output, $return );
115+
if ( ! empty( $output ) ) {
116+
echo "Error: You have uncommitted changes. Please commit or stash them before running this script.\n";
117+
echo "Changes found:\n";
118+
foreach ( $output as $line ) {
119+
echo " {$line}\n";
120+
}
121+
exit( 1 );
122+
}
123+
}
124+
93125
/**
94126
* Check if required tools are available
95127
*/
@@ -271,8 +303,8 @@ private function get_stable_tag() {
271303
private function update_stable_tag( $version ) {
272304
$readme = file_get_contents( 'readme.txt' );
273305
$readme = preg_replace(
274-
'/(Stable tag: )[^\s\n]+/',
275-
'$1' . $version,
306+
'/^Stable tag:.*$/m',
307+
'Stable tag: ' . $version,
276308
$readme
277309
);
278310
file_put_contents( 'readme.txt', $readme );

composer.json

+6-9
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@
1717
"ergebnis/composer-normalize": "^2.45",
1818
"nikic/php-parser": "^4.0",
1919
"phpcompatibility/phpcompatibility-wp": "^2.1.3",
20+
"phpstan/extension-installer": "^1.4",
2021
"phpunit/phpunit": "^9.6",
2122
"sirbrillig/phpcs-changed": "^2.11",
2223
"symfony/finder": "^5.0 || ^6.0",
23-
"wp-coding-standards/wpcs": "^3.0",
24-
"yoast/phpunit-polyfills": "^1.1.0",
2524
"szepeviktor/phpstan-wordpress": "^2.0",
26-
"phpstan/extension-installer": "^1.4"
25+
"wp-coding-standards/wpcs": "^3.0",
26+
"yoast/phpunit-polyfills": "^1.1.0"
2727
},
2828
"config": {
2929
"allow-plugins": {
3030
"dealerdirect/phpcodesniffer-composer-installer": true,
3131
"ergebnis/composer-normalize": true,
32-
"roots/wordpress-core-installer": true,
33-
"phpstan/extension-installer": true
32+
"phpstan/extension-installer": true,
33+
"roots/wordpress-core-installer": true
3434
},
3535
"platform": {
3636
"php": "7.4"
@@ -62,10 +62,7 @@
6262
"format:php": "phpcbf",
6363
"lint": "@lint:php",
6464
"lint:php": "phpcs",
65-
"prepare-release": [
66-
"@format:packages",
67-
"php bin/prepare-release.php"
68-
],
65+
"prepare-release": "php bin/prepare-release.php",
6966
"test": [
7067
"@test:php",
7168
"@test:phpstan"

composer.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ parameters:
55
paths:
66
- .
77
excludePaths:
8-
- node_modules
8+
- node_modules (?)
99
- assets
1010
- vendor
1111
- docs
1212
- lang
13-
- wordpress
13+
- wordpress (?)
1414
bootstrapFiles:
1515
- bin/phpstan-bootstrap.php

0 commit comments

Comments
 (0)