Skip to content

Commit

Permalink
Declare PHP version requirement in all Composer packages (#34192)
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 authored Nov 20, 2023
1 parent 9a9987b commit 3815717
Show file tree
Hide file tree
Showing 192 changed files with 1,599 additions and 772 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
18 changes: 10 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.
6 changes: 4 additions & 2 deletions 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 Expand Up @@ -42,7 +44,7 @@
"link-template": "https://github.com/Automattic/jetpack-a8c-mc-stats/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.4.x-dev"
"dev-trunk": "2.0.x-dev"
}
}
}
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.
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -48,7 +49,7 @@
"link-template": "https://github.com/Automattic/jetpack-abtest/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.10.x-dev"
"dev-trunk": "2.0.x-dev"
}
},
"config": {
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.
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -54,7 +55,7 @@
},
"autotagger": true,
"branch-alias": {
"dev-trunk": "0.1.x-dev"
"dev-trunk": "0.2.x-dev"
},
"textdomain": "jetpack-action-bar"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/action-bar/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-action-bar",
"version": "0.1.33-alpha",
"version": "0.2.0-alpha",
"description": "An easy way for visitors to follow, like, and comment on your WordPress site.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/action-bar/#readme",
"bugs": {
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.
6 changes: 4 additions & 2 deletions 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 Expand Up @@ -47,7 +49,7 @@
"link-template": "https://github.com/Automattic/jetpack-admin-ui/compare/${old}...${new}"
},
"branch-alias": {
"dev-trunk": "0.2.x-dev"
"dev-trunk": "0.3.x-dev"
},
"version-constants": {
"::PACKAGE_VERSION": "src/class-admin-menu.php"
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/admin-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-admin-ui",
"version": "0.2.26-alpha",
"version": "0.3.0-alpha",
"description": "Generic Jetpack wp-admin UI elements",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/admin-ui/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/admin-ui/src/class-admin-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
class Admin_Menu {

const PACKAGE_VERSION = '0.2.26-alpha';
const PACKAGE_VERSION = '0.3.0-alpha';

/**
* Whether this class has been initialized
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.
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -49,7 +50,7 @@
"link-template": "https://github.com/Automattic/jetpack-analyzer/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.7.x-dev"
"dev-trunk": "2.0.x-dev"
}
}
}
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.
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -59,7 +60,7 @@
"link-template": "https://github.com/Automattic/jetpack-assets/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.18.x-dev"
"dev-trunk": "2.0.x-dev"
}
}
}
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.
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -56,7 +57,7 @@
"::VERSION": "src/AutoloadGenerator.php"
},
"branch-alias": {
"dev-trunk": "2.12.x-dev"
"dev-trunk": "3.0.x-dev"
}
}
}
2 changes: 1 addition & 1 deletion projects/packages/autoloader/src/AutoloadGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class AutoloadGenerator {

const VERSION = '2.12.0';
const VERSION = '3.0.0-alpha';

/**
* IO object.
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.
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -75,7 +76,7 @@
"link-template": "https://github.com/Automattic/jetpack-backup/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.17.x-dev"
"dev-trunk": "2.0.x-dev"
}
},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/backup/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '1.17.13-alpha';
const PACKAGE_VERSION = '2.0.0-alpha';

const PACKAGE_SLUG = 'backup';

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.
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -63,7 +64,7 @@
"link-template": "https://github.com/automattic/jetpack-blaze/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "0.12.x-dev"
"dev-trunk": "0.13.x-dev"
},
"textdomain": "jetpack-blaze",
"version-constants": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/blaze/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@automattic/jetpack-blaze",
"version": "0.12.4-alpha",
"version": "0.13.0-alpha",
"description": "Attract high-quality traffic to your site using Blaze. Using this service, you can advertise a post or page on some of the millions of pages across WordPress.com and Tumblr from just $5 per day.",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/packages/blaze/#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion projects/packages/blaze/src/class-dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Dashboard {
*
* @var string
*/
const PACKAGE_VERSION = '0.12.4-alpha';
const PACKAGE_VERSION = '0.13.0-alpha';

/**
* List of dependencies needed to render the dashboard in wp-admin.
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.
3 changes: 2 additions & 1 deletion 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 Expand Up @@ -48,7 +49,7 @@
"link-template": "https://github.com/Automattic/jetpack-blocks/compare/v${old}...v${new}"
},
"branch-alias": {
"dev-trunk": "1.6.x-dev"
"dev-trunk": "2.0.x-dev"
}
},
"config": {
Expand Down
Loading

0 comments on commit 3815717

Please sign in to comment.