Skip to content

Commit

Permalink
Merge pull request #37737 from Automattic/add/converge-wpcomsh
Browse files Browse the repository at this point in the history
Introducing wpcom site helper plugin into the Monorepo.
  • Loading branch information
zinigor authored Jun 12, 2024
2 parents a195694 + 0d115b7 commit 68d1ce7
Show file tree
Hide file tree
Showing 493 changed files with 313,890 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .github/files/generate-ci-matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
'with-woocommerce' => true,
);

/**
* Here is the place where wpcomsh tests would be introduced by adding 'with-wpcomsh' property set to true.
* This adds a new run into the matrix that would enable wpcomsh loading with unit tests.
*/

// Add JS tests.
$matrix[] = array(
'name' => 'JS tests',
Expand Down
10 changes: 10 additions & 0 deletions .github/files/setup-wordpress-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ if [[ "$WITH_WOOCOMMERCE" == true ]]; then
echo "::endgroup::"
fi

# Install the wpcomsh plugin used for some Jetpack integration tests.
if [[ "$WITH_WPCOMSH" == true ]]; then
echo "::group::Installing wpcomsh into WordPress"

mkdir "/tmp/wordpress-$WP_BRANCH/src/wp-content/mu-plugins"
cp -r "/tmp/wordpress-$WP_BRANCH/src/wp-content/plugins/wpcomsh" "/tmp/wordpress-$WP_BRANCH/src/wp-content/mu-plugins/wpcomsh"

echo "::endgroup::"
fi

cd "/tmp/wordpress-$WP_BRANCH"

cp wp-tests-config-sample.php wp-tests-config.php
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
NODE_VERSION: ${{ matrix.node }}
MONOREPO_BASE: ${{ github.workspace }}
WITH_WOOCOMMERCE: ${{ matrix.with-woocommerce }}
WITH_WPCOMSH: ${{ matrix.with-wpcomsh }}
strategy:
fail-fast: false
matrix:
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions projects/plugins/jetpack/.phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
__DIR__ . '/../../../plugins/crm/includes/ZeroBSCRM.Core.Extensions.php', // functions zeroBSCRM_isExtensionInstalled, zeroBSCRM_extension_install_jetpackforms

// Make an exception to the above for packages/jetpack-mu-wpcom. Pulling in that whole package here seems more risky than beneficial.
__DIR__ . '/../../../packages/jetpack-mu-wpcom/src/class-jetpack-mu-wpcom.php', // class Jetpack_Mu_Wpcom
__DIR__ . '/../../../packages/jetpack-mu-wpcom/src/features/launchpad/launchpad.php', // function wpcom_launchpad_is_fse_next_steps_modal_hidden
),
)
Expand Down
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/changelog/try-wpcomsh-skeleton-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Added ability to test Jetpack together with wpcomsh.
4 changes: 4 additions & 0 deletions projects/plugins/jetpack/tests/action-test-php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ if [[ "$WITH_WOOCOMMERCE" == true ]]; then
exit 0
fi

if [[ "$WITH_WPCOMSH" == true ]]; then
export JETPACK_TEST_WPCOMSH=1
fi

echo "::group::Jetpack tests"
phpunit
echo "::endgroup::"
Expand Down
33 changes: 33 additions & 0 deletions projects/plugins/jetpack/tests/php/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
echo "Disregard Core's -c tests/phpunit/multisite.xml notice below." . PHP_EOL;
}

if ( '1' !== getenv( 'JETPACK_TEST_WPCOMSH' ) ) {
echo 'To run tests with the WordPress.com Site Helper plugin activated and Atomic mode enabled,' . PHP_EOL;
echo 'prefix phpunit with JETPACK_TEST_WPCOMSH=1' . PHP_EOL;
}

