Skip to content

Commit

Permalink
Declare PHP version requirement in all Composer packages
Browse files Browse the repository at this point in the history
This makes for a better experience for third parties using the packages,
as they can see on Packagist which PHP versions the package is supposed
to support.

Also this is a good excuse to make a major version bump for all the
packages following #34126 which removed testing with PHP 5.6 and allows
use of 7.0+ features going forward.

And since we're making systematic use of declared PHP versions now,
let's lint for that and make use of it to skip phpunit tests where
appropriate.
  • Loading branch information
anomiex committed Nov 17, 2023
1 parent b62f68f commit f2c1bcb
Show file tree
Hide file tree
Showing 120 changed files with 338 additions and 28 deletions.
9 changes: 8 additions & 1 deletion .github/files/lint-project-structure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cd $(dirname "${BASH_SOURCE[0]}")/../..
BASE=$PWD
. "$BASE/tools/includes/check-osx-bash-version.sh"
. "$BASE/tools/includes/chalk-lite.sh"
. "$BASE/.github/versions.sh"

if [[ -n "$CI" ]]; then
function debug {
Expand Down Expand Up @@ -226,6 +227,13 @@ for PROJECT in projects/*/*; do
echo "::error file=$PROJECT/composer.json::Package $SLUG should set \`.extra.branch-alias.dev-trunk\` in composer.json."
fi

# - Packages must set `.require.php`.
if [[ "$TYPE" == "packages" ]] && ! jq -e '.require.php // null' "$PROJECT/composer.json" >/dev/null; then
EXIT=1
LINE=$(jq --stream -r 'if length == 1 then .[0][:-1] else .[0] end | if . == ["require"] then ",line=\( input_line_number )" else empty end' "$PROJECT/composer.json")
echo "::error file=$PROJECT/composer.json$LINE::Package $SLUG should set \`.require.php\` in composer.json (probably to \">=$MIN_PHP_VERSION\")."
fi

SUGGESTION="You might add this with \`composer config autoloader-suffix '$(printf "%s" "$SLUG" | md5sum | sed -e 's/[[:space:]]*-$//')_$(sed -e 's/[^0-9a-zA-Z]/_/g' <<<"${SLUG##*/}")ⓥversion'\` in the appropriate directory."

