Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into update/module-scss
Browse files Browse the repository at this point in the history
  • Loading branch information
haqadn committed Jan 31, 2025
2 parents f03525d + 4a02ca9 commit c3c4346
Show file tree
Hide file tree
Showing 565 changed files with 9,876 additions and 5,919 deletions.
85 changes: 85 additions & 0 deletions .github/files/coverage-munger/upload-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
## Environment used by this script:
#
# Required:
# - API_TOKEN_GITHUB: GitHub API token.
# - GITHUB_API_URL: GitHub API URL.
# - GITHUB_TOKEN: GitHub API token.
# - GITHUB_REPOSITORY: GitHub repo.
# - GITHUB_SHA: Commit SHA.
# - PR_HEAD: SHA for the PR head commit (versus GITHUB_SHA which is a merge commit)
# - PR_ID: PR number or "trunk".
# - SECRET: Shared secret.
# - STATUS: Status of the coverage run.

set -eo pipefail

Expand Down Expand Up @@ -95,3 +101,82 @@ done
do_req "op=finish&token=$TOKEN"
TOKEN=
echo '::endgroup::'

if [[ "$PR_ID" != "trunk" ]]; then
echo "::group::Setting GitHub status"
if jq -e '.covinfo' <<<"$JSON" &>/dev/null; then
JSON=$( jq '.covinfo' <<<"$JSON" )
if [[ "$STATUS" != 'success' ]]; then
JSON=$( jq '.state |= "pending" | .description |= "Waiting for tests to pass" | .msg |= "Cannot generate coverage summary while tests are failing. :zipper_mouth_face:\n\nPlease fix the tests, or re-run the Code coverage job if it was something being flaky."' <<<"$JSON" )
fi
else
JSON='{"state":"error","description":"No covinfo received from server","msg":"","footer":""}'
fi
jq . <<<"$JSON"
curl -v -L --fail \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/statuses/$( jq --arg V "$PR_HEAD" -nr '$V | @uri' )" \
--header "authorization: Bearer $API_TOKEN_GITHUB" \
--header 'content-type: application/json' \
--data "$( jq -c --arg PR "$PR_ID" '{
context: "Code coverage requirement",
state: .state,
target_url: "https://jetpackcodecoverage.atomicsites.blog/prs/\( $PR | @uri )/",
description: .description,
}' <<<"$JSON" )"
echo "::endgroup::"

# Find the last comment starting with "### Code Coverage Summary"
echo "::group::Looking for existing comment"
PAGE=1
while true; do
J=$( curl -v -L fail \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/issues/${ID}/comments?per_page=100&page=$PAGE" \
--header "authorization: Bearer $API_TOKEN_GITHUB"
)
CID=$( jq -r --arg CID "$CID" '[ { id: $CID }, ( .[] | select( .user.login == "github-actions[bot]" ) | select( .body | test( "^### Code Coverage Summary" ) ) ) ] | last | .id' <<<"$J" )
if jq -e 'length < 100' <<<"$J" &>/dev/null; then
break
fi
PAGE=$(( PAGE + 1 ))
done
echo "::endgroup::"
if [[ -n "$CID" ]]; then
echo "Existing comment ID=$CID"
else
echo "No existing comment found"
fi

if jq -e '.msg != ""' <<<"$JSON" &>/dev/null; then
if [[ -n "$CID" ]]; then
echo "::group::Updating comment"
curl -v -L --fail \
-X PATCH \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/issues/comments/${CID}" \
--header "authorization: Bearer $API_TOKEN_GITHUB" \
--header 'content-type: application/json' \
--data "$( jq -c '{
body: "### Code Coverage Summary\n\n\( .msg )\n\n\( .footer )",
}' <<<"$JSON" )"
echo "::endgroup::"
else
echo "::group::Creating comment"
curl -v -L --fail \
-X POST \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/issues/${ID}/comments" \
--header "authorization: Bearer $API_TOKEN_GITHUB" \
--header 'content-type: application/json' \
--data "$( jq -c '{
body: "### Code Coverage Summary\n\n\( .msg )\n\n\( .footer )",
}' <<<"$JSON" )"
echo "::endgroup::"
fi
elif [[ -n "$CID" ]]; then
# No message, delete existing comment.
echo "::group::Deleting comment"
curl -v -L --fail \
-X DELETE \
--url "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/issues/comments/${CID}" \
--header "authorization: Bearer $API_TOKEN_GITHUB"
echo "::endgroup::"
fi
fi
13 changes: 12 additions & 1 deletion .github/files/renovate-post-upgrade-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@ if [[ ! -e /tmp/dummy-log/xdebug_remote.log ]]; then
fi

