From 3a57a51c3b0509607a1326ec6d03eafddd85afcc Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Thu, 5 Sep 2024 20:56:09 +0300 Subject: [PATCH 01/29] Added a CI job for WPCloud testing of wpcomsh. --- .github/workflows/wpcloud.yml | 95 +++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .github/workflows/wpcloud.yml diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml new file mode 100644 index 0000000000000..7b8ce692517a8 --- /dev/null +++ b/.github/workflows/wpcloud.yml @@ -0,0 +1,95 @@ +name: WPCloud Unit Testing for WPCOMSH + +on: + pull_request: + push: + branches: ['trunk', '*/branch-*'] +concurrency: + group: wpcloud-${{ github.event_name }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + deploy: + name: Run phpunit on WPCloud site + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + # codecov.io requires a fetch depth > 1. + fetch-depth: 2 + + # For pull requests, list-changed-projects.sh needs the merge base. + # But it doesn't have to be checked out. + - name: Deepen to merge base + if: github.event_name == 'pull_request' + uses: ./.github/actions/deepen-to-merge-base + with: + checkout: false + + - name: Detect if wpcomsh has changed + id: changed + run: | + CHANGED="$(EXTRA=test .github/files/list-changed-projects.sh)" + + WPCOMSH_CHANGED="$(jq --argjson changed "$CHANGED" -n '$changed | has( "plugins/wpcomsh" ) ')" + echo "wpcomsh=${WPCOMSH_CHANGED}" >> "$GITHUB_OUTPUT" + + - name: Configure Github to be able to SSH to the Atomic site + if: steps.changed.outputs.wpcomsh == 'true' + run: | + echo "Intializing" + echo "::group::setup" + + mkdir -vp ~/.ssh/ + chmod -v 700 ~/.ssh + + touch ~/.ssh/id_site + chmod 600 ~/.ssh/id_site + echo "$WPCLOUD_SSH_KEY" > ~/.ssh/id_site + echo "wrote ~/.ssh/id_site" + + touch ~/.ssh/askpass + chmod -v 700 ~/.ssh/askpass + cat >>~/.ssh/askpass <>~/.ssh/config <>~/.ssh/stdin < Date: Thu, 5 Sep 2024 21:00:06 +0300 Subject: [PATCH 02/29] Add pnpm and install. --- .github/workflows/wpcloud.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index 7b8ce692517a8..fafba4c2d19f4 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -26,6 +26,16 @@ jobs: with: checkout: false + - name: Setup tools + uses: ./.github/actions/tool-setup + with: + php: ${{ matrix.php }} + node: ${{ matrix.node }} + - name: Monorepo install + run: | + echo "::group::Pnpm" + pnpm install + echo "::endgroup::" - name: Detect if wpcomsh has changed id: changed run: | From 0d40db9fb8ee279d6a170b76131d9e3b2374fdf4 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Mon, 7 Oct 2024 20:24:38 +0300 Subject: [PATCH 03/29] Testing WPCloud on a new test site for jetpackisbestpack. --- .github/workflows/wpcloud.yml | 43 +++++++---------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index fafba4c2d19f4..da9778e95f82e 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -54,42 +54,18 @@ jobs: chmod -v 700 ~/.ssh touch ~/.ssh/id_site + touch ~/.ssh/known_hosts chmod 600 ~/.ssh/id_site - echo "$WPCLOUD_SSH_KEY" > ~/.ssh/id_site + chmod 600 ~/.ssh/known_hosts + echo "$SSH_KEY" > ~/.ssh/id_site echo "wrote ~/.ssh/id_site" - - touch ~/.ssh/askpass - chmod -v 700 ~/.ssh/askpass - cat >>~/.ssh/askpass <>~/.ssh/config <>~/.ssh/stdin < ~/.ssh/known_hosts + echo "wrote ~/.ssh/known_hosts" echo "::endgroup::" echo "::group::execution" - cat ~/.ssh/stdin | setsid ssh -i ~/.ssh/id_site -l "$WPCLOUD_SSH_USER" ssh.atomicsites.net "$WPCLOUD_SSH_COMMAND" || CODE=$? + ssh -i ~/.ssh/id_site jetpackwpcomshtester.wordpress.com@sftp.wp.com "ls" || CODE=$? echo "::endgroup::" echo "::group::teardown" @@ -98,8 +74,5 @@ jobs: echo "Exiting with exit code $CODE" exit $CODE env: - WPCLOUD_SSH_KEY: ${{ secrets.WPCLOUD_SSH_KEY }} - WPCLOUD_SSH_KEY_PASSPHRASE: ${{ secrets.WPCLOUD_SSH_KEY_PASSPHRASE }} - WPCLOUD_SSH_USER: ${{ secrets.WPCLOUD_SSH_USER }} - WPCLOUD_SSH_COMMAND: ${{ secrets.WPCLOUD_SSH_COMMAND }} - WPCLOUD_STDIN: ${{ toJSON(github) }} + SSH_KEY: ${{ secrets.UPDATEJETPACKSTAGING_SSH_KEY }} + SSH_KNOWN_HOSTS: ${{ secrets.UPDATEJETPACKSTAGING_SSH_KNOWN_HOSTS }} From a3a5533bfaa7b7f3cb1c77f345d97772746dde9d Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Mon, 7 Oct 2024 20:34:25 +0300 Subject: [PATCH 04/29] Temporarily marking wpcomsh as always changed. --- .github/workflows/wpcloud.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index da9778e95f82e..f860d74a56484 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -41,7 +41,8 @@ jobs: run: | CHANGED="$(EXTRA=test .github/files/list-changed-projects.sh)" - WPCOMSH_CHANGED="$(jq --argjson changed "$CHANGED" -n '$changed | has( "plugins/wpcomsh" ) ')" + # WPCOMSH_CHANGED="$(jq --argjson changed "$CHANGED" -n '$changed | has( "plugins/wpcomsh" ) ')" + WPCOMSH_CHANGED="true" echo "wpcomsh=${WPCOMSH_CHANGED}" >> "$GITHUB_OUTPUT" - name: Configure Github to be able to SSH to the Atomic site From 4df8ed738fde0c9f76f739b0594477ce524e075f Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Wed, 23 Oct 2024 20:30:07 +0300 Subject: [PATCH 05/29] Added transferring of tests. --- .github/workflows/wpcloud.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index f860d74a56484..25c2104c53929 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -48,8 +48,7 @@ jobs: - name: Configure Github to be able to SSH to the Atomic site if: steps.changed.outputs.wpcomsh == 'true' run: | - echo "Intializing" - echo "::group::setup" + echo "::group::Intializing" mkdir -vp ~/.ssh/ chmod -v 700 ~/.ssh @@ -65,8 +64,16 @@ jobs: echo "::endgroup::" + echo "::group::Transferring wpcomsh to the testing server" + jetpack rsync wpcomsh jetpackwpcomshtester.wordpress.com@sftp.wp.com:~/htdocs/wp-content/mu-plugins + scp -r projects/plugins/wpcomsh/bin jetpackwpcomshtester.wordpress.com@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh + scp -r projects/plugins/wpcomsh/tests jetpackwpcomshtester.wordpress.com@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ + scp projects/plugins/wpcomsh/phpunit.xml.dist jetpackwpcomshtester.wordpress.com@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ + + echo "::engroup::" + echo "::group::execution" - ssh -i ~/.ssh/id_site jetpackwpcomshtester.wordpress.com@sftp.wp.com "ls" || CODE=$? + ssh -i ~/.ssh/id_site jetpackwpcomshtester.wordpress.com@sftp.wp.com "~/htdocs/github-action-handler.sh" || CODE=$? echo "::endgroup::" echo "::group::teardown" From b10273825c93a58e3e5d6fbd1218e48b0e13a4bc Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Wed, 23 Oct 2024 20:31:32 +0300 Subject: [PATCH 06/29] Added DB password slash escaping. --- projects/plugins/wpcomsh/bin/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/wpcomsh/bin/install-wp-tests.sh b/projects/plugins/wpcomsh/bin/install-wp-tests.sh index c401896c91322..eeed9a1d78280 100755 --- a/projects/plugins/wpcomsh/bin/install-wp-tests.sh +++ b/projects/plugins/wpcomsh/bin/install-wp-tests.sh @@ -118,7 +118,7 @@ install_test_suite() { sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/yourpasswordhere/${DB_PASS//\//\\/}/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php fi From 27bbd0745ab060ed3c24527b13da45dbe29c3e41 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Wed, 23 Oct 2024 20:31:57 +0300 Subject: [PATCH 07/29] changelog --- .../plugins/wpcomsh/changelog/add-wpcomsh-wpcloud-testing | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 projects/plugins/wpcomsh/changelog/add-wpcomsh-wpcloud-testing diff --git a/projects/plugins/wpcomsh/changelog/add-wpcomsh-wpcloud-testing b/projects/plugins/wpcomsh/changelog/add-wpcomsh-wpcloud-testing new file mode 100644 index 0000000000000..71d30adf105d7 --- /dev/null +++ b/projects/plugins/wpcomsh/changelog/add-wpcomsh-wpcloud-testing @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fixed a database password escaping issue when installing tests. From aad27e3e498a9b969cb097237be5cc9d3b77accd Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Wed, 23 Oct 2024 21:08:24 +0300 Subject: [PATCH 08/29] Added a mock for get_option_and_ensure_autoload. --- .../tests/lib/mocks/class-jetpack-options.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/projects/plugins/wpcomsh/tests/lib/mocks/class-jetpack-options.php b/projects/plugins/wpcomsh/tests/lib/mocks/class-jetpack-options.php index 61d650cd6789e..c9aa896d3780c 100644 --- a/projects/plugins/wpcomsh/tests/lib/mocks/class-jetpack-options.php +++ b/projects/plugins/wpcomsh/tests/lib/mocks/class-jetpack-options.php @@ -24,5 +24,18 @@ class Jetpack_Options { public static function get_option( $option_name, $default = false ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.defaultFound return apply_filters( 'jetpack_options', get_option( $option_name, $default ), $option_name ); } + + /** + * Returns the requested option, and ensures it's autoloaded in the future. + * This does _not_ adjust the prefix in any way (does not prefix jetpack_%) + * + * @param string $name Option name. + * @param mixed $default (optional). + * + * @return mixed + */ + public static function get_option_and_ensure_autoload( $name, $default ) { + return self::get_option( $name, $default ); + } } } From 9e892e4490fa21eb072deaa264c1ebd1297bb0c7 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Thu, 24 Oct 2024 19:14:07 +0300 Subject: [PATCH 09/29] Added a missing cache expulsion function. --- projects/plugins/wpcomsh/tests/bootstrap.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/projects/plugins/wpcomsh/tests/bootstrap.php b/projects/plugins/wpcomsh/tests/bootstrap.php index 77b36d57c08ae..ba84d780b6444 100644 --- a/projects/plugins/wpcomsh/tests/bootstrap.php +++ b/projects/plugins/wpcomsh/tests/bootstrap.php @@ -5,9 +5,10 @@ * @package wpcomsh */ -$_tests_dir = getenv( 'WP_TESTS_DIR' ); -$_core_dir = getenv( 'WP_CORE_DIR' ); -$wp_branch = getenv( 'WP_BRANCH' ); +$_tests_dir = getenv( 'WP_TESTS_DIR' ); +$_core_dir = getenv( 'WP_CORE_DIR' ); +$_wp_content_dir = getenv( 'WP_CONTENT_DIR' ) ?? $_core_dir; +$wp_branch = getenv( 'WP_BRANCH' ); if ( ! $_tests_dir ) { if ( $wp_branch ) { @@ -26,7 +27,7 @@ } define( 'IS_ATOMIC', true ); -define( 'WPMU_PLUGIN_DIR', "{$_core_dir}wp-content/mu-plugins" ); +define( 'WPMU_PLUGIN_DIR', "{$_wp_content_dir}/mu-plugins" ); if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) { echo "Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped @@ -53,5 +54,16 @@ function _manually_load_plugin() { } tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); +if ( ! function_exists( 'wp_cache_flush_runtime' ) ) { + /** + * Removes all cache items from the in-memory runtime cache. + * + * @return bool True on success, false on failure. + */ + function wp_cache_flush_runtime() { + return wp_cache_flush(); + } +} + // Start up the WP testing environment. require_once $_tests_dir . '/includes/bootstrap.php'; From dfb7439e1cbcf56426c7795c1515347c68471438 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Thu, 24 Oct 2024 19:32:12 +0300 Subject: [PATCH 10/29] Removed set -x from test installer. --- projects/plugins/wpcomsh/bin/install-wp-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/wpcomsh/bin/install-wp-tests.sh b/projects/plugins/wpcomsh/bin/install-wp-tests.sh index eeed9a1d78280..3cedfabb261f5 100755 --- a/projects/plugins/wpcomsh/bin/install-wp-tests.sh +++ b/projects/plugins/wpcomsh/bin/install-wp-tests.sh @@ -51,7 +51,7 @@ else fi WP_TESTS_TAG="tags/$LATEST_VERSION" fi -set -ex +set -e install_wp() { From bf302d542de1817f3efcc67cdbc9efa1fa79fb1e Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Thu, 24 Oct 2024 19:33:15 +0300 Subject: [PATCH 11/29] Using pnpm to not bother with linking binaries. --- .github/workflows/wpcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index 25c2104c53929..c936b9eda6cc9 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -65,7 +65,7 @@ jobs: echo "::endgroup::" echo "::group::Transferring wpcomsh to the testing server" - jetpack rsync wpcomsh jetpackwpcomshtester.wordpress.com@sftp.wp.com:~/htdocs/wp-content/mu-plugins + pnpm jetpack rsync wpcomsh jetpackwpcomshtester.wordpress.com@sftp.wp.com:~/htdocs/wp-content/mu-plugins scp -r projects/plugins/wpcomsh/bin jetpackwpcomshtester.wordpress.com@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh scp -r projects/plugins/wpcomsh/tests jetpackwpcomshtester.wordpress.com@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ scp projects/plugins/wpcomsh/phpunit.xml.dist jetpackwpcomshtester.wordpress.com@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ From 8f1f1948db8441f5028f13a7376687e9fe31e03e Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Thu, 24 Oct 2024 19:51:02 +0300 Subject: [PATCH 12/29] Added a build step. --- .github/workflows/wpcloud.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index c936b9eda6cc9..c05e6fcaf5de4 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -64,6 +64,10 @@ jobs: echo "::endgroup::" + echo "::group::Installing and building wpcomsh" + pnpm jetpack build plugins/wpcomsh + echo "::endgroup::" + echo "::group::Transferring wpcomsh to the testing server" pnpm jetpack rsync wpcomsh jetpackwpcomshtester.wordpress.com@sftp.wp.com:~/htdocs/wp-content/mu-plugins scp -r projects/plugins/wpcomsh/bin jetpackwpcomshtester.wordpress.com@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh From 3618211d9bf9c46d355b3a41b26dd8515820820a Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Fri, 25 Oct 2024 18:37:22 +0300 Subject: [PATCH 13/29] Created a separate job to avoid re-building on a re-run, h/t @anomiex. --- .github/workflows/wpcloud.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index c05e6fcaf5de4..cae020a02c8bc 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -9,8 +9,8 @@ concurrency: cancel-in-progress: true jobs: - deploy: - name: Run phpunit on WPCloud site + build: + name: Install the Monorepo and build wpcomsh runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -44,9 +44,20 @@ jobs: # WPCOMSH_CHANGED="$(jq --argjson changed "$CHANGED" -n '$changed | has( "plugins/wpcomsh" ) ')" WPCOMSH_CHANGED="true" echo "wpcomsh=${WPCOMSH_CHANGED}" >> "$GITHUB_OUTPUT" + - name: Build wpcomsh + if: steps.changed.outputs.wpcomsh == 'true' + run: | + echo "::group::Installing and building wpcomsh" + pnpm jetpack build -v --deps plugins/wpcomsh + echo "::endgroup::" + deploy: + name: Run PHPUnit on the WPCloud test site + runs-on: ubuntu-latest + needs: build + steps: - name: Configure Github to be able to SSH to the Atomic site - if: steps.changed.outputs.wpcomsh == 'true' + if: needs.build.changed.outputs.wpcomsh == 'true' run: | echo "::group::Intializing" @@ -64,10 +75,6 @@ jobs: echo "::endgroup::" - echo "::group::Installing and building wpcomsh" - pnpm jetpack build plugins/wpcomsh - echo "::endgroup::" - echo "::group::Transferring wpcomsh to the testing server" pnpm jetpack rsync wpcomsh jetpackwpcomshtester.wordpress.com@sftp.wp.com:~/htdocs/wp-content/mu-plugins scp -r projects/plugins/wpcomsh/bin jetpackwpcomshtester.wordpress.com@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh From 510482f60505caf00d468b7c3f430d5fa9541ae7 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Fri, 25 Oct 2024 19:49:07 +0300 Subject: [PATCH 14/29] Added cache saving and restoring, moved if to parent job. --- .github/workflows/wpcloud.yml | 46 ++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index cae020a02c8bc..23839cf0eb3ef 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -12,6 +12,8 @@ jobs: build: name: Install the Monorepo and build wpcomsh runs-on: ubuntu-latest + outputs: + wpcomsh: ${{ steps.changed.outputs.wpcomsh }} steps: - uses: actions/checkout@v4 with: @@ -51,13 +53,55 @@ jobs: pnpm jetpack build -v --deps plugins/wpcomsh echo "::endgroup::" + # We only want to save the files that were actually created or changed. + # But we can't just list them for actions/cache/save, "Argument list too long". + # So instead we delete all the unchanged files so we can tell actions/cache/save + # to save everything that's left. + git -c core.quotepath=off diff --name-only | sort > /tmp/changed.txt + if [[ -s /tmp/changed.txt ]]; then + grep -F -x -v -f /tmp/changed.txt /tmp/before.txt > /tmp/remove.txt + else + cp /tmp/before.txt /tmp/remove.txt + fi + xargs -d '\n' rm < /tmp/remove.txt + find . -type d -empty -delete + + - name: Save wpcomsh build cache + if: steps.changed.outputs.wpcomsh == 'true' + id: wpcomsh-build-cache-save + uses: actions/cache/save@v4 + with: + path: | + . + !./.github/ + key: ${{ github.sha }} deploy: name: Run PHPUnit on the WPCloud test site runs-on: ubuntu-latest needs: build + if: needs.build.changed.outputs.wpcomsh == 'true' steps: + - uses: actions/checkout@v4 + + - name: Restore wpcomsh build cache + id: wpcomsh-build-cache + if: needs.build.result == 'success' + uses: actions/cache/restore@v4 + with: + path: | + . + !./.github/ + key: ${{ github.sha }} + fail-on-cache-miss: true + + - name: Setup tools + uses: ./.github/actions/tool-setup + + - name: Install monorepo + run: | + pnpm install + - name: Configure Github to be able to SSH to the Atomic site - if: needs.build.changed.outputs.wpcomsh == 'true' run: | echo "::group::Intializing" From 747555d5b5974ae9095ad703e2ef41819d4ffba1 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Fri, 25 Oct 2024 19:58:27 +0300 Subject: [PATCH 15/29] Added the before file. --- .github/workflows/wpcloud.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index 23839cf0eb3ef..25d5d99831d65 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -49,6 +49,7 @@ jobs: - name: Build wpcomsh if: steps.changed.outputs.wpcomsh == 'true' run: | + find . -path ./.github -prune -o -type f -print | sort > /tmp/before.txt echo "::group::Installing and building wpcomsh" pnpm jetpack build -v --deps plugins/wpcomsh echo "::endgroup::" From cdff320311951c88eb60ba0892fd0771c0134ea1 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Fri, 25 Oct 2024 20:09:31 +0300 Subject: [PATCH 16/29] Trying with instead of . --- .github/workflows/wpcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index 25d5d99831d65..9bf99f4423236 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -80,7 +80,7 @@ jobs: name: Run PHPUnit on the WPCloud test site runs-on: ubuntu-latest needs: build - if: needs.build.changed.outputs.wpcomsh == 'true' + if: jobs.build.changed.outputs.wpcomsh == 'true' steps: - uses: actions/checkout@v4 From a60df09a4794bdc8737fa82ef79f0cb23555e305 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Fri, 25 Oct 2024 20:15:35 +0300 Subject: [PATCH 17/29] Fixing var schema. --- .github/workflows/wpcloud.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index 9bf99f4423236..e38e3a9a0f515 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -80,13 +80,12 @@ jobs: name: Run PHPUnit on the WPCloud test site runs-on: ubuntu-latest needs: build - if: jobs.build.changed.outputs.wpcomsh == 'true' + if: needs.build.outputs.wpcomsh == 'true' steps: - uses: actions/checkout@v4 - name: Restore wpcomsh build cache id: wpcomsh-build-cache - if: needs.build.result == 'success' uses: actions/cache/restore@v4 with: path: | From 3ff1beac817304b3402f735479ba6315a9adf71d Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Wed, 15 Jan 2025 18:49:28 +0300 Subject: [PATCH 18/29] Fixed the user string in SSH connection. --- .github/workflows/wpcloud.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index e38e3a9a0f515..30149e41ba08b 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -120,10 +120,10 @@ jobs: echo "::endgroup::" echo "::group::Transferring wpcomsh to the testing server" - pnpm jetpack rsync wpcomsh jetpackwpcomshtester.wordpress.com@sftp.wp.com:~/htdocs/wp-content/mu-plugins - scp -r projects/plugins/wpcomsh/bin jetpackwpcomshtester.wordpress.com@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh - scp -r projects/plugins/wpcomsh/tests jetpackwpcomshtester.wordpress.com@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ - scp projects/plugins/wpcomsh/phpunit.xml.dist jetpackwpcomshtester.wordpress.com@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ + pnpm jetpack rsync wpcomsh wpcom-jetpackisbestpack-default-237778992@sftp.wp.com:~/htdocs/wp-content/mu-plugins + scp -r projects/plugins/wpcomsh/bin wpcom-jetpackisbestpack-default-237778992@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh + scp -r projects/plugins/wpcomsh/tests wpcom-jetpackisbestpack-default-237778992@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ + scp projects/plugins/wpcomsh/phpunit.xml.dist wpcom-jetpackisbestpack-default-237778992@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ echo "::engroup::" From 131ac21cd618f134d58d685e22f2e4c114a65b5c Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Wed, 15 Jan 2025 19:14:59 +0300 Subject: [PATCH 19/29] Trying to create an SSH config file. --- .github/workflows/wpcloud.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index 30149e41ba08b..975c22579203d 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -110,16 +110,24 @@ jobs: touch ~/.ssh/id_site touch ~/.ssh/known_hosts + touch ~/.ssh/config chmod 600 ~/.ssh/id_site chmod 600 ~/.ssh/known_hosts + chmod 600 ~/.ssh/config echo "$SSH_KEY" > ~/.ssh/id_site echo "wrote ~/.ssh/id_site" echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts echo "wrote ~/.ssh/known_hosts" + echo "Host jpwpcomsh" > ~/.ssh/config + echo " Hostname sftp.wp.com" >> ~/.ssh/config + echo " User wpcom-jetpackisbestpack-default-237778992" >> ~/.ssh/config + echo " IdentityFile ~/.ssh/id_jetpackisbestpack" >> ~/.ssh/config + echo " IdentitiesOnly yes" >> ~/.ssh/config echo "::endgroup::" echo "::group::Transferring wpcomsh to the testing server" + ssh -v jpwpcomsh "exit" pnpm jetpack rsync wpcomsh wpcom-jetpackisbestpack-default-237778992@sftp.wp.com:~/htdocs/wp-content/mu-plugins scp -r projects/plugins/wpcomsh/bin wpcom-jetpackisbestpack-default-237778992@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh scp -r projects/plugins/wpcomsh/tests wpcom-jetpackisbestpack-default-237778992@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ From 6b04ffa20c33f2abe0b60860dfa1f60a4717e639 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Wed, 15 Jan 2025 19:22:36 +0300 Subject: [PATCH 20/29] Fixed the SSH key file name. --- .github/workflows/wpcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index 975c22579203d..bfbdbab1b6cb0 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -121,7 +121,7 @@ jobs: echo "Host jpwpcomsh" > ~/.ssh/config echo " Hostname sftp.wp.com" >> ~/.ssh/config echo " User wpcom-jetpackisbestpack-default-237778992" >> ~/.ssh/config - echo " IdentityFile ~/.ssh/id_jetpackisbestpack" >> ~/.ssh/config + echo " IdentityFile ~/.ssh/id_site" >> ~/.ssh/config echo " IdentitiesOnly yes" >> ~/.ssh/config echo "::endgroup::" From 738ee0b2b3b9c221a660fa14244b5e0f2b2c4502 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Wed, 15 Jan 2025 19:29:59 +0300 Subject: [PATCH 21/29] Making sure to use the preset configured host. --- .github/workflows/wpcloud.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index bfbdbab1b6cb0..6bfeeb604d708 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -127,16 +127,15 @@ jobs: echo "::endgroup::" echo "::group::Transferring wpcomsh to the testing server" - ssh -v jpwpcomsh "exit" - pnpm jetpack rsync wpcomsh wpcom-jetpackisbestpack-default-237778992@sftp.wp.com:~/htdocs/wp-content/mu-plugins - scp -r projects/plugins/wpcomsh/bin wpcom-jetpackisbestpack-default-237778992@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh - scp -r projects/plugins/wpcomsh/tests wpcom-jetpackisbestpack-default-237778992@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ - scp projects/plugins/wpcomsh/phpunit.xml.dist wpcom-jetpackisbestpack-default-237778992@sftp.wp.com:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ + pnpm jetpack rsync wpcomsh jpwpcomsh:~/htdocs/wp-content/mu-plugins + scp -r projects/plugins/wpcomsh/bin jpwpcomsh:/srv/htdocs/wp-content/mu-plugins/wpcomsh + scp -r projects/plugins/wpcomsh/tests jpwpcomsh:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ + scp projects/plugins/wpcomsh/phpunit.xml.dist jpwpcomsh:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ echo "::engroup::" echo "::group::execution" - ssh -i ~/.ssh/id_site jetpackwpcomshtester.wordpress.com@sftp.wp.com "~/htdocs/github-action-handler.sh" || CODE=$? + ssh jpwpcomsh "~/htdocs/github-action-handler.sh" || CODE=$? echo "::endgroup::" echo "::group::teardown" From e1dbc3e80602420fa0eec357f21404b4259d06b9 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Wed, 15 Jan 2025 20:06:57 +0300 Subject: [PATCH 22/29] Moved the polyfill load to after WordPress loading. --- projects/plugins/wpcomsh/tests/bootstrap.php | 13 ++----------- projects/plugins/wpcomsh/tests/lib/polyfills.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 projects/plugins/wpcomsh/tests/lib/polyfills.php diff --git a/projects/plugins/wpcomsh/tests/bootstrap.php b/projects/plugins/wpcomsh/tests/bootstrap.php index ec4c191e095bd..5f5984056fbad 100644 --- a/projects/plugins/wpcomsh/tests/bootstrap.php +++ b/projects/plugins/wpcomsh/tests/bootstrap.php @@ -47,6 +47,8 @@ * Manually load the plugin being tested. */ function _manually_load_plugin() { + + require_once __DIR__ . '/lib/polyfills.php'; if ( file_exists( WPMU_PLUGIN_DIR . '/wpcomsh-loader.php' ) ) { return; } @@ -60,16 +62,5 @@ function _manually_load_plugin() { define( 'WP_TESTS_CONFIG_FILE_PATH', getenv( 'WP_TESTS_CONFIG_FILE_PATH' ) ); } -if ( ! function_exists( 'wp_cache_flush_runtime' ) ) { - /** - * Removes all cache items from the in-memory runtime cache. - * - * @return bool True on success, false on failure. - */ - function wp_cache_flush_runtime() { - return wp_cache_flush(); - } -} - // Start up the WP testing environment. require_once $_tests_dir . '/includes/bootstrap.php'; diff --git a/projects/plugins/wpcomsh/tests/lib/polyfills.php b/projects/plugins/wpcomsh/tests/lib/polyfills.php new file mode 100644 index 0000000000000..930a072f26fb7 --- /dev/null +++ b/projects/plugins/wpcomsh/tests/lib/polyfills.php @@ -0,0 +1,12 @@ + Date: Fri, 17 Jan 2025 16:47:22 +0300 Subject: [PATCH 23/29] Removed polyfills. --- projects/plugins/wpcomsh/tests/bootstrap.php | 1 - projects/plugins/wpcomsh/tests/lib/polyfills.php | 12 ------------ 2 files changed, 13 deletions(-) delete mode 100644 projects/plugins/wpcomsh/tests/lib/polyfills.php diff --git a/projects/plugins/wpcomsh/tests/bootstrap.php b/projects/plugins/wpcomsh/tests/bootstrap.php index 5f5984056fbad..682a8c41e9956 100644 --- a/projects/plugins/wpcomsh/tests/bootstrap.php +++ b/projects/plugins/wpcomsh/tests/bootstrap.php @@ -48,7 +48,6 @@ */ function _manually_load_plugin() { - require_once __DIR__ . '/lib/polyfills.php'; if ( file_exists( WPMU_PLUGIN_DIR . '/wpcomsh-loader.php' ) ) { return; } diff --git a/projects/plugins/wpcomsh/tests/lib/polyfills.php b/projects/plugins/wpcomsh/tests/lib/polyfills.php deleted file mode 100644 index 930a072f26fb7..0000000000000 --- a/projects/plugins/wpcomsh/tests/lib/polyfills.php +++ /dev/null @@ -1,12 +0,0 @@ - Date: Fri, 17 Jan 2025 17:36:05 +0300 Subject: [PATCH 24/29] Removed null coalescing and added a short ternary. --- projects/plugins/wpcomsh/tests/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/wpcomsh/tests/bootstrap.php b/projects/plugins/wpcomsh/tests/bootstrap.php index 682a8c41e9956..f626ac4fba738 100644 --- a/projects/plugins/wpcomsh/tests/bootstrap.php +++ b/projects/plugins/wpcomsh/tests/bootstrap.php @@ -7,7 +7,7 @@ $_tests_dir = getenv( 'WP_TESTS_DIR' ); $_core_dir = getenv( 'WP_CORE_DIR' ); -$_wp_content_dir = getenv( 'WP_CONTENT_DIR' ) ?? $_core_dir; +$_wp_content_dir = getenv( 'WP_CONTENT_DIR' ) ?: $_core_dir; // phpcs:ignore Universal.Operators $wp_branch = getenv( 'WP_BRANCH' ); if ( ! $_tests_dir ) { From a6b8715d3a22a2c3e4066c1a95401c2b07fcda20 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Fri, 17 Jan 2025 17:49:48 +0300 Subject: [PATCH 25/29] Removed the change detector prop. --- .github/workflows/wpcloud.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index 6bfeeb604d708..026633ba10cbd 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -43,8 +43,7 @@ jobs: run: | CHANGED="$(EXTRA=test .github/files/list-changed-projects.sh)" - # WPCOMSH_CHANGED="$(jq --argjson changed "$CHANGED" -n '$changed | has( "plugins/wpcomsh" ) ')" - WPCOMSH_CHANGED="true" + WPCOMSH_CHANGED="$(jq --argjson changed "$CHANGED" -n '$changed | has( "plugins/wpcomsh" ) ')" echo "wpcomsh=${WPCOMSH_CHANGED}" >> "$GITHUB_OUTPUT" - name: Build wpcomsh if: steps.changed.outputs.wpcomsh == 'true' From 805d152d0c51aeddd9790c6ad2672eb0817e7dd6 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Fri, 17 Jan 2025 19:31:27 +0300 Subject: [PATCH 26/29] Added concurrency settings to make sure there can be only one. --- .github/workflows/wpcloud.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index 026633ba10cbd..0010cffc1f56a 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -5,8 +5,9 @@ on: push: branches: ['trunk', '*/branch-*'] concurrency: - group: wpcloud-${{ github.event_name }}-${{ github.ref }} - cancel-in-progress: true + group: wpcloud-wpcomsh + cancel-in-progress: false + # Concurrency is set up to make sure we can only run one WPCloud testing job at the same time. jobs: build: From e482ee5c330100ae2cebe0cd579bf63c6053de02 Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Fri, 17 Jan 2025 19:52:36 +0300 Subject: [PATCH 27/29] Added updating of source files and cleanup after that updating. --- .github/workflows/wpcloud.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index 0010cffc1f56a..cce1414b12a5b 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -127,6 +127,8 @@ jobs: echo "::endgroup::" echo "::group::Transferring wpcomsh to the testing server" + ssh jpwpcomsh "wp dereferenced freshen > /dev/null 2>&1" + ssh jpwpcomsh "rm -rf /tmp/old-* > /dev/null 2>&1" pnpm jetpack rsync wpcomsh jpwpcomsh:~/htdocs/wp-content/mu-plugins scp -r projects/plugins/wpcomsh/bin jpwpcomsh:/srv/htdocs/wp-content/mu-plugins/wpcomsh scp -r projects/plugins/wpcomsh/tests jpwpcomsh:/srv/htdocs/wp-content/mu-plugins/wpcomsh/ From 8b93c18111eee0391b194288e79ab788baefe7ac Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Tue, 21 Jan 2025 20:47:24 +0300 Subject: [PATCH 28/29] Update .github/workflows/wpcloud.yml Co-authored-by: Brad Jorsch --- .github/workflows/wpcloud.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index cce1414b12a5b..031ca67f41cd3 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -17,9 +17,6 @@ jobs: wpcomsh: ${{ steps.changed.outputs.wpcomsh }} steps: - uses: actions/checkout@v4 - with: - # codecov.io requires a fetch depth > 1. - fetch-depth: 2 # For pull requests, list-changed-projects.sh needs the merge base. # But it doesn't have to be checked out. From ca16342d2ba913da6ed99aff1c50526700ea104f Mon Sep 17 00:00:00 2001 From: Igor Zinovyev Date: Tue, 21 Jan 2025 20:47:40 +0300 Subject: [PATCH 29/29] Update .github/workflows/wpcloud.yml Co-authored-by: Brad Jorsch --- .github/workflows/wpcloud.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/wpcloud.yml b/.github/workflows/wpcloud.yml index 031ca67f41cd3..7f4700742cd73 100644 --- a/.github/workflows/wpcloud.yml +++ b/.github/workflows/wpcloud.yml @@ -28,9 +28,6 @@ jobs: - name: Setup tools uses: ./.github/actions/tool-setup - with: - php: ${{ matrix.php }} - node: ${{ matrix.node }} - name: Monorepo install run: | echo "::group::Pnpm"