diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml index 75bba15a..a3c8def7 100644 --- a/.github/workflows/phpcs.yml +++ b/.github/workflows/phpcs.yml @@ -1,6 +1,13 @@ name: Code Standards on: + push: + branches: + - trunk + - 'branch/*' pull_request: + branches: + - trunk + - 'branch/*' jobs: phpcs: diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 00000000..0a318b66 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,33 @@ +name: Static Analysis + +on: + push: + branches: + - trunk + - 'branch/*' + pull_request: + branches: + - trunk + - 'branch/*' + +jobs: + phpstan: + name: PHPStan + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + coverage: none + tools: composer:v2 + + - name: Install dependencies + run: composer install --no-progress --prefer-dist --no-interaction + + - name: Run PHPStan + run: composer test:phpstan \ No newline at end of file diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 6757263f..ec49a7ce 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -2,9 +2,13 @@ name: PHPUnit Tests on: push: - branches: [ trunk ] + branches: + - trunk + - 'branch/*' pull_request: - branches: [ trunk ] + branches: + - trunk + - 'branch/*' jobs: test: diff --git a/bin/prepare-release.php b/bin/prepare-release.php index eb00cf9d..7d20fd5c 100644 --- a/bin/prepare-release.php +++ b/bin/prepare-release.php @@ -43,6 +43,8 @@ class Release_Preparation { * Run the release preparation */ public function run() { + $this->check_uncommitted_changes(); + $this->format_packages(); $this->check_requirements(); $this->build_assets(); $this->run_tests(); @@ -90,6 +92,36 @@ public function run() { echo "\nRelease preparation complete!\n"; } + /** + * Format package files + */ + private function format_packages() { + echo "Formatting package files...\n"; + passthru( 'composer normalize', $return ); + if ( 0 !== $return ) { + exit( $return ); + } + passthru( 'npm run sort-package-json', $return ); + if ( 0 !== $return ) { + exit( $return ); + } + } + + /** + * Check for uncommitted changes and abort if found + */ + private function check_uncommitted_changes() { + exec( 'git status --porcelain', $output, $return ); + if ( ! empty( $output ) ) { + echo "Error: You have uncommitted changes. Please commit or stash them before running this script.\n"; + echo "Changes found:\n"; + foreach ( $output as $line ) { + echo " {$line}\n"; + } + exit( 1 ); + } + } + /** * Check if required tools are available */ @@ -271,8 +303,8 @@ private function get_stable_tag() { private function update_stable_tag( $version ) { $readme = file_get_contents( 'readme.txt' ); $readme = preg_replace( - '/(Stable tag: )[^\s\n]+/', - '$1' . $version, + '/^Stable tag:.*$/m', + 'Stable tag: ' . $version, $readme ); file_put_contents( 'readme.txt', $readme ); diff --git a/composer.json b/composer.json index 92d5c9ce..d2487154 100644 --- a/composer.json +++ b/composer.json @@ -17,20 +17,20 @@ "ergebnis/composer-normalize": "^2.45", "nikic/php-parser": "^4.0", "phpcompatibility/phpcompatibility-wp": "^2.1.3", + "phpstan/extension-installer": "^1.4", "phpunit/phpunit": "^9.6", "sirbrillig/phpcs-changed": "^2.11", "symfony/finder": "^5.0 || ^6.0", - "wp-coding-standards/wpcs": "^3.0", - "yoast/phpunit-polyfills": "^1.1.0", "szepeviktor/phpstan-wordpress": "^2.0", - "phpstan/extension-installer": "^1.4" + "wp-coding-standards/wpcs": "^3.0", + "yoast/phpunit-polyfills": "^1.1.0" }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, "ergebnis/composer-normalize": true, - "roots/wordpress-core-installer": true, - "phpstan/extension-installer": true + "phpstan/extension-installer": true, + "roots/wordpress-core-installer": true }, "platform": { "php": "7.4" @@ -62,10 +62,7 @@ "format:php": "phpcbf", "lint": "@lint:php", "lint:php": "phpcs", - "prepare-release": [ - "@format:packages", - "php bin/prepare-release.php" - ], + "prepare-release": "php bin/prepare-release.php", "test": [ "@test:php", "@test:phpstan" diff --git a/composer.lock b/composer.lock index a899f9ce..1e900d23 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0ed549f49528a34912ada7cdd46e44ca", + "content-hash": "0db333e4dd2919b0f2cedc2b291c4bc6", "packages": [], "packages-dev": [ { diff --git a/phpstan.neon b/phpstan.neon index 79801a84..84447de4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,11 +5,11 @@ parameters: paths: - . excludePaths: - - node_modules + - node_modules (?) - assets - vendor - docs - lang - - wordpress + - wordpress (?) bootstrapFiles: - bin/phpstan-bootstrap.php