docker pull --quiet ghcr.io/automattic/jetpack-wordpress-dev:latest
docker run --rm --workdir "$PWD" --user $EUID --volume /tmp/:/tmp/ --volume /tmp/dummy-log:/var/log/php ghcr.io/automattic/jetpack-wordpress-dev:latest /tmp/monorepo/.github/files/renovate-post-upgrade.sh "$@"

# Work around https://github.com/fabiospampinato/atomically/issues/13 by extracting /etc/passwd from the container and appending the entry for $EUID to it.
TMPFILE=$( mktemp )
function cleanup {
rm -f "$TMPFILE"
}
trap cleanup exit
chmod 0644 "$TMPFILE"
docker run --rm ghcr.io/automattic/jetpack-wordpress-dev:latest cat /etc/passwd > "$TMPFILE"
getent passwd $EUID >> "$TMPFILE"

docker run --rm --workdir "$PWD" --user $EUID --volume "$TMPFILE":/etc/passwd --volume /tmp/:/tmp/ --volume /tmp/dummy-log:/var/log/php ghcr.io/automattic/jetpack-wordpress-dev:latest /tmp/monorepo/.github/files/renovate-post-upgrade.sh "$@"
19 changes: 6 additions & 13 deletions .github/files/setup-wordpress-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ git clone --depth=1 --branch "$WORDPRESS_TAG" git://develop.git.wordpress.org/ "
# We need a built version of WordPress to test against, so download that into the src directory instead of what's in wordpress-develop.
rm -rf "/tmp/wordpress-$WP_BRANCH/src"
git clone --depth=1 --branch "$WORDPRESS_TAG" git://core.git.wordpress.org/ "/tmp/wordpress-$WP_BRANCH/src"

echo "::group::Setting up WordPress uploads directory"
mkdir -p "/tmp/wordpress-$WP_BRANCH/src/wp-content/uploads"
chmod -R 777 "/tmp/wordpress-$WP_BRANCH/src/wp-content/uploads"
echo "::endgroup::"

echo "::endgroup::"