if ( '1' !== getenv( 'JETPACK_TEST_WOOCOMMERCE' ) ) {
echo 'To run Jetpack woocommerce tests, prefix phpunit with JETPACK_TEST_WOOCOMMERCE=1' . PHP_EOL;
} else {
Expand All @@ -101,6 +106,7 @@ function _manually_load_plugin() {
if ( '1' === getenv( 'JETPACK_TEST_WOOCOMMERCE' ) ) {
require JETPACK_WOOCOMMERCE_INSTALL_DIR . '/woocommerce.php';
}

require __DIR__ . '/../../jetpack.php';
$jetpack = Jetpack::init();
$jetpack->configure();
Expand All @@ -120,9 +126,36 @@ function _manually_install_woocommerce() {
echo 'Installing WooCommerce...' . PHP_EOL;
}

/**
* Loading required mu-wpcom plugin files to be able to test with all required code.
*/
function _manually_load_muplugin() {
if ( getenv( 'GITHUB_ACTIONS' ) ) {

// Using plugin code installed by .github/files/setup-wordpress-env.sh.
require_once __DIR__ . '/../../../../mu-plugins/wpcomsh/wpcomsh.php';
require_once __DIR__ . '/../../../../mu-plugins/wpcomsh/vendor/autoload.php';
} else {
require_once __DIR__ . '/../../../wpcomsh/wpcomsh.php';
require_once __DIR__ . '/../../../wpcomsh/vendor/autoload.php';
}
\Automattic\Jetpack\Jetpack_Mu_Wpcom::init();

defined( 'WPCOMSH_PREMIUM_THEMES_PATH' ) || define( 'WPCOMSH_PREMIUM_THEMES_PATH', sys_get_temp_dir() . '/premium' );
if ( ! is_dir( WPCOMSH_PREMIUM_THEMES_PATH ) ) {
mkdir( WPCOMSH_PREMIUM_THEMES_PATH, 0777 );
}
}

// If we are running the uninstall tests don't load jetpack.
if ( ! ( in_running_uninstall_group() ) ) {
tests_add_filter( 'plugins_loaded', '_manually_load_plugin', 1 );

if ( '1' === getenv( 'JETPACK_TEST_WPCOMSH' ) ) {
define( 'IS_ATOMIC', true );
tests_add_filter( 'muplugins_loaded', '_manually_load_muplugin' );
}

if ( '1' === getenv( 'JETPACK_TEST_WOOCOMMERCE' ) ) {
tests_add_filter( 'setup_theme', '_manually_install_woocommerce' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* @package Jetpack
*/

if ( class_exists( 'WPCOM_Features' ) ) {
return;
}

/**
* Class WPCOM_Features.
*/
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/tests/php/lib/mock-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function has_blog_sticker( $sticker ) {
function wp_cache_is_enabled() {}
}

if ( ! function_exists( 'wpcom_site_has_feature' ) ) {
if ( ! function_exists( 'wpcom_site_has_feature' ) && false === getenv( 'JETPACK_TEST_WPCOMSH' ) ) {
/**
* Mock feature support.
*
Expand Down
95 changes: 95 additions & 0 deletions projects/plugins/wpcomsh/.circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
workflows:
version: 2
main:
jobs:
- php74-build
- php80-build
- php81-build
- public-access
- private-access

version: 2

job-references:
mariadb_image: &mariadb_image
cimg/mariadb:10.11

setup_environment: &setup_environment
name: "Setup Environment Variables"
command: |
echo "export PATH=$HOME/.composer/vendor/bin:$PATH" >> $BASH_ENV
source /home/circleci/.bashrc
install_dependencies: &install_dependencies
name: "Install Dependencies"
command: |
sudo apt-get update && sudo apt-get install subversion mariadb-client rsync
php_job: &php_job
environment:
- WP_TESTS_DIR: "/tmp/wordpress-tests-lib"
- WP_CORE_DIR: "/tmp/wordpress/"
steps:
- checkout
- run: *setup_environment
- run: *install_dependencies
- run:
name: "Run Tests"
command: |
composer global require "phpunit/phpunit=^9.6" --ignore-platform-reqs --dev
composer global require "yoast/phpunit-polyfills" --ignore-platform-reqs --dev
rm -rf $WP_TESTS_DIR $WP_CORE_DIR
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
echo "Building wpcomsh"
make build
echo "php -l the build/"
find build/ -name "*.php" | xargs -I X php -l X
echo "Copying build to mu-plugins"
mkdir -p ${WP_CORE_DIR}wp-content/mu-plugins/
cp -r ./build/wpcomsh ${WP_CORE_DIR}wp-content/mu-plugins/
echo "Linking the wpcomsh-loader.php file into mu-plugins";
ln -s ${WP_CORE_DIR}wp-content/mu-plugins/wpcomsh/wpcomsh-loader.php ${WP_CORE_DIR}wp-content/mu-plugins/wpcomsh-loader.php
mysql -uroot --protocol=tcp -e "ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password AS '';"
phpunit
WP_MULTISITE=1 phpunit
jobs:
php74-build:
<<: *php_job
docker:
- image: cimg/php:7.4
- image: *mariadb_image

php80-build:
<<: *php_job
docker:
- image: cimg/php:8.0
- image: *mariadb_image

php81-build:
<<: *php_job
docker:
- image: cimg/php:8.1
- image: *mariadb_image

public-access:
docker:
- image: circleci/buildpack-deps:buster
steps:
- run: sudo su -c "apt-get update && apt-get -y upgrade && apt-get -y install composer rsync"
- run: php -v
- add_ssh_keys
- checkout
- setup_remote_docker
- run: make test-public-access

private-access:
docker:
- image: circleci/buildpack-deps:buster
steps:
- run: sudo su -c "apt-get update && apt-get -y upgrade && apt-get -y install composer rsync"
- run: php -v
- add_ssh_keys
- checkout
- setup_remote_docker
- run: make test-private-access
1 change: 1 addition & 0 deletions projects/plugins/wpcomsh/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
29 changes: 29 additions & 0 deletions projects/plugins/wpcomsh/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const loadIgnorePatterns = require( 'jetpack-js-tools/load-eslint-ignore.js' );

module.exports = {
root: true,
extends: [
require.resolve( 'jetpack-js-tools/eslintrc/jest' ),
require.resolve( 'jetpack-js-tools/eslintrc/prettier' ),
],
ignorePatterns: loadIgnorePatterns( __dirname ),
overrides: [],
env: {
browser: true,
jest: true,
node: true,
},
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
globals: {},
settings: {},
rules: {
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/prefer-to-have-length': 'warn',
'jest/valid-expect': 'error',
},
};
50 changes: 50 additions & 0 deletions projects/plugins/wpcomsh/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Files not needed to be distributed in the package.
.gitattributes export-ignore
.github/ export-ignore
package.json export-ignore

# Files to include in the mirror repo, but excluded via gitignore
# Remember to end all directories with `/**` to properly tag every file.
# /src/js/example.min.js production-include
# Files to include in Automattic/wpcom-site-helper
/vendor/** production-include
/vendor/autoload.php production-include
/vendor/automattic/** production-include
/vendor/composer/** production-include
/vendor/tubalmartin/** production-include

# Files to exclude from the mirror repo, but included in the monorepo.
# Remember to end all directories with `/**` to properly tag every file.
.eslintignore production-exclude
.dockerignore production-exclude
.editorconfig production-exclude
composer.lock production-exclude
/.circleci/** production-exclude
/.gitignore production-exclude
/.phpcsignore production-exclude
/.phpcs.dir.xml production-exclude
/.phpcs.dir.phpcompatibility.xml production-exclude
/changelog/** production-exclude
/jetpack_vendor/automattic/**/README.md production-exclude
/jetpack_vendor/automattic/**/src/css/*.scss production-exclude
/jetpack_vendor/automattic/**/composer.json production-exclude
/node_modules/** production-exclude
/phpunit.xml.dist production-exclude
/README.md production-exclude
/vendor/automattic/**/src/css/*.scss production-exclude
/vendor/automattic/**/composer.json production-exclude
/vendor/automattic/jetpack-autoloader/** production-exclude
/vendor/automattic/jetpack-changelogger/** production-exclude
/vendor/automattic/jetpack-composer-plugin/** production-exclude
/vendor/**/.git* production-exclude
/vendor/**/.git*/** production-exclude
/vendor/**/*.md production-exclude
**/*.md production-exclude
/bin/** production-exclude
/build/** production-exclude
/tests/** production-exclude
/.circleci/** production-exclude
.*ntrc production-exclude
Makefile production-exclude
*.mdown production-exclude
error_log production-exclude
43 changes: 43 additions & 0 deletions projects/plugins/wpcomsh/.github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: PHP Lint

on: pull_request

jobs:
phpcs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Check existence of composer.json & phpcs.xml.dist files
id: check_files
uses: andstor/file-existence-action@v2
with:
files: "composer.json, phpcs.xml.dist"

- name: Set up PHP environment
if: steps.check_files.outputs.files_exists == 'true'
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
tools: cs2pr
env:
COMPOSER_TOKEN: ${{ secrets.REPO_GITHUB_TOKEN }}

- name: Install Composer dependencies & cache dependencies
if: steps.check_files.outputs.files_exists == 'true'
uses: "ramsey/composer-install@v2"
env:
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Detect coding standard violations (Expand for details)
# continue-on-error: true
run: composer phpcs --report-full --report-checkstyle=./phpcs-report.xml

- name: Show coding standard violations in PR (Expand above section for details)
run: cs2pr --graceful-warnings ./phpcs-report.xml
Loading

0 comments on commit 68d1ce7

Please sign in to comment.