# - If vendor/autoload.php or vendor/autoload_packages.php is production-included, composer.json must set .config.autoloader-suffix.
Expand Down Expand Up @@ -453,7 +461,6 @@ for FILE in $(git -c core.quotepath=off ls-files 'projects/packages/**/.eslintrc
done

# - .nvmrc should match .github/versions.sh.
. .github/versions.sh
debug "Checking .nvmrc vs versions.sh"
if [[ "$(<.nvmrc)" != "$NODE_VERSION" ]]; then
EXIT=1
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ jobs:
echo "Skipping $SLUG, no changes in it or its dependencies"
elif ! jq --arg script "$TEST_SCRIPT" -e '.scripts[$script] // false' "$P" > /dev/null; then
echo "Skipping $SLUG, no test script is defined in composer.json"
elif php -r 'exit( preg_match( "/^>=\\s*(\\d+\\.\\d+)$/", $argv[1], $m ) && version_compare( PHP_VERSION, $m[1], "<" ) ? 0 : 1 );' "$( jq -r '.require.php // ""' "$P" )"; then
echo "Skipping $SLUG, requires PHP $( jq -r '.require.php // ""' "$P" ) but PHP version is $( php -r 'echo PHP_VERSION;' )"
else
if jq --arg script "skip-$TEST_SCRIPT" -e '.scripts[$script] // false' "$P" > /dev/null; then
{ composer --working-dir="$DIR" run "skip-$TEST_SCRIPT"; CODE=$?; } || true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
4 changes: 3 additions & 1 deletion projects/packages/a8c-mc-stats/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "Used to record internal usage stats for Automattic. Not visible to site owners.",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {},
"require": {
"php": ">=7.0"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
"automattic/jetpack-changelogger": "@dev"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/abtest/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.0",
"automattic/jetpack-connection": "@dev",
"automattic/jetpack-error": "@dev"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/action-bar/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.0",
"automattic/jetpack-assets": "@dev",
"automattic/jetpack-constants": "@dev"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
4 changes: 3 additions & 1 deletion projects/packages/admin-ui/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "Generic Jetpack wp-admin UI elements",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {},
"require": {
"php": ">=7.0"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
"automattic/jetpack-changelogger": "@dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/analyzer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"static analysis"
],
"require": {
"php": ">=7.0",
"nikic/php-parser": "4.13.2"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/assets/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.0",
"automattic/jetpack-constants": "@dev"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/autoloader/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"wordpress"
],
"require": {
"php": ">=7.0",
"composer-plugin-api": "^1.1 || ^2.0"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/backup/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.0",
"automattic/jetpack-assets": "@dev",
"automattic/jetpack-admin-ui": "@dev",
"automattic/jetpack-autoloader": "@dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/blaze/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.0",
"automattic/jetpack-assets": "@dev",
"automattic/jetpack-connection": "@dev",
"automattic/jetpack-constants": "@dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/blocks/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.0",
"automattic/jetpack-constants": "@dev"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
4 changes: 3 additions & 1 deletion projects/packages/boost-core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "Core functionality for boost and relevant packages to depend on",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {},
"require": {
"php": ">=7.0"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
"automattic/jetpack-changelogger": "@dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/boost-speed-score/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
}
},
"require": {
"php": ">=7.0",
"automattic/jetpack-boost-core": "@dev"
},
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
4 changes: 3 additions & 1 deletion projects/packages/chatbot/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "Helpful chatbots for you and your visitors",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {},
"require": {
"php": ">=7.0"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
"automattic/jetpack-changelogger": "@dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Declare requirement of PHP >= 7.4.
4 changes: 1 addition & 3 deletions projects/packages/codesniffer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"testing"
],
"require": {
"php": ">=7.4",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"mediawiki/mediawiki-codesniffer": "^41.0",
"phpcompatibility/phpcompatibility-wp": "^2.1",
Expand All @@ -35,9 +36,6 @@
"phpunit": [
"./vendor/phpunit/phpunit/phpunit --colors=always"
],
"skip-test-php": [
"./tests/action-skip-test-php.sh"
],
"test-php": [
"@composer phpunit"
]
Expand Down
6 changes: 0 additions & 6 deletions projects/packages/codesniffer/tests/action-skip-test-php.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
4 changes: 3 additions & 1 deletion projects/packages/compat/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "Compatibility layer with previous versions of Jetpack",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {},
"require": {
"php": ">=7.0"
},
"require-dev": {
"automattic/jetpack-changelogger": "@dev"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/composer-plugin/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"i18n"
],
"require": {
"php": ">=7.0",
"composer-plugin-api": "^2.1.0"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
4 changes: 3 additions & 1 deletion projects/packages/config/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "Jetpack configuration package that initializes other packages and configures Jetpack's functionality. Can be used as a base for all variants of Jetpack package usage.",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {},
"require": {
"php": ">=7.0"
},
"require-dev": {
"automattic/jetpack-changelogger": "@dev"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/connection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.0",
"automattic/jetpack-a8c-mc-stats": "@dev",
"automattic/jetpack-admin-ui": "@dev",
"automattic/jetpack-constants": "@dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
4 changes: 3 additions & 1 deletion projects/packages/constants/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "A wrapper for defining constants in a more testable way.",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {},
"require": {
"php": ">=7.0"
},
"require-dev": {
"brain/monkey": "2.6.1",
"yoast/phpunit-polyfills": "1.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
4 changes: 3 additions & 1 deletion projects/packages/device-detection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "A way to detect device types based on User-Agent header.",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {},
"require": {
"php": ">=7.0"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
"automattic/jetpack-changelogger": "@dev"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
4 changes: 3 additions & 1 deletion projects/packages/error/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "Jetpack Error - a wrapper around WP_Error.",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {},
"require": {
"php": ">=7.0"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
"automattic/jetpack-changelogger": "@dev"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/forms/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.0",
"automattic/jetpack-blocks": "@dev",
"automattic/jetpack-assets": "@dev",
"automattic/jetpack-connection": "@dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
4 changes: 3 additions & 1 deletion projects/packages/google-fonts-provider/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"description": "WordPress Webfonts provider for Google Fonts",
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {},
"require": {
"php": ">=7.0"
},
"require-dev": {
"yoast/phpunit-polyfills": "1.1.0",
"automattic/jetpack-changelogger": "@dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: changed

The package now requires PHP >= 7.0.
1 change: 1 addition & 0 deletions projects/packages/heartbeat/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"type": "jetpack-library",
"license": "GPL-2.0-or-later",
"require": {
"php": ">=7.0",
"automattic/jetpack-connection": "@dev"
},
"require-dev": {
Expand Down
Loading

0 comments on commit f2c1bcb

Please sign in to comment.