if [[ -n "$GITHUB_ENV" ]]; then
Expand Down Expand Up @@ -105,19 +111,6 @@ for PLUGIN in projects/plugins/*/composer.json; do
fi
cd "$BASE"

# Upgrade/downgrade WorDBless if necessary.
if [[ ( "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ) && "$TEST_SCRIPT" == "test-php" ]]; then
VER=$(composer --format=json --working-dir="$DIR" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
if [[ -n "$VER" ]]; then
INSVER=$WORDPRESS_TAG
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
rm -rf "$DIR/wordpress"
composer --working-dir="$DIR" require --dev roots/wordpress="$INSVER" roots/wordpress-no-content="$INSVER"
fi
fi

cp -r "$DIR" "/tmp/wordpress-$WP_BRANCH/src/wp-content/plugins/$NAME"
# Plugin dir for tests in WP >= 5.6-beta1
ln -s "/tmp/wordpress-$WP_BRANCH/src/wp-content/plugins/$NAME" "/tmp/wordpress-$WP_BRANCH/tests/phpunit/data/plugins/$NAME"
Expand Down
62 changes: 41 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
# Note matrix-job outputs are kind of weird. Last-to-run job that sets a non-empty value wins.
outputs:
did-coverage: ${{ ( steps.run-tests.conclusion != 'cancelled' && steps.process-coverage.conclusion == 'success' && steps.upload-artifacts.conclusion == 'success' ) && 'true' || '' }}
coverage-status: ${{ matrix.script == 'test-coverage' && steps.run-tests.conclusion || '' }}

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -85,14 +86,6 @@ jobs:
pnpm install
echo "::endgroup::"
# If we're going to be making WorDBless use WP "nightlies", remove the relevant package from Composer's cache to get the latest version.
if [[ "$WP_BRANCH" == 'trunk' && ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) ]]; then
echo "::group::Clear composer cache for roots/wordpress"
DIR=$(composer config cache-files-dir)
rm -rf "$DIR/roots/wordpress" "$DIR/roots/wordpress-no-content"
echo "::endgroup::"
fi
- name: Detect changed projects
id: changed
run: |
Expand All @@ -109,9 +102,45 @@ jobs:
echo "any-plugins=${ANY_PLUGINS}" >> "$GITHUB_OUTPUT"
- name: Select WordPress version
if: steps.changed.outputs.any-plugins != 'true' && matrix.wp != 'none'
if: matrix.wp != 'none'
run: .github/files/select-wordpress-tag.sh

- name: Composer Install
run: |
# If we're going to be making WorDBless use WP "nightlies", remove the relevant package from Composer's cache to get the latest version.
if [[ "$WP_BRANCH" == 'trunk' && ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) ]]; then
echo "::group::Clear composer cache for roots/wordpress"
DIR=$(composer config cache-files-dir)
rm -rf "$DIR/roots/wordpress" "$DIR/roots/wordpress-no-content"
echo "::endgroup::"
fi
echo "::group::Composer"
composer install --working-dir=tools/php-test-env
# Add WorDBless for various package tests that use uploads since concurrency can nuke uploads that are in use.
# @todo Update WorDBless to be able to use a customized upload dir, do that, and remove this.
if [[ "$TEST_SCRIPT" =~ ^test-(php|coverage)$ ]]; then
VER=$( jq -r '.require["automattic/wordbless"]' tools/php-test-env/composer.json )
for pkg in packages/image-cdn packages/publicize packages/videopress; do
echo "Adding WordBless for $pkg tests"
composer require --working-dir="projects/$pkg" "automattic/wordbless:$VER" --dev --no-update
done
fi
if [[ ( "$TEST_SCRIPT" == "test-php" || "$TEST_SCRIPT" == "test-coverage" ) && ( "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ) ]]; then
VER=$(composer --format=json --working-dir="tools/php-test-env" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
if [[ -n "$VER" ]]; then
INSVER=$WORDPRESS_TAG
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
rm -rf "tools/php-test-env/wordpress"
composer --working-dir="tools/php-test-env" require --dev "roots/wordpress:$INSVER" "roots/wordpress-no-content:$INSVER"
fi
fi
echo "::endgroup::"
- name: Setup WordPress environment for plugin tests
env:
API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -195,18 +224,6 @@ jobs:
echo 'Platform reqs failed, running `composer update`'
composer --working-dir="$DIR" update
fi
if [[ "$WP_BRANCH" == 'trunk' || "$WP_BRANCH" == 'previous' ]]; then
VER=$(composer --format=json --working-dir="$DIR" show | jq -r '.installed[] | select( .name == "roots/wordpress" ) | .version')
if [[ -n "$VER" ]]; then
INSVER=$WORDPRESS_TAG
[[ "$WORDPRESS_TAG" == 'trunk' ]] && INSVER="dev-main as $VER"
echo "Supposed to run tests against WordPress $WORDPRESS_TAG, so setting roots/wordpress and roots/wordpress-no-content to \"$INSVER\""
# Composer seems to sometimes have issues with deleting the wordpress dir on its own, so do it manually first.
rm -rf "$DIR/wordpress"
composer --working-dir="$DIR" require --dev roots/wordpress="$INSVER" roots/wordpress-no-content="$INSVER"
fi
fi
fi
fi
Expand Down Expand Up @@ -305,6 +322,9 @@ jobs:
env:
PR_ID: ${{ github.event_name != 'pull_request' && 'trunk' || github.event.pull_request.number }}
SECRET: ${{ secrets.CODECOV_SECRET }}
STATUS: ${{ needs.run-tests.outputs.coverage-status }}
PR_HEAD: ${{ github.event.pull_request.head.sha }}
API_TOKEN_GITHUB: ${{ secrets.GITHUB_TOKEN }}
run: .github/files/coverage-munger/upload-coverage.sh

storybook-test:
Expand Down
22 changes: 22 additions & 0 deletions .phan/config.base.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ function make_phan_config( $dir, $options = array() ) {
case 'full-site-editing':
$stubs[] = "$root/.phan/stubs/full-site-editing-stubs.php";
break;
case 'gutenberg':
$stubs[] = "$root/.phan/stubs/gutenberg-stubs.php";
break;
case 'photon-opencv':
$stubs[] = "$root/.phan/stubs/photon-opencv-stubs.php";
break;
Expand Down Expand Up @@ -134,6 +137,25 @@ function make_phan_config( $dir, $options = array() ) {
$internal_stubs[ $stub ] = $stub_file_path;
}

// Check if test-environment is a dependency and add WorDBless if it is
$composer_json = $dir . '/composer.json';
if ( file_exists( $composer_json ) ) {
$composer_data = json_decode( file_get_contents( $composer_json ), true );
foreach ( array( 'require', 'require-dev' ) as $require_type ) {
if ( isset( $composer_data[ $require_type ]['automattic/jetpack-test-environment'] ) ) {
// Use absolute path to ensure WorDBless is found
$wordbless_path = dirname( __DIR__ ) . '/tools/php-test-env/vendor/automattic/wordbless';
if ( is_dir( $wordbless_path ) ) {
// Only include the src directory
$options['directory_list'][] = $wordbless_path . '/src';
// Exclude from analysis
$options['exclude_analysis_directory_list'][] = $wordbless_path;
}
break;
}
}
}

$config = array(
// Apparently this is only useful when upgrading from php 5, not for 7-to-8.
'backward_compatibility_checks' => false,
Expand Down
2 changes: 2 additions & 0 deletions .phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
// Ignore stuff in various subdirs too.
'.*/node_modules/',
'tools/docker/',
'tools/php-test-env/wordpress/',
'tools/php-test-env/vendor/',
// Don't load the stubs. (if we need to start loading _a_ stub for the "monorepo", do like `(?!filename\.php)` to exclude it from the exclusion.)
'.phan/stubs/',
),
Expand Down
40 changes: 40 additions & 0 deletions .phan/stubs/gutenberg-stubs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Stubs automatically generated from Gutenberg 20.1.0
* using the definition file `tools/stubs/gutenberg-stub-defs.php` in the Jetpack monorepo.
*
* Do not edit this directly! Run tools/stubs/update-stubs.sh to regenerate it.
*/

/**
* Retrieves the root plugin path.
*
* @since 0.1.0
*
* @return string Root path to the gutenberg plugin.
*/
function gutenberg_dir_path()
{
}
/**
* Registers a script according to `wp_register_script`. Honors this request by
* reassigning internal dependency properties of any script handle already
* registered by that name. It does not deregister the original script, to
* avoid losing inline scripts which may have been attached.
*
* @since 4.1.0
*
* @param WP_Scripts $scripts WP_Scripts instance.
* @param string $handle Name of the script. Should be unique.
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
* @param array $deps Optional. An array of registered script handles this script depends on. Default empty array.
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
* as a query string for cache busting purposes. If version is set to false, a version
* number is automatically added equal to current installed WordPress version.
* If set to null, no version is added.
* @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
* Default 'false'.
*/
function gutenberg_override_script($scripts, $handle, $src, $deps = array(), $ver = \false, $in_footer = \false)
{
}
18 changes: 17 additions & 1 deletion .phan/stubs/wpcom-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* `bin/teamcity-builds/jetpack-stubs/stub-defs.php` and regenerate the stubs
* by triggering the Jetpack Staging → Update WPCOM Stubs job in TeamCity.
*
* Stubs automatically generated from WordPress.com commit 8455d799e19d81bab955e52ecf72bcda5d4e6e34.
* Stubs automatically generated from WordPress.com commit 58daa278d1c6807cf18400dee1d9f45815e24fae.
*/

namespace {
Expand Down Expand Up @@ -1289,6 +1289,12 @@ public static function is_enabled(string $feature): bool
{
}
}
/**
* @phan-return mixed
*/
function is_graylisted($_blog_id = \NULL)
{
}
/**
* @param string $new_path
* @param string $path
Expand Down Expand Up @@ -1518,6 +1524,16 @@ function get_blog_subscriptions_aggregate_count(int $blog_id = null, $post_term_
{
}
}
namespace WPCOM\Experiments\Internal {
/**
* @param string $name
* @return \WPCOM\Experiments\Models\Experiment|null
* @throws File_Cache_Failure
*/
function get_cached_experiment_by_name(string $name): ?\WPCOM\Experiments\Models\Experiment
{
}
}
namespace WPCOM\Jetpack_AI {
class Feature_Control
{
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
],
"test-js": [
"cd tools/cli && pnpm test"
],
"post-install-cmd": [
"cd tools/php-test-env && composer install"
],
"post-update-cmd": [
"cd tools/php-test-env && composer update"
]
},
"scripts-descriptions": {
Expand Down
Loading

0 comments on commit c3c4346

Please sign in to comment.