From f838d20493065191d3993c0fe75f5f95f22ceb84 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sat, 4 Jun 2022 12:15:29 +0100 Subject: [PATCH 01/41] Update tests.yml Configure for GitHub Actions --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d3f46f2..ec0a0e4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,7 +44,7 @@ jobs: runs-on: ubuntu-latest # Remove this line if Github Actions is your preferred means of running the tests. - if: ${{ false }} + #if: ${{ false }} env: # This is only a subset/example of env vars available. See the `.env.default` file for a full list. From 77ffe4b19738be22d36e195851882905d47dc8b5 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 18:01:14 +0100 Subject: [PATCH 02/41] Use terminus instead of ssh to access wp-cli --- prepare.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/prepare.php b/prepare.php index 6045ea7..76f0529 100644 --- a/prepare.php +++ b/prepare.php @@ -27,7 +27,12 @@ file_put_contents( getenv( 'HOME' ) . '/.ssh/id_rsa', base64_decode( $WPT_SSH_PRIVATE_KEY_BASE64 ) ); perform_operations( array( 'chmod 600 ~/.ssh/id_rsa', - 'ssh -q ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' wp cli info', + 'mkdir -p ~/terminus && cd ~/terminus', + 'curl -L https://github.com/pantheon-systems/terminus/releases/download/latest/terminus.phar --output terminus', + 'chmod +x terminus', + './terminus self:update', + './terminus auth:login --machine-token=' . getenv( 'TERMINUS_MACHINE_TOKEN'), + './terminus wp ' . getenv( 'PANTHEON_SITE_NAME') . '.' getenv( 'PANTHEON_SITE_ENV' ) . ' -- cli info', ) ); } From 6e00fb25a47e78d46562d0ec395e2c98435c6e5c Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 18:03:26 +0100 Subject: [PATCH 03/41] Typo --- prepare.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare.php b/prepare.php index 76f0529..dc507f1 100644 --- a/prepare.php +++ b/prepare.php @@ -32,7 +32,7 @@ 'chmod +x terminus', './terminus self:update', './terminus auth:login --machine-token=' . getenv( 'TERMINUS_MACHINE_TOKEN'), - './terminus wp ' . getenv( 'PANTHEON_SITE_NAME') . '.' getenv( 'PANTHEON_SITE_ENV' ) . ' -- cli info', + './terminus wp ' . getenv( 'PANTHEON_SITE_NAME' ) . '.' . getenv( 'PANTHEON_SITE_ENV' ) . ' -- cli info', ) ); } From 949a26fe7fac17ed3c03aab4b49e1275e72f3195 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 18:12:25 +0100 Subject: [PATCH 04/41] Use variables instead of getenv. --- prepare.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/prepare.php b/prepare.php index dc507f1..100262e 100644 --- a/prepare.php +++ b/prepare.php @@ -16,6 +16,9 @@ $WPT_TEST_DIR = getenv( 'WPT_TEST_DIR' ); $WPT_PHP_EXECUTABLE = getenv( 'WPT_PHP_EXECUTABLE' ) ? : 'php'; $WPT_DEBUG = getenv( 'WPT_DEBUG' ); +$TERMINUS_MACHINE_TOKEN = getenv( 'TERMINUS_MACHINE_TOKEN' ); +$PANTHEON_SITE_NAME = getenv( 'PANTHEON_SITE_NAME' ); +$PANTHEON_SITE_ENV = getenv( 'PANTHEON_SITE_ENV' ); // Set the ssh private key if it's set. $WPT_SSH_PRIVATE_KEY_BASE64 = getenv( 'WPT_SSH_PRIVATE_KEY_BASE64' ); @@ -31,8 +34,8 @@ 'curl -L https://github.com/pantheon-systems/terminus/releases/download/latest/terminus.phar --output terminus', 'chmod +x terminus', './terminus self:update', - './terminus auth:login --machine-token=' . getenv( 'TERMINUS_MACHINE_TOKEN'), - './terminus wp ' . getenv( 'PANTHEON_SITE_NAME' ) . '.' . getenv( 'PANTHEON_SITE_ENV' ) . ' -- cli info', + './terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, + './terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', ) ); } From 13c1dee90bf98e67a2376fcda3d400ed4a0e6596 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 18:26:44 +0100 Subject: [PATCH 05/41] Run when there is a commit to master --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ec0a0e4..54d650b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,6 +20,9 @@ on: # - cron: '0 0 * * *' # Every 30 minutes. # - cron: '0/30 * * * *' + push: + branches: + - 'master' # Cancels all previous workflow runs for pull requests that have not completed. concurrency: From 909dac97e56977cc25f602407bd22ef3693a7251 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 18:30:48 +0100 Subject: [PATCH 06/41] Fix syntax. Run on any push --- .github/workflows/tests.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 54d650b..cca4fb3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,9 +20,7 @@ on: # - cron: '0 0 * * *' # Every 30 minutes. # - cron: '0/30 * * * *' - push: - branches: - - 'master' + push: # Cancels all previous workflow runs for pull requests that have not completed. concurrency: From 368f549c5a0e46890a624a871b296e2d7afbad46 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 18:34:10 +0100 Subject: [PATCH 07/41] Don't try to update terminus after just downloading it. --- prepare.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare.php b/prepare.php index 100262e..ed4247d 100644 --- a/prepare.php +++ b/prepare.php @@ -33,7 +33,7 @@ 'mkdir -p ~/terminus && cd ~/terminus', 'curl -L https://github.com/pantheon-systems/terminus/releases/download/latest/terminus.phar --output terminus', 'chmod +x terminus', - './terminus self:update', + 'pwd', './terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, './terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', ) ); From 35d78378aaa6735777f9c2fb2b9b9b83ed66990c Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 18:41:25 +0100 Subject: [PATCH 08/41] List files of the current directory --- prepare.php | 1 + 1 file changed, 1 insertion(+) diff --git a/prepare.php b/prepare.php index ed4247d..43760e0 100644 --- a/prepare.php +++ b/prepare.php @@ -34,6 +34,7 @@ 'curl -L https://github.com/pantheon-systems/terminus/releases/download/latest/terminus.phar --output terminus', 'chmod +x terminus', 'pwd', + 'ls -al', './terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, './terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', ) ); From 69c5fca3ba7b425bb82fa7ad9e563b1f79996071 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 18:44:09 +0100 Subject: [PATCH 09/41] Don't put terminus in a folder under ~ --- prepare.php | 1 - 1 file changed, 1 deletion(-) diff --git a/prepare.php b/prepare.php index 43760e0..9725d71 100644 --- a/prepare.php +++ b/prepare.php @@ -30,7 +30,6 @@ file_put_contents( getenv( 'HOME' ) . '/.ssh/id_rsa', base64_decode( $WPT_SSH_PRIVATE_KEY_BASE64 ) ); perform_operations( array( 'chmod 600 ~/.ssh/id_rsa', - 'mkdir -p ~/terminus && cd ~/terminus', 'curl -L https://github.com/pantheon-systems/terminus/releases/download/latest/terminus.phar --output terminus', 'chmod +x terminus', 'pwd', From 2e34a91bd7bbb642cfbc61563f80502930131686 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 18:59:22 +0100 Subject: [PATCH 10/41] Remove the dot slash before terminus --- prepare.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prepare.php b/prepare.php index 9725d71..0330cd7 100644 --- a/prepare.php +++ b/prepare.php @@ -34,8 +34,8 @@ 'chmod +x terminus', 'pwd', 'ls -al', - './terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, - './terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', + 'terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, + 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', ) ); } From bc82259a7a109b5e8cacef9715004e3adefec08e Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 19:01:37 +0100 Subject: [PATCH 11/41] List /usr/local/bin/terminus --- prepare.php | 1 + 1 file changed, 1 insertion(+) diff --git a/prepare.php b/prepare.php index 0330cd7..53713dc 100644 --- a/prepare.php +++ b/prepare.php @@ -34,6 +34,7 @@ 'chmod +x terminus', 'pwd', 'ls -al', + 'ls -al /usr/local/bin/terminus' 'terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', ) ); From b7fd50f41a530605d8a364426f6897e75acc9b67 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 19:02:41 +0100 Subject: [PATCH 12/41] Just list /usr/local/bin --- prepare.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare.php b/prepare.php index 53713dc..90ce77a 100644 --- a/prepare.php +++ b/prepare.php @@ -34,7 +34,7 @@ 'chmod +x terminus', 'pwd', 'ls -al', - 'ls -al /usr/local/bin/terminus' + 'ls -al /usr/local/bin/', 'terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', ) ); From 0fa100d4f2417aa529bf6cb1bbe459d1a18437c9 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 19:14:13 +0100 Subject: [PATCH 13/41] Add a symlink for terminus --- prepare.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare.php b/prepare.php index 90ce77a..50c1771 100644 --- a/prepare.php +++ b/prepare.php @@ -33,7 +33,7 @@ 'curl -L https://github.com/pantheon-systems/terminus/releases/download/latest/terminus.phar --output terminus', 'chmod +x terminus', 'pwd', - 'ls -al', + 'ln -s terminus /usr/local/bin/terminus' 'ls -al /usr/local/bin/', 'terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', From aeecefbd5cd499ef98c4eb7b005214891a63415f Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 19:14:55 +0100 Subject: [PATCH 14/41] Typo --- prepare.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare.php b/prepare.php index 50c1771..eb2c62a 100644 --- a/prepare.php +++ b/prepare.php @@ -33,7 +33,7 @@ 'curl -L https://github.com/pantheon-systems/terminus/releases/download/latest/terminus.phar --output terminus', 'chmod +x terminus', 'pwd', - 'ln -s terminus /usr/local/bin/terminus' + 'ln -s terminus /usr/local/bin/terminus', 'ls -al /usr/local/bin/', 'terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', From 33372277ed367ad0d07da900feb62ed5639795f4 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 19:17:29 +0100 Subject: [PATCH 15/41] Use an absolute path on the symlink --- prepare.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare.php b/prepare.php index eb2c62a..908dce6 100644 --- a/prepare.php +++ b/prepare.php @@ -33,7 +33,7 @@ 'curl -L https://github.com/pantheon-systems/terminus/releases/download/latest/terminus.phar --output terminus', 'chmod +x terminus', 'pwd', - 'ln -s terminus /usr/local/bin/terminus', + 'ln -s /home/runner/work/wporg-phpunit-test-runner/wporg-phpunit-test-runner/terminus /usr/local/bin/terminus', 'ls -al /usr/local/bin/', 'terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', From 6ffb4dacca3f884154b8035baf2f387bf0641152 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 19:18:52 +0100 Subject: [PATCH 16/41] Also list the pwd's contents --- prepare.php | 1 + 1 file changed, 1 insertion(+) diff --git a/prepare.php b/prepare.php index 908dce6..7fc661e 100644 --- a/prepare.php +++ b/prepare.php @@ -33,6 +33,7 @@ 'curl -L https://github.com/pantheon-systems/terminus/releases/download/latest/terminus.phar --output terminus', 'chmod +x terminus', 'pwd', + 'ls -al', 'ln -s /home/runner/work/wporg-phpunit-test-runner/wporg-phpunit-test-runner/terminus /usr/local/bin/terminus', 'ls -al /usr/local/bin/', 'terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, From 473c49cfceb2920a6fe47d7aac07fe450bef334c Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 19:20:36 +0100 Subject: [PATCH 17/41] Try to symlink as root --- prepare.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare.php b/prepare.php index 7fc661e..7eeedc6 100644 --- a/prepare.php +++ b/prepare.php @@ -34,7 +34,7 @@ 'chmod +x terminus', 'pwd', 'ls -al', - 'ln -s /home/runner/work/wporg-phpunit-test-runner/wporg-phpunit-test-runner/terminus /usr/local/bin/terminus', + 'sudo ln -s /home/runner/work/wporg-phpunit-test-runner/wporg-phpunit-test-runner/terminus /usr/local/bin/terminus', 'ls -al /usr/local/bin/', 'terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', From 9d7eafcda154fea7a95b0f1b104709d01fd59af3 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 19:27:33 +0100 Subject: [PATCH 18/41] Load the Pantheon secrets --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cca4fb3..35ffbdb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -61,6 +61,10 @@ jobs: # SSH settings for connecting to the test environment. WPT_SSH_CONNECT: ${{ secrets.WPT_SSH_CONNECT }} WPT_SSH_PRIVATE_KEY_BASE64: ${{ secrets.WPT_SSH_PRIVATE_KEY_BASE64 }} + # Pantheon-specific variables + PANTHEON_SITE_NAME: ${{ secrets.PANTHEON_SITE_NAME }} + PANTHEON_SITE_ENV: ${{ secrets.PANTHEON_SITE_ENV }} + TERMINUS_MACHINE_TOKEN: ${{ secrets.TERMINUS_MACHINE_TOKEN }} steps: - name: Checkout repository From c2185f826a03db017088ab3f61f038fe650fd0e6 Mon Sep 17 00:00:00 2001 From: Ryan Marks Date: Sun, 5 Jun 2022 19:29:22 +0100 Subject: [PATCH 19/41] Enable verbose (x3) terminus logging. --- prepare.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prepare.php b/prepare.php index 7eeedc6..867be95 100644 --- a/prepare.php +++ b/prepare.php @@ -36,7 +36,7 @@ 'ls -al', 'sudo ln -s /home/runner/work/wporg-phpunit-test-runner/wporg-phpunit-test-runner/terminus /usr/local/bin/terminus', 'ls -al /usr/local/bin/', - 'terminus auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, + 'terminus -vvv auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', ) ); } From 5f6e4d79e7df8520232eca8eca29e769ce11af53 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 10:24:09 -0700 Subject: [PATCH 20/41] update actions --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9e09f80..dec1542 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -69,16 +69,16 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 + uses: actions/checkout@v4 - name: Set up PHP - uses: shivammathur/setup-php@c5fc0d8281aba02c7fda07d3a70cc5371548067d # v2.25.2 + uses: shivammathur/setup-php@v2 with: php-version: '7.4' coverage: none - name: Install NodeJS - uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 + uses: actions/setup-node@v4 with: node-version: 20 From f08e6bd0fbc72ccf6e9bf86792c43be8a00493b5 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 10:24:37 -0700 Subject: [PATCH 21/41] remove if false --- .github/workflows/tests.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dec1542..c4d8b50 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -45,9 +45,6 @@ jobs: name: Run Core PHPUnit tests runs-on: ubuntu-latest - # Remove this line if Github Actions is your preferred means of running the tests. - #if: ${{ false }} - env: # This is only a subset/example of env vars available. See the `.env.default` file for a full list. WPT_PREPARE_DIR: ${{ secrets.WPT_PREPARE_DIR }} From 14c0e8f0a9bd7c447c05414a6e961e9b2a0ed1c1 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 10:29:50 -0700 Subject: [PATCH 22/41] install terminus in the action --- .github/workflows/tests.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c4d8b50..218523f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -78,6 +78,14 @@ jobs: uses: actions/setup-node@v4 with: node-version: 20 + + - name: Install Terminus + uses: pantheon-systems/terminus-github-actions@v1 + with: + terminus-machine-token: ${{ secrets.TERMINUS_MACHINE_TOKEN }} + + - name: Test Terminus + run: terminus art wp - name: Prepare environment run: php prepare.php From 6602d1bb85ab1e6dbdd4112b7efb8e23f0f8a5a3 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 10:31:08 -0700 Subject: [PATCH 23/41] remove the terminus install from prepare this is what was breaking, we can install terminus first --- prepare.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/prepare.php b/prepare.php index 2d2aaa3..bf832bd 100644 --- a/prepare.php +++ b/prepare.php @@ -82,13 +82,6 @@ file_put_contents( getenv( 'HOME' ) . '/.ssh/id_rsa', base64_decode( $WPT_SSH_PRIVATE_KEY_BASE64 ) ); perform_operations( array( 'chmod 600 ~/.ssh/id_rsa', - 'curl -L https://github.com/pantheon-systems/terminus/releases/download/latest/terminus.phar --output terminus', - 'chmod +x terminus', - 'pwd', - 'ls -al', - 'sudo ln -s /home/runner/work/wporg-phpunit-test-runner/wporg-phpunit-test-runner/terminus /usr/local/bin/terminus', - 'ls -al /usr/local/bin/', - 'terminus -vvv auth:login --machine-token=' . $TERMINUS_MACHINE_TOKEN, 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', ) ); } From 9f956f9c57f0973569eb73f710b4198251d47edc Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 10:32:05 -0700 Subject: [PATCH 24/41] run on push to main --- .github/workflows/tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 218523f..0aec181 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,6 +21,8 @@ on: # Every 30 minutes. # - cron: '0/30 * * * *' push: + branches: + - main workflow_dispatch: # Cancels all previous workflow runs for pull requests that have not completed. From 8ffa5d965167e4023faf5b11a40a6046acccf6aa Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 10:32:51 -0700 Subject: [PATCH 25/41] wp -> wordpress --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0aec181..d4122fb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -87,7 +87,7 @@ jobs: terminus-machine-token: ${{ secrets.TERMINUS_MACHINE_TOKEN }} - name: Test Terminus - run: terminus art wp + run: terminus art wordpress - name: Prepare environment run: php prepare.php From c1efec71e1e6892f0c97683e6b8b5860cea243fa Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 10:34:31 -0700 Subject: [PATCH 26/41] run terminus auth:login --- .github/workflows/tests.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d4122fb..551492f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -86,8 +86,10 @@ jobs: with: terminus-machine-token: ${{ secrets.TERMINUS_MACHINE_TOKEN }} - - name: Test Terminus - run: terminus art wordpress + - name: Authenticate Terminus + run: | + terminus art wordpress + terminus auth:login --machine-token=${{ secrets.TERMINUS_MACHINE_TOKEN }} - name: Prepare environment run: php prepare.php From 6123443d378651b565d91ebcec8f9a47e00410e0 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 10:39:26 -0700 Subject: [PATCH 27/41] add drush.in to ssh-rsa config --- prepare.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/prepare.php b/prepare.php index bf832bd..5b361ec 100644 --- a/prepare.php +++ b/prepare.php @@ -82,6 +82,9 @@ file_put_contents( getenv( 'HOME' ) . '/.ssh/id_rsa', base64_decode( $WPT_SSH_PRIVATE_KEY_BASE64 ) ); perform_operations( array( 'chmod 600 ~/.ssh/id_rsa', + 'echo "Host *.drush.in HostKeyAlgorithms +ssh-rsa" >> ~/.ssh/config', + 'echo "Host *.drush.in PubkeyAcceptedKeyTypes +ssh-rsa" >> ~/.ssh/config', + 'echo "StrictHostKeyChecking no" >> ~/.ssh/config', 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', ) ); } From 47ed24d20b2482e2c29f822b643b1d4541da7680 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 10:54:26 -0700 Subject: [PATCH 28/41] output the fingerprint of the ssh key --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 551492f..3de6a61 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -90,6 +90,9 @@ jobs: run: | terminus art wordpress terminus auth:login --machine-token=${{ secrets.TERMINUS_MACHINE_TOKEN }} + + - name: Check the SSH key token + run: echo "${{ secrets.WPT_SSH_PRIVATE_KEY_BASE64 }}" | base64 -d | ssh-keygen -lf - - name: Prepare environment run: php prepare.php From cf275c200fffbd2d9066d482177f66f453a34f7c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 13:18:35 -0700 Subject: [PATCH 29/41] use /dev/stdin --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3de6a61..b1c80a2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -92,7 +92,7 @@ jobs: terminus auth:login --machine-token=${{ secrets.TERMINUS_MACHINE_TOKEN }} - name: Check the SSH key token - run: echo "${{ secrets.WPT_SSH_PRIVATE_KEY_BASE64 }}" | base64 -d | ssh-keygen -lf - + run: echo "${{ secrets.WPT_SSH_PRIVATE_KEY_BASE64 }}" | base64 -d | ssh-keygen -lf /dev/stdin - name: Prepare environment run: php prepare.php From bed7d3cdd482ba704209cd3d256c99855a6a2e3a Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 13:33:01 -0700 Subject: [PATCH 30/41] remove the ssh key checking step --- .github/workflows/tests.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b1c80a2..551492f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -90,9 +90,6 @@ jobs: run: | terminus art wordpress terminus auth:login --machine-token=${{ secrets.TERMINUS_MACHINE_TOKEN }} - - - name: Check the SSH key token - run: echo "${{ secrets.WPT_SSH_PRIVATE_KEY_BASE64 }}" | base64 -d | ssh-keygen -lf /dev/stdin - name: Prepare environment run: php prepare.php From 1e819443bdef6af2aa779ffe96ffef0327b9db81 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 16:19:47 -0700 Subject: [PATCH 31/41] commit the cleanup --- cleanup.php | 1 + 1 file changed, 1 insertion(+) diff --git a/cleanup.php b/cleanup.php index e584c6c..45fc282 100644 --- a/cleanup.php +++ b/cleanup.php @@ -37,6 +37,7 @@ 'rm -rf ' . escapeshellarg( $WPT_PREPARE_DIR . '/.git' ), 'rm -rf ' . escapeshellarg( $WPT_PREPARE_DIR . '/node_modules/.cache' ), 'rm -r ' . escapeshellarg( $WPT_PREPARE_DIR ), + 'terminus env:commit --message="Cleanup test environment" --yes', ) ); /** From 51904ead6dbb4714252f9a6ec9c223e149a2c35c Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 16:19:53 -0700 Subject: [PATCH 32/41] set sftp --- prepare.php | 1 + 1 file changed, 1 insertion(+) diff --git a/prepare.php b/prepare.php index 5b361ec..b4e0d4d 100644 --- a/prepare.php +++ b/prepare.php @@ -86,6 +86,7 @@ 'echo "Host *.drush.in PubkeyAcceptedKeyTypes +ssh-rsa" >> ~/.ssh/config', 'echo "StrictHostKeyChecking no" >> ~/.ssh/config', 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', + 'terminus connection:set sftp', ) ); } From 44e0903b34d8b2018d10308870e93c49dd01127a Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 16:21:56 -0700 Subject: [PATCH 33/41] fix terminus command --- prepare.php | 2 +- wporg_phpunit_test_runner_rsa | 50 +++++++++++++++++++++++++++++++ wporg_phpunit_test_runner_rsa.pub | 1 + 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 wporg_phpunit_test_runner_rsa create mode 100644 wporg_phpunit_test_runner_rsa.pub diff --git a/prepare.php b/prepare.php index b4e0d4d..34c1892 100644 --- a/prepare.php +++ b/prepare.php @@ -86,7 +86,7 @@ 'echo "Host *.drush.in PubkeyAcceptedKeyTypes +ssh-rsa" >> ~/.ssh/config', 'echo "StrictHostKeyChecking no" >> ~/.ssh/config', 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', - 'terminus connection:set sftp', + 'terminus connection:set ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' sftp', ) ); } diff --git a/wporg_phpunit_test_runner_rsa b/wporg_phpunit_test_runner_rsa new file mode 100644 index 0000000..8e6349e --- /dev/null +++ b/wporg_phpunit_test_runner_rsa @@ -0,0 +1,50 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn +NhAAAAAwEAAQAAAgEAlveuheU0qGt8fmIXb3GJVBgmhf7n1KSuWt8nBoWWJ90Mup+SBut8 +56rA8vHOBgkSx+sneT5a4a31qGyIZhUiN3yQlbA3xR0FUFJ0zFhor0pEYqIVphtQQsNjeU +HGYV7AGtyoK8PqvLS4RjfN4OwDSg72vQnY8Fb2Ynte/QiLhkrFpFYxeVld3QUcfBaqYFrh +IrRZ2phMVZzfQVdRAVASEzfL/UxKZbvs1boe9McdDsyes6MDQz4k4gJ2n8ySyinO9yfpcV +NKvxP5NoaGCtqkL4WXedr38VAKuvM1AGQKGkFfh61WMtDlBGPL8HjOgtgiRk2sgIMjT42N +KK3pb0lfdaYdXZDmGofA0NUO5E0KY57dCOkMcvOjb+968PujIPfSKcAt1Hy0Jg1eFDpA/q +D3FifEgvzi/NyWbrmYgbzQMGtJqSEXuJMPymKyA2Nqb0cUqYhY1oC21ZxWFTfmOf1gHdNd +A9a5YcpeHeV7Y4e3tncxLG/NltdpUlhiLqtfE8/3X4RbWydtQVn/vaVp0r6IYez3lmhR51 +Nr1NLLKe5obqd/2qE4id8jSqyYMfOCD3k8Po5ho8tKf50dAtAeEAx80+aqWQO3H6ITAK+G +FicEzKXMJx74/qj0yZ2wuoazlupk8Hc28frINxSBw/ihaRl7pr2HbxapDp2LICpv2RqXba +UAAAdgTzJBxk8yQcYAAAAHc3NoLXJzYQAAAgEAlveuheU0qGt8fmIXb3GJVBgmhf7n1KSu +Wt8nBoWWJ90Mup+SBut856rA8vHOBgkSx+sneT5a4a31qGyIZhUiN3yQlbA3xR0FUFJ0zF +hor0pEYqIVphtQQsNjeUHGYV7AGtyoK8PqvLS4RjfN4OwDSg72vQnY8Fb2Ynte/QiLhkrF +pFYxeVld3QUcfBaqYFrhIrRZ2phMVZzfQVdRAVASEzfL/UxKZbvs1boe9McdDsyes6MDQz +4k4gJ2n8ySyinO9yfpcVNKvxP5NoaGCtqkL4WXedr38VAKuvM1AGQKGkFfh61WMtDlBGPL +8HjOgtgiRk2sgIMjT42NKK3pb0lfdaYdXZDmGofA0NUO5E0KY57dCOkMcvOjb+968PujIP +fSKcAt1Hy0Jg1eFDpA/qD3FifEgvzi/NyWbrmYgbzQMGtJqSEXuJMPymKyA2Nqb0cUqYhY +1oC21ZxWFTfmOf1gHdNdA9a5YcpeHeV7Y4e3tncxLG/NltdpUlhiLqtfE8/3X4RbWydtQV +n/vaVp0r6IYez3lmhR51Nr1NLLKe5obqd/2qE4id8jSqyYMfOCD3k8Po5ho8tKf50dAtAe +EAx80+aqWQO3H6ITAK+GFicEzKXMJx74/qj0yZ2wuoazlupk8Hc28frINxSBw/ihaRl7pr +2HbxapDp2LICpv2RqXbaUAAAADAQABAAACAC7Ceqj4TG4aFM5kfZPEG+ATNuNsB8yCUYrN +8Z2AhPjF6+pmAGnqSJ7M8cSOBt0xtEJ94JUaLjYWlq9bJohP5XBAQdxLX4rLKVkuoQSmIY +6htzrBr2jqrtpvAIGPUO3Z1jC7xc8AeNWIOEdvg3I2R/KJXf1BbpNKrDfmtI41NlobEMqM +8/f9KSiLK753msALhg4kxGwDnikqVLA9Zla8wUx4jNNg7O5D3eB5LJtujN6HnGRRinIqbm +wejTWDvLenaXZ+Qz0Zql4yxo8P7baw8AfUHg3dN8zjmN88816ynbpyIy+4Danhr/3DF2jd +UkGOxlb2Ogb4F1jNpDpEW7hfhpRFWJq1ijg85egV0bElfBTWGS+tPK/bCA9CjJEsSBNRjE +q/HGmDAuOKboda77aFmQRqg6KVyi3fBQHAAY0NAjEkHn6CKhOjUjhDVW7Hjz8YlCkKf6OR +ytbm6Idm2s4aLQjXM9kfqtvcGanlNb56He8NSKs9l0rVF6304HWECu5SOZTI2Y2qx0FzBD +V/rcZ5VXYNipwSMa21FwQeIwyRliCzpd4RYE5jCrsnT3JL90FrrxmaXylwgpv5c6CSL0Kq +8CYgvu3AhVm30Sf7IOfXwWIVUyRUAoaIszoUpEOlKSMnYQoDxwgNnBh8C7EBmBzvVhj6k4 +tOtOpZEfSs0mLfQmelAAABAQCV8GFH2lR+5ikP/YhZOAOpOJWQiH/Iuwk6oXYfPg/aTJm6 +0t12eoBxtwLFK3xyd0pnnKRGg67nlJY9bWMfRtT2GM0n7IQTTLosqyLtfiWhvffsVy76Zh +rOWcuQvPMcXhubS+ErbXGgzdWetjqR+9U3hKf8382AFTFxFeZjuDP+ulzmdFd1jQJ3y2TR +extvdEmrPoq5Pm6CSf+2TwSR2FZyMnssbwepU7Rs4fajlLeSSpw1xAJpn+2kNzuncb+nPW +9bQSbakO6ESUTC4FIidZ5+HbiLFUxBaG4mlIfGSlVoffIU7Qpd85FPEi0w1Dfkuq0p6THb +15uoKkiGXGQ3T8+RAAABAQDISnw035mdpUW8rJDtnH/UXc+Vu5+vCYR+iPz+flxDxqHe9x +banX/4aP5yj3SRX0GoOJ2dmRy1FCPUAL1uWBmsJ1MsfCiv6Q8YxEhCygj4XvMTSAVKZRWS +HaPaa2DEPaiECDS+7ytDC3ERU6g6ABo2BuQ7iL6v/4AEUG6Ec4UJ/3zFnbarpRlydIjwHn +dt6Td87KHG+id+uNCyifeXxdsk2we56jbt4ceolDJcXOaPKgFnYRypMj0aRmQcmtea048J +KRvAUWT8DdrK8GRj/rpDcgCUT0bGOBKMWpmYE4n49Pk0oi6mJ28dy3h0aYD/CcEO3W7oF5 +hpfWY+4U4hRPi3AAABAQDA9SuQQBcdj35JFGmaw2dwk7UwmrosupRm3unM+jJ3L+LKaQo+ +D9tZP16HmemJ0QkU0KcEDDJ99kh2cbrduDdbHgPFW5Ys56eBzR3GPWqpHj3FGh+mZ6KIRD +5Fc9MRq+9/04ZX8dGmaox06wLtAePFebpFg8HwuT95OuWW0OR6lAcvz5UEh2SmgsMn8RHA +O+VnCt9IEcUEX8PoEYqpOzi/nPH82q4OSTcEvVDt2sXGw+STfSGnJSFHdL364gkI9pOP5K +lp2TJUQvjQ4xddLu9abeeLpgQraEv5Dhafip6mPtOfVnomm2HY0hpD34tKN3oZGSJkxPqW +A/5QnJVR3RiDAAAAJ2RldmVsb3Blcit3cG9yZy10ZXN0LXJ1bm5lckBwYW50aGVvbi5pbw +ECAw== +-----END OPENSSH PRIVATE KEY----- diff --git a/wporg_phpunit_test_runner_rsa.pub b/wporg_phpunit_test_runner_rsa.pub new file mode 100644 index 0000000..d890fb0 --- /dev/null +++ b/wporg_phpunit_test_runner_rsa.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCW966F5TSoa3x+YhdvcYlUGCaF/ufUpK5a3ycGhZYn3Qy6n5IG63znqsDy8c4GCRLH6yd5PlrhrfWobIhmFSI3fJCVsDfFHQVQUnTMWGivSkRiohWmG1BCw2N5QcZhXsAa3Kgrw+q8tLhGN83g7ANKDva9CdjwVvZie179CIuGSsWkVjF5WV3dBRx8FqpgWuEitFnamExVnN9BV1EBUBITN8v9TEplu+zVuh70xx0OzJ6zowNDPiTiAnafzJLKKc73J+lxU0q/E/k2hoYK2qQvhZd52vfxUAq68zUAZAoaQV+HrVYy0OUEY8vweM6C2CJGTayAgyNPjY0orelvSV91ph1dkOYah8DQ1Q7kTQpjnt0I6Qxy86Nv73rw+6Mg99IpwC3UfLQmDV4UOkD+oPcWJ8SC/OL83JZuuZiBvNAwa0mpIRe4kw/KYrIDY2pvRxSpiFjWgLbVnFYVN+Y5/WAd010D1rlhyl4d5Xtjh7e2dzEsb82W12lSWGIuq18Tz/dfhFtbJ21BWf+9pWnSvohh7PeWaFHnU2vU0ssp7mhup3/aoTiJ3yNKrJgx84IPeTw+jmGjy0p/nR0C0B4QDHzT5qpZA7cfohMAr4YWJwTMpcwnHvj+qPTJnbC6hrOW6mTwdzbx+sg3FIHD+KFpGXumvYdvFqkOnYsgKm/ZGpdtpQ== developer+wporg-test-runner@pantheon.io From 741175a0a1cc3441f362e1b4d5a1542131ea0beb Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 17:48:00 -0700 Subject: [PATCH 34/41] extend timeout --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 551492f..e9cf674 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -46,6 +46,7 @@ jobs: test: name: Run Core PHPUnit tests runs-on: ubuntu-latest + timeout-minutes: 120 env: # This is only a subset/example of env vars available. See the `.env.default` file for a full list. From 11ffdf293446a43a06287e569d47b139175cf136 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 17:48:09 -0700 Subject: [PATCH 35/41] tweak the test script --- test.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test.php b/test.php index 18b3f4f..f99379f 100644 --- a/test.php +++ b/test.php @@ -9,6 +9,15 @@ */ require __DIR__ . '/functions.php'; +// Disable PHP output buffering +ini_set( 'output_buffering', 'off' ); +ini_set( 'zlib.output_compression', 'off' ); +ini_set( 'implicit_flush', 'on' ); +for ( $i = 0; $i < ob_get_level(); $i++ ) { + ob_end_flush(); +} +ob_implicit_flush( 1 ); + /** * Check for the presence of required environment variables. * This function should be defined in functions.php and should throw an @@ -71,12 +80,13 @@ */ $WPT_PHPUNIT_CMD = trim( getenv( 'WPT_PHPUNIT_CMD' ) ); if( empty( $WPT_PHPUNIT_CMD ) ) { - $WPT_PHPUNIT_CMD = 'cd ' . escapeshellarg( $WPT_TEST_DIR ) . ' && ' . $WPT_PHP_EXECUTABLE . ' ./vendor/phpunit/phpunit/phpunit --dont-report-useless-tests' . $WPT_FLAVOR_TXT . $WPT_EXTRATESTS_TXT; + $WPT_PHPUNIT_CMD = 'cd ' . escapeshellarg( $WPT_TEST_DIR ) . ' && ' . $WPT_PHP_EXECUTABLE . ' ./vendor/phpunit/phpunit/phpunit --dont-report-useless-tests --verbose' . $WPT_FLAVOR_TXT . $WPT_EXTRATESTS_TXT; } -// If an SSH connection string is provided, prepend the SSH command to the PHPUnit execution command. +// Adjust SSH command to force TTY and reduce buffering if ( ! empty( $WPT_SSH_CONNECT ) ) { - $WPT_PHPUNIT_CMD = 'ssh ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' ' . escapeshellarg( $WPT_PHPUNIT_CMD ); + $WPT_SSH_OPTIONS .= ' -tt -o ServerAliveInterval=30 -o ServerAliveCountMax=5 -o LogLevel=ERROR'; + $WPT_PHPUNIT_CMD = 'ssh ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' ' . escapeshellarg( $WPT_PHPUNIT_CMD ); } // Execute the PHPUnit command. From 303c84a52b4760130896032e52266fbf8aa8ebf7 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 17 Sep 2024 17:48:17 -0700 Subject: [PATCH 36/41] fix env for cleanup --- cleanup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cleanup.php b/cleanup.php index 45fc282..3fbb64f 100644 --- a/cleanup.php +++ b/cleanup.php @@ -37,7 +37,7 @@ 'rm -rf ' . escapeshellarg( $WPT_PREPARE_DIR . '/.git' ), 'rm -rf ' . escapeshellarg( $WPT_PREPARE_DIR . '/node_modules/.cache' ), 'rm -r ' . escapeshellarg( $WPT_PREPARE_DIR ), - 'terminus env:commit --message="Cleanup test environment" --yes', + "terminus env:commit $PANTHEON_SITE_NAME.$PANTHEON_SITE_ENV --message='Cleanup test environment' --yes", ) ); /** From 00e074041b00383e3d9c9d4efdc9ac1c5d4a1aaf Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 26 Aug 2025 09:48:15 -0700 Subject: [PATCH 37/41] bump php version --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 73929c6..81cabd7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -74,7 +74,7 @@ jobs: - name: Set up PHP uses: shivammathur/setup-php@20529878ed81ef8e78ddf08b480401e6101a850f # v2.35.3 with: - php-version: '7.4' + php-version: '8.4' coverage: none - name: Install NodeJS From 13cf9cacd1b950447c4397ed65fff3cf541e057e Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 26 Aug 2025 16:00:35 -0700 Subject: [PATCH 38/41] can we spit out some info about the site? --- .github/workflows/tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 81cabd7..89e1cbc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -92,6 +92,10 @@ jobs: terminus art wordpress terminus auth:login --machine-token=${{ secrets.TERMINUS_MACHINE_TOKEN }} + - name: Debug + run: | + terminus site:info ${{ secrets.PANTHEON_SITE_NAME }} + - name: Prepare environment run: php prepare.php From 865a537821cab455a3ac024efe236c772dc9c3a8 Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Tue, 26 Aug 2025 16:08:37 -0700 Subject: [PATCH 39/41] add db port --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 89e1cbc..d985f0e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -58,7 +58,7 @@ jobs: WPT_DB_NAME: ${{ secrets.WPT_DB_NAME }} WPT_DB_USER: ${{ secrets.WPT_DB_USER }} WPT_DB_PASSWORD: ${{ secrets.WPT_DB_PASSWORD }} - WPT_DB_HOST: ${{ secrets.WPT_DB_HOST }} + WPT_DB_HOST: "${{ secrets.WPT_DB_HOST }}:${{ secrets.WPT_DB_PORT }}" # SSH settings for connecting to the test environment. WPT_SSH_CONNECT: ${{ secrets.WPT_SSH_CONNECT }} WPT_SSH_PRIVATE_KEY_BASE64: ${{ secrets.WPT_SSH_PRIVATE_KEY_BASE64 }} From bfeb44d4a96faf47fb8465a6c7897fdcfc7619d1 Mon Sep 17 00:00:00 2001 From: Lauren Strong Date: Tue, 14 Apr 2026 15:38:17 -0700 Subject: [PATCH 40/41] DELENG-444: Establish DevRel ownership - Create CODEOWNERS with DevRel team - Add catalog-info.yaml for service catalog integration This repo runs WordPress core hosting tests to get Pantheon listed on make.wordpress.org/hosting/test-results/. DevRel will maintain this going forward. --- CODEOWNERS | 1 + catalog-info.yaml | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 CODEOWNERS create mode 100644 catalog-info.yaml diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..3f8f7ed --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @pantheon-systems/devrel diff --git a/catalog-info.yaml b/catalog-info.yaml new file mode 100644 index 0000000..af21779 --- /dev/null +++ b/catalog-info.yaml @@ -0,0 +1,17 @@ +--- +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: wporg-phpunit-test-runner + description: Runs WordPress core hosting tests for WordPress.org hosting test results listing + annotations: + github.com/project-slug: pantheon-systems/wporg-phpunit-test-runner + tags: + - wordpress + - testing + - phpunit + - hosting +spec: + type: tool + lifecycle: production + owner: devrel From 25cfe0b4f0cbf79d02d1759ad116e65274b5ac3e Mon Sep 17 00:00:00 2001 From: Chris Reynolds Date: Mon, 22 Jun 2026 15:51:32 -0600 Subject: [PATCH 41/41] Add Pantheon-specific WordPress PHPUnit test runner (#2) Merges upstream through 12388e8 and adapts the runner to execute tests on a Pantheon site via Terminus rather than locally on GHA. See PR description for full details. --- .env.default | 15 +- .github/workflows/props-bot.yml | 92 ------- .github/workflows/tests.yml | 98 +++++--- .gitignore | 11 +- README.md | 406 ++++-------------------------- cleanup.php | 58 ++--- functions.php | 80 +++++- prepare.php | 292 ++++++--------------- report.php | 227 +++++++---------- test.php | 121 ++++----- wporg_phpunit_test_runner_rsa | 50 ---- wporg_phpunit_test_runner_rsa.pub | 1 - 12 files changed, 447 insertions(+), 1004 deletions(-) delete mode 100644 .github/workflows/props-bot.yml delete mode 100644 wporg_phpunit_test_runner_rsa delete mode 100644 wporg_phpunit_test_runner_rsa.pub diff --git a/.env.default b/.env.default index 33b49c1..df58ae0 100644 --- a/.env.default +++ b/.env.default @@ -57,9 +57,16 @@ export WPT_SSH_OPTIONS="" # SSH private key, base64 encoded. export WPT_SSH_PRIVATE_KEY_BASE64="" -# Output logging -# Use 'verbose' to increase verbosity -export WPT_DEBUG="" +# Whether to enable debug Mode. +# +# Enabling debug mode will output verbose logging and details about each part +# of the test runner. +# +# 0 = Debug mode off +# 1 = Debug mode on +# +# Any other truthy value will also enable debug mode. +export WPT_DEBUG= # Certificate validation # Use 1 to validate, and 0 to not validate @@ -68,7 +75,7 @@ export WPT_CERTIFICATE_VALIDATION=1 # WordPress flavor # 0 = WordPress (simple version) # 1 = WordPress Multisite -export WPT_FLAVOR=1 +export WPT_FLAVOR=0 # Extra tests (groups) # 0 = none diff --git a/.github/workflows/props-bot.yml b/.github/workflows/props-bot.yml deleted file mode 100644 index 671f399..0000000 --- a/.github/workflows/props-bot.yml +++ /dev/null @@ -1,92 +0,0 @@ -name: Props Bot - -on: - # This event runs anytime a PR is (re)opened, updated, marked ready for review, or labeled. - # GitHub does not allow filtering the `labeled` event by a specific label. - # However, the logic below will short-circuit the workflow when the `props-bot` label is not the one being added. - # Note: The pull_request_target event is used instead of pull_request because this workflow needs permission to comment - # on the pull request. Because this event grants extra permissions to `GITHUB_TOKEN`, any code changes within the PR - # should be considered untrusted. See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/. - pull_request_target: - types: - - opened - - synchronize - - reopened - - labeled - - ready_for_review - # This event runs anytime a comment is added or deleted. - # You cannot filter this event for PR comments only. - # However, the logic below does short-circuit the workflow for issues. - issue_comment: - types: - - created - # This event will run everytime a new PR review is initially submitted. - pull_request_review: - types: - - submitted - # This event runs anytime a PR review comment is created or deleted. - pull_request_review_comment: - types: - - created - -# Cancels all previous workflow runs for pull requests that have not completed. -concurrency: - # The concurrency group contains the workflow name and the branch name for pull requests - # or the commit hash for any other events. - group: ${{ github.workflow }}-${{ contains( fromJSON( '["pull_request_target", "pull_request_review", "pull_request_review_comment"]' ), github.event_name ) && github.head_ref || github.sha }} - cancel-in-progress: true - -# Disable permissions for all available scopes by default. -# Any needed permissions should be configured at the job level. -permissions: {} - -jobs: - # Compiles a list of props for a pull request. - # - # Performs the following steps: - # - Collects a list of contributor props and leaves a comment. - # - Removes the props-bot label, if necessary. - props-bot: - name: Generate a list of props - runs-on: ubuntu-24.04 - permissions: - # The action needs permission `write` permission for PRs in order to add a comment. - pull-requests: write - contents: read - timeout-minutes: 20 - # The job will run when pull requests are open, ready for review and: - # - # - A comment is added to the pull request. - # - A review is created or commented on (unless PR originates from a fork). - # - The pull request is opened, synchronized, marked ready for review, or reopened. - # - The `props-bot` label is added to the pull request. - if: | - ( - github.event_name == 'issue_comment' && github.event.issue.pull_request || - ( contains( fromJSON( '["pull_request_review", "pull_request_review_comment"]' ), github.event_name ) && ! github.event.pull_request.head.repo.fork ) || - github.event_name == 'pull_request_target' && github.event.action != 'labeled' || - 'props-bot' == github.event.label.name - ) && - ( ! github.event.pull_request.draft && github.event.pull_request.state == 'open' || ! github.event.issue.draft && github.event.issue.state == 'open' ) - - steps: - - name: Gather a list of contributors - uses: WordPress/props-bot-action@trunk - with: - format: 'git' - - - name: Remove the props-bot label - uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - if: ${{ github.event.action == 'labeled' && 'props-bot' == github.event.label.name }} - with: - retries: 2 - retry-exempt-status-codes: 418 - script: | - github.rest.issues.removeLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: process.env.ISSUE_NUMBER, - name: 'props-bot' - }); - env: - ISSUE_NUMBER: ${{ github.event.number }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d985f0e..eff3b5e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -24,77 +24,109 @@ on: branches: - main workflow_dispatch: + inputs: + test_group: + description: 'Run only tests in this @group. Defaults to full suite.' + required: false + default: '' + type: choice + options: + - '' + - actions + - canonical + - comment + - cron + - db + - feed + - filters + - formatting + - http + - image + - l10n + - media + - ms-site + - option + - post + - query + - rest-api + - rewrite + - taxonomy + - themes + - upload + - user + - utf8 + test_filter: + description: 'PHPUnit --filter pattern — matches against class and method names. Examples: Tests_DB, Tests_Options, Tests_Post_Types::test_register. Overrides test_group if set.' + required: false + default: '' -# Cancels all previous workflow runs for pull requests that have not completed. +# Only one run at a time — prevents simultaneous runs from conflicting +# over the same wptests_* tables on the shared Pantheon environment. concurrency: - # The concurrency group contains the workflow name and the branch name for pull requests - # or the commit hash for any other events. - group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }} + group: ${{ github.workflow }} cancel-in-progress: true jobs: - # Tests the PHPUnit test runner. + # Runs the WordPress PHPUnit test suite on the Pantheon environment via Terminus. # - # Performs the following steps: - # - Checks out the repository. - # - Installs PHP. - # - Installs NodeJS 14 with caching configured. - # - Prepares the environment for tests. - # - Runs the tests. - # - Reports the results. - # - Cleans up. + # Flow: + # 1. Prepare: git clone wordpress-develop locally, rsync to Pantheon, run composer on Pantheon. + # 2. Test: run PHPUnit on Pantheon via terminus remote:wp eval --skip-wordpress. + # 3. Report: rsync results from Pantheon, upload to WordPress.org. + # 4. Cleanup: remove test dir on Pantheon and locally. test: name: Run Core PHPUnit tests runs-on: ubuntu-latest timeout-minutes: 120 env: - # This is only a subset/example of env vars available. See the `.env.default` file for a full list. WPT_PREPARE_DIR: ${{ secrets.WPT_PREPARE_DIR }} WPT_TEST_DIR: ${{ secrets.WPT_TEST_DIR }} WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }} - WPT_PHP_EXECUTABLE: ${{ secrets.WPT_PHP_EXECUTABLE }} - # Database settings - WPT_DB_NAME: ${{ secrets.WPT_DB_NAME }} - WPT_DB_USER: ${{ secrets.WPT_DB_USER }} - WPT_DB_PASSWORD: ${{ secrets.WPT_DB_PASSWORD }} - WPT_DB_HOST: "${{ secrets.WPT_DB_HOST }}:${{ secrets.WPT_DB_PORT }}" - # SSH settings for connecting to the test environment. - WPT_SSH_CONNECT: ${{ secrets.WPT_SSH_CONNECT }} + # PHP binary on the Pantheon container — use 'php' so it follows whatever + # version the environment is configured to run, without hardcoding a version. + WPT_PHP_EXECUTABLE: php + # SSH key for Terminus SSH operations (remote:wp, remote:composer). WPT_SSH_PRIVATE_KEY_BASE64: ${{ secrets.WPT_SSH_PRIVATE_KEY_BASE64 }} - # Pantheon-specific variables + # Pantheon-specific variables. PANTHEON_SITE_NAME: ${{ secrets.PANTHEON_SITE_NAME }} PANTHEON_SITE_ENV: ${{ secrets.PANTHEON_SITE_ENV }} TERMINUS_MACHINE_TOKEN: ${{ secrets.TERMINUS_MACHINE_TOKEN }} + # Optional test scoping — set via workflow_dispatch inputs. + WPT_TEST_GROUP: ${{ inputs.test_group }} + WPT_TEST_FILTER: ${{ inputs.test_filter }} steps: - name: Checkout repository - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 - name: Set up PHP - uses: shivammathur/setup-php@20529878ed81ef8e78ddf08b480401e6101a850f # v2.35.3 + uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2.37.2 with: php-version: '8.4' coverage: none - name: Install NodeJS - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 with: node-version: 20 - + - name: Install Terminus - uses: pantheon-systems/terminus-github-actions@v1 + uses: pantheon-systems/terminus-github-actions@409451ede17f75acac08f42edc823fee6c435057 # v1 with: - terminus-machine-token: ${{ secrets.TERMINUS_MACHINE_TOKEN }} + pantheon-machine-token: ${{ secrets.TERMINUS_MACHINE_TOKEN }} - - name: Authenticate Terminus + - name: Install Terminus plugins run: | - terminus art wordpress - terminus auth:login --machine-token=${{ secrets.TERMINUS_MACHINE_TOKEN }} + terminus self:plugin:install pantheon-systems/terminus-composer-plugin - - name: Debug + - name: Wake and configure Pantheon environment run: | + terminus art wordpress + terminus env:wake ${{ secrets.PANTHEON_SITE_NAME }}.${{ secrets.PANTHEON_SITE_ENV }} terminus site:info ${{ secrets.PANTHEON_SITE_NAME }} + terminus env:info ${{ secrets.PANTHEON_SITE_NAME }}.${{ secrets.PANTHEON_SITE_ENV }} + terminus connection:set ${{ secrets.PANTHEON_SITE_NAME }}.${{ secrets.PANTHEON_SITE_ENV }} sftp - name: Prepare environment run: php prepare.php diff --git a/.gitignore b/.gitignore index 4e67ea0..7e74adf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,13 @@ vendor/ package-lock.json commit.json -ignore.json \ No newline at end of file +ignore.json + +# Exclude the default test directory. +wp-test-runner/ + +# Files related to applying patches +*.rej +*.orig +*.patch +*.diff diff --git a/README.md b/README.md index 5baa664..ad96bdb 100644 --- a/README.md +++ b/README.md @@ -1,395 +1,79 @@ -# PHPUnit Test Runner +# WordPress PHPUnit Test Runner — Pantheon -Thanks for running the WordPress PHPUnit test suite on your infrastructure. We appreciate you helping to ensure WordPress’s compatibility for your users. +This is Pantheon's fork of the [WordPress PHPUnit Test Runner](https://github.com/WordPress/phpunit-test-runner), adapted to run the WordPress core hosting test suite on a Pantheon site and report results to the [WordPress.org hosting test results page](https://make.wordpress.org/hosting/test-results/). -If you haven't already, [please first read through the "Getting Started" documentation](https://make.wordpress.org/hosting/handbook/tests/). +The Pantheon site used as the test target runs the empty WordPress upstream (`empty-wp`). -The test suite runner is designed to be used without any file modification. Configuration happens with a series of environment variables (see [.env.default](.env.default) for an annotated overview). +For general background on the hosting tests, see the [Getting Started documentation](https://make.wordpress.org/hosting/handbook/tests/). -At a high level, the test suite runner: +## How it works -1. Prepares the test environment for the test suite. -2. Runs the PHPUnit tests in the test environment. -3. Reports the PHPUnit test results to WordPress.org -4. Cleans up the test suite environment. +Tests run directly on the Pantheon site via Terminus. The workflow: -## Setup +1. **Prepare** — clones `wordpress-develop` on the Pantheon site via `terminus remote:wp eval`, generates `wp-tests-config.php` using Pantheon's internal DB credentials, and installs PHPUnit dependencies via `terminus remote:composer`. +2. **Test** — runs the full WordPress PHPUnit suite on the Pantheon site via `terminus remote:wp eval`. +3. **Report** — retrieves results from the Pantheon site, fetches the current WordPress SVN revision, and uploads to WordPress.org. +4. **Cleanup** — removes the test directory from the Pantheon site. -The test suite runner can be used in one of two ways: +## GitHub Actions secrets -1. With GitHub Actions, (or Travis, Circle, or another CI service) as the controller that connects to the remote test environment. -2. With the runner cloned to and run directly within the test environment. +| Secret | Description | +|--------|-------------| +| `PANTHEON_SITE_NAME` | Pantheon site name (e.g. `my-site`) | +| `PANTHEON_SITE_ENV` | Pantheon environment (e.g. `dev`) | +| `TERMINUS_MACHINE_TOKEN` | Terminus machine token for the Pantheon account that owns the site | +| `WPT_SSH_PRIVATE_KEY_BASE64` | RSA private key (base64-encoded) registered on the Pantheon account — required for `terminus remote:wp` and `terminus remote:composer` | +| `WPT_PREPARE_DIR` | Local GHA path for temporary files (e.g. `/tmp/wp-test-runner`) | +| `WPT_TEST_DIR` | Path on the Pantheon site where tests run (e.g. `/code/wp-test-runner`) | +| `WPT_REPORT_API_KEY` | WordPress.org API key in `username:password` format | -The test runner is configured through environment variables, documented in [`.env.default`](.env.default). It shouldn't need any code modifications; in fact, please refrain from editing the scripts entirely, as it will make it easier to stay up to date. +## Running the tests -With a direct Git clone, you can: +### Scheduled runs -```bash -# Copy the default .env file. -cp .env.default .env -# Edit the .env file to define your variables. -vim .env -# Load your variables into scope. -source .env -``` - -In a CI service, you can set these environment variables through the service's web console. Importantly, the `WPT_SSH_CONNECT` environment variable determines whether the test suite is run locally or against a remote environment. - -Concurrently run tests in the same environment by appending build ids to the test directory and table prefix: - -```bash -export WPT_TEST_DIR=wp-test-runner-$TRAVIS_BUILD_NUMBER -export WPT_TABLE_PREFIX=wptests_$TRAVIS_BUILD_NUMBER\_ -``` - -Connect to a remote environment over SSH by having the CI job provision the SSH key: - -```bash -# 1. Create a SSH key pair for the controller to use -ssh-keygen -t rsa -b 4096 -C "travis@travis-ci.org" -# 2. base64 encode the private key for use with the environment variable -cat ~/.ssh/id_rsa | base64 --wrap=0 -# 3. Append id_rsa.pub to authorized_keys so the CI service can SSH in -cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys -``` - -Use a more complex SSH connection process by creating an SSH alias: - -```bash -# 1. Add the following to ~/.ssh/config to create a 'wpt' alias -Host wpt - Hostname 123.45.67.89 - User wpt - Port 1234 -# 2. Use 'wpt' wherever you might normally use a SSH connection string -ssh wpt -``` - -## Running - -The test suite runner is run in four steps. This explanation is for the local execution. - -### Requirements - -To use the Runner, the following is required (testing WordPress 6.5): - -- Server / hosting (infrastructure) with the usual configuration you use -- A database where you can test (tables will be created and destroyed several times) -- PHP 7.2+ -- MySQL 5.5.5+ / MariaDB 5.5.5+ -- NodeJS 20.x / npm 10.x / grunt -- PHP Composer -- Git, RSync, WGet, UnZip - -Test environment: - -- Writable filesystem for the entire test directory (see [#40910](https://core.trac.wordpress.org/ticket/40910)). -- Run with a non-root user, both for security and practical purposes (see [#44233](https://core.trac.wordpress.org/ticket/44233#comment:34)/[#46577](https://core.trac.wordpress.org/ticket/46577)). - -#### Database creation - -_This is an example for MySQL / MariaDB._ - -```sql -CREATE DATABASE wordpressdatabase CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci; -GRANT ALL ON wordpressdatabase.* TO 'wordpressusername'@'localhost' IDENTIFIED BY 'wordpresspassword'; -GRANT ALL ON wordpressdatabase.* TO 'wordpressusername'@'127.0.0.1' IDENTIFIED BY 'wordpresspassword'; -FLUSH PRIVILEGES; -``` - -#### NodeJS installation - -_This is an example for Debian / Ubuntu._ - -```bash -curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - -sudo apt -y install nodejs -sudo npm install -g npm@latest -nodejs --version -npm --version -``` +The workflow runs automatically on an hourly schedule. Results appear on the [WordPress.org hosting test results page](https://make.wordpress.org/hosting/test-results/). -#### PHP Composer +### Manual runs -_This is an example for Debian / Ubuntu._ +Trigger a run manually from **Actions → WordPress PHPUnit tests → Run workflow**. -```bash -curl -sS https://getcomposer.org/installer -o composer-setup.php -php composer-setup.php --install-dir=/usr/local/bin --filename=composer -composer --version -``` - -#### Git - -_This is an example for Debian / Ubuntu._ - -```bash -apt -y install git -git --version -``` - -### Installing the Test Runner +Two optional inputs are available for targeted runs: -First, download the software. This example uses `/home/wptestrunner/` folder, but set the best for this environment. +#### `test_group` (dropdown) -```bash -cd /home/wptestrunner/ -git clone https://github.com/WordPress/phpunit-test-runner.git -cd phpunit-test-runner/ -``` - -The next step will be to configure the environment. To do this, make a copy of the example file and then configure it. - -```bash -cp .env.default .env -vim .env -``` +Runs only tests tagged with a specific `@group` annotation. Useful for quickly validating a specific feature area without running the full ~29,000 test suite. Available groups include `post`, `query`, `user`, `taxonomy`, `comment`, `db`, `formatting`, `rest-api`, and others. -The content (in summary form) can be something like this: - -```bash -### -# Configuration environment variables used by the test runner -# -# # Create a copy for your local environment -# $ cp .env.default .env -# -# # Make any necessary changes to the default values -# $ vim .env -# -# # Load your variables into your environment -# $ source .env -### +Leave blank to run the full suite. -# Path to the directory where files can be prepared before being delivered to the environment. -export WPT_PREPARE_DIR=/tmp/wp-test-runner +#### `test_filter` -# Path to the directory where the WordPress develop checkout can be placed and tests can be run. -# When running tests in the same environment, set WPT_TEST_DIR to WPT_PREPARE_DIR -export WPT_TEST_DIR=/tmp/wp-test-runner +A PHPUnit `--filter` pattern matched against class and method names. More flexible than `test_group` — accepts any pattern PHPUnit's `--filter` supports. -# API key to authenticate with the reporting service in 'username:password' format. -export WPT_REPORT_API_KEY= +Examples: +- `Tests_DB` — all tests in the `Tests_DB` class +- `Tests_Options` — all options tests +- `Tests_Post_Types::test_register` — a specific method -# (Optionally) define an alternate reporting URL -export WPT_REPORT_URL= +If both inputs are set, `test_filter` takes precedence over `test_group`. -# Credentials for a database that can be written to and reset. -# WARNING!!! This database will be destroyed between tests. Only use safe database credentials. -# Please note that you must escape _or_ refrain from using # as special character in your credentials. -export WPT_DB_NAME= -export WPT_DB_USER= -export WPT_DB_PASSWORD= -export WPT_DB_HOST= +> **Note:** Partial runs still report to WordPress.org. Use these inputs for pipeline testing only, not as your regular scheduled run. -# (Optionally) set a custom table prefix to permit concurrency against the same database. -export WPT_TABLE_PREFIX=${WPT_TABLE_PREFIX-wptests_} +## Upstream sync -# (Optionally) define the PHP executable to be called -export WPT_PHP_EXECUTABLE=${WPT_PHP_EXECUTABLE-php} - -# (Optionally) define the PHPUnit command execution call. -# Use if `php phpunit.phar` can't be called directly for some reason. -export WPT_PHPUNIT_CMD= - -# (Optionally) define the command execution to remove the test directory -# Use if `rm -r` can't be called directly for some reason. -export WPT_RM_TEST_DIR_CMD= - -# SSH connection string (can also be an alias). -# Leave empty if tests are meant to run in the same environment. -export WPT_SSH_CONNECT= - -# Any options to be passed to the SSH connection -# Defaults to '-o StrictHostKeyChecking=no' -export WPT_SSH_OPTIONS= - -# SSH private key, base64 encoded. -export WPT_SSH_PRIVATE_KEY_BASE64= - -# Output logging -# Use 'verbose' to increase verbosity -export WPT_DEBUG= - -# Certificate validation -# Use 1 to validate, and 0 to not validate -export WPT_CERTIFICATE_VALIDATION=1 - -# WordPress flavor -# 0 = WordPress (simple version) -# 1 = WordPress Multisite -export WPT_FLAVOR=1 - -# Extra tests (groups) -# 0 = none -# 1 = ajax -# 2 = ms-files -# 3 = external-http -export WPT_EXTRATESTS=0 -``` - -Configure the folder where the WordPress software downloads and the database accesses will be made in order to prepare the tests. - -### Preparing the environment - -Before performing the first test, let’s update all the components. This process can be run before each test in this environment if wanted to keep it up to date, although it will depend more if it is in a production environment. +This fork tracks [WordPress/phpunit-test-runner](https://github.com/WordPress/phpunit-test-runner). To pull in upstream changes: ```bash -cd /home/wptestrunner/phpunit-test-runner/ -git pull -source .env -git checkout master +git fetch upstream +git merge upstream/master ``` -If you want to check a different branch, you can change it doing: - -```bash -git checkout example-branch -``` - -## Preparing the test - -Now there is the environment ready, run the test preparation. - -```bash -php prepare.php -``` - -The system will run a long series of installations, configurations and compilations of different elements in order to prepare the test. If warnings and warnings come out you should not worry too much, as it is quite normal. At the end of the process it will warn you if it needs something it doesn’t have. If it works, you should see something like this at the end: - -``` -Success: Prepared environment. -``` - -Now that the environment has been prepared, the next step is to run the tests for the first time. - -### Running the test - -Now that the environment is ready, let’s run the tests. To do this, execute the file that will perform it. - -```bash -php test.php -``` - -What do the symbols mean? - -`.` → Each dot means that the test has been passed correctly. - -`S` → It means the test has been skipped. This is usually because these tests are only valid in certain configurations. - -`F` → Means that the test has failed. Information about why this happened is displayed at the end. - -`E` → It means that the test has failed due to a PHP error, which can be an error, warning or notice. - -`I` → Means that the test has been marked as incomplete. - -If you follow these steps, everything should work perfectly and not make any mistakes. In case you get any error, it may be normal due to some missing adjustment or extension of PHP, among others. We recommend that you adjust the configuration until it works correctly. After all, this tool is to help you improve the optimal configuration for WordPress in that infrastructure. - -### Creating a report - -Even if the test has failed, a report will be made. The first one shows the information about our environment. Among the most important elements are the extensions that are commonly used in WordPress and some utilities that are also generally useful. - -```bash -cat /tmp/wp-test-runner/tests/phpunit/build/logs/env.json -``` - -The content of this file is somewhat similar to this: - -```bash -{ - "php_version": "7.4.5", - "php_modules": { - "bcmath": false, - "curl": "7.4.5", - "filter": "7.4.5", - "gd": false, - "libsodium": false, - "mcrypt": false, - "mod_xml": false, - "mysqli": "7.4.5", - "imagick": false, - "pcre": "7.4.5", - "xml": "7.4.5", - "xmlreader": "7.4.5", - "zlib": "7.4.5" - }, - "system_utils": { - "curl": "7.58.0 (x86_64-pc-linux-gnu) libcurl\/7.58.0 OpenSSL\/1.1.1g zlib\/1.2.11 libidn2\/2.3.0 libpsl\/0.19.1 (+libidn2\/2.0.4) nghttp2\/1.30.0 librtmp\/2.3", - "ghostscript": "", - "imagemagick": false, - "openssl": "1.1.1g 21 Apr 2020" - }, - "mysql_version": "mysql Ver 15.1 Distrib 10.4.12-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2", - "os_name": "Linux", - "os_version": "4.15.0-20-generic" -} -``` - -In addition to this report, a definitive file with all the information of what happened in the tests. This is the one that includes all the tests that are made (more than 10,000) giving information of the time that they take to be executed, problems that have arisen… - -```bash -cat /tmp/wp-test-runner/tests/phpunit/build/logs/junit.xml -``` - -At this point we can generate the reports by sending them to WordPress.org, if necessary. Even if you haven’t included the WordPress user (see below for how to create it), you can still run this file. - -```bash -php report.php -``` - -### Cleaning up the environment for other tests - -Having the tests working, all that remains is to delete all the files that have been created so that we can start over. To do this, execute the following command: - -```bash -php cleanup.php -``` - -### Automatic running - -The best way to run this test is to create a cron that runs everything. Having in mind that the tests can overlap, the best way can be using a systemd timer. - -```bash -cat > /etc/systemd/system/wordpressphpunittestrunner.service << EOF -[Unit] -Description=WordPress PHPUnit Test Runner -[Service] -Type=oneshot -ExecStart=cd /home/wptestrunner/phpunit-test-runner/ && source .env && php prepare.php && php test.php && php report.php && php cleanup.php -User=wptestrunner -Group=wptestrunner -EOF -``` - -```bash -cat > /etc/systemd/system/wordpressphpunittestrunner.timer << EOF -[Unit] -Description=WordPress PHPUnit Test Runner -[Timer] -OnCalendar=*-*-* *:*:00 -Persistent=true -[Install] -WantedBy=timers.target -EOF -``` - -```bash -systemctl daemon-reload -systemctl enable wordpressphpunittestrunner.timer -systemctl start wordpressphpunittestrunner.timer -systemctl status wordpressphpunittestrunner.timer -``` - -If you want to check how is everything working... - -```bash -journalctl -u wordpressphpunittestrunner.timer -journalctl -n 120 -u wordpressphpunittestrunner.service -``` +Conflicts will occur in `prepare.php`, `test.php`, `report.php`, `cleanup.php`, and the workflow — these files contain Pantheon-specific logic that differs from the upstream approach. Everything else should merge cleanly. ## Contributing -If you have questions about the process or run into test failures along the way, please [open an issue in the project repository](https://github.com/WordPress/phpunit-test-runner/issues) and we’ll help diagnose/get the documentation updated. Alternatively, you can also pop into the `#hosting` channel on [WordPress.org Slack](https://make.wordpress.org/chat/) for help. +For issues specific to this Pantheon fork, open an issue in this repository. For issues with the upstream test runner, open an issue in [WordPress/phpunit-test-runner](https://github.com/WordPress/phpunit-test-runner/issues). + +For questions about the WordPress hosting tests generally, visit the `#hosting` channel on [WordPress.org Slack](https://make.wordpress.org/chat/). ## License diff --git a/cleanup.php b/cleanup.php index 3fbb64f..dd76a20 100644 --- a/cleanup.php +++ b/cleanup.php @@ -1,54 +1,30 @@ trim( getenv( 'WPT_TEST_DIR' ) ) ?: '/tmp/wp-test-runner', + ); + + + + return array_merge( + $runner_configuration, + array( + // Directory configuration + 'WPT_PREPARE_DIR' => trim( getenv( 'WPT_PREPARE_DIR' ) ) ?: '/tmp/wp-test-runner', + // SSH connection configuration + 'WPT_SSH_CONNECT' => trim( getenv( 'WPT_SSH_CONNECT' ) ), + 'WPT_SSH_OPTIONS' => trim( getenv( 'WPT_SSH_OPTIONS' ) ) ?: '-o StrictHostKeyChecking=no', + // Test execution configuration + 'WPT_PHP_EXECUTABLE' => trim( getenv( 'WPT_PHP_EXECUTABLE' ) ) ?: 'php', + // Cleanup configuration + 'WPT_RM_TEST_DIR_CMD' => trim( getenv( 'WPT_RM_TEST_DIR_CMD' ) ) ?: 'rm -r ' . $runner_configuration['WPT_TEST_DIR'], + // Reporting configuration + 'WPT_REPORT_API_KEY' => trim( getenv( 'WPT_REPORT_API_KEY' ) ), + // Miscellaneous + 'WPT_DEBUG' => (bool) getenv( 'WPT_DEBUG' ), + // Pantheon-specific + 'PANTHEON_SITE_NAME' => trim( getenv( 'PANTHEON_SITE_NAME' ) ), + 'PANTHEON_SITE_ENV' => trim( getenv( 'PANTHEON_SITE_ENV' ) ), + ) + ); +} + /** * Executes a series of shell commands provided in the operations array. Each operation is logged before execution. * If any command fails (indicated by a non-zero return code), an error message is displayed. This function is diff --git a/prepare.php b/prepare.php index 3ff2226..2ed5c3b 100644 --- a/prepare.php +++ b/prepare.php @@ -1,142 +1,95 @@ > ~/.ssh/config', - 'echo "Host *.drush.in PubkeyAcceptedKeyTypes +ssh-rsa" >> ~/.ssh/config', - 'echo "StrictHostKeyChecking no" >> ~/.ssh/config', - 'terminus wp ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' -- cli info', - 'terminus connection:set ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . ' sftp', + 'echo "Host *.drush.in" >> ~/.ssh/config', + 'echo " HostKeyAlgorithms +ssh-rsa" >> ~/.ssh/config', + 'echo " PubkeyAcceptedKeyTypes +ssh-rsa" >> ~/.ssh/config', + 'echo "StrictHostKeyChecking no" >> ~/.ssh/config', ) ); } /** - * Don't validate the TLS certificate - * Useful for local environments + * Fetch Pantheon's internal DB credentials and PHP version in one terminus call. + * Using internal credentials means tests connect to localhost — no latency. */ -$certificate_validation = ''; -if( ! $WPT_CERTIFICATE_VALIDATION ) { - $certificate_validation .= ' --no-check-certificate'; -} - -/** - * Performs a series of operations to set up the test environment. This includes creating a preparation directory, - * cloning the WordPress development repository, and preparing the environment with npm. - */ -// Prepare an array of shell commands to set up the testing environment. -perform_operations( array( - - // Create the preparation directory if it doesn't exist. The '-p' flag creates intermediate directories as required. - 'mkdir -p ' . escapeshellarg( $WPT_PREPARE_DIR ), +log_message( 'Fetching Pantheon environment DB credentials and PHP version' ); +$info_php = 'echo json_encode(["host"=>getenv("DB_HOST"),"port"=>getenv("DB_PORT"),"name"=>getenv("DB_NAME"),"user"=>getenv("DB_USER"),"pass"=>getenv("DB_PASSWORD"),"php"=>PHP_VERSION]);'; +$info_json = trim( shell_exec( 'terminus remote:wp ' . $site_env . ' -- eval ' . escapeshellarg( $info_php ) . ' --skip-wordpress --quiet 2>/dev/null' ) ); +$pantheon = json_decode( $info_json, true ); - // Clone the WordPress develop repository from GitHub into the preparation directory. - // The '--depth=1' flag creates a shallow clone with a history truncated to the last commit. - 'git clone --depth=1 https://github.com/WordPress/wordpress-develop.git ' . escapeshellarg( $WPT_PREPARE_DIR ), +if ( empty( $pantheon ) || empty( $pantheon['host'] ) ) { + error_message( 'Could not retrieve Pantheon environment info. Check Terminus authentication and site/env names.' ); +} - // Change directory to the preparation directory, install npm dependencies, and build the project. - 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . '; npm install && npm run build' +$env_php_version = $pantheon['php']; +$pantheon_db_host = $pantheon['host'] . ':' . $pantheon['port']; +$php_bin = 'php' . implode( '.', array_slice( explode( '.', $env_php_version ), 0, 2 ) ); -) ); +log_message( 'Pantheon PHP: ' . $env_php_version . ' (binary: ' . $php_bin . ')' ); +log_message( 'Pantheon DB host: ' . $pantheon_db_host ); -// Log a message indicating the start of the variable replacement process for configuration. -log_message( 'Replacing variables in wp-tests-config.php' ); +if ( version_compare( $env_php_version, '7.2', '<' ) ) { + error_message( 'The test runner is not compatible with PHP < 7.2.' ); +} /** - * Reads the contents of the WordPress test configuration sample file. - * This file contains template placeholders that need to be replaced with actual values - * from environment variables to configure the WordPress test environment. + * Clone wordpress-develop directly on Pantheon's container. + * Pantheon has git and outbound HTTPS, so this avoids any rsync/SSH-key dependency. + * npm build is intentionally skipped — PHP unit tests do not require compiled JS/CSS. */ -$contents = file_get_contents( $WPT_PREPARE_DIR . '/wp-tests-config-sample.php' ); +log_message( 'Cloning wordpress-develop on Pantheon' ); +$clone_cmd = 'rm -rf ' . escapeshellarg( $test_dir ) . ' && git clone --depth=1 https://github.com/WordPress/wordpress-develop.git ' . escapeshellarg( $test_dir ) . ' 2>&1'; +perform_operations( array( + 'terminus remote:wp ' . $site_env . ' -- eval ' . escapeshellarg( 'passthru(' . var_export( $clone_cmd, true ) . ');' ) . ' --skip-wordpress', +) ); /** - * Prepares a script to log system information relevant to the testing environment. - * The script checks for the existence of the log directory and creates it if it does not exist. - * It then collects various pieces of system information including PHP version, loaded PHP modules, - * MySQL version, operating system details, and versions of key utilities like cURL and OpenSSL. - * This information is collected in an array and written to a JSON file in the log directory. - * Additionally, if running from the command line during a WordPress installation process, - * it outputs the PHP version and executable path. + * Generate wp-tests-config.php locally using Pantheon's internal DB credentials, + * then upload it to Pantheon by base64-encoding it through terminus eval. + * This avoids any file transfer over SSH/rsync. */ +log_message( 'Generating wp-tests-config.php' ); +$sample_php = 'echo base64_encode(file_get_contents(' . var_export( $test_dir . '/wp-tests-config-sample.php', true ) . '));'; +$sample_b64 = trim( shell_exec( 'terminus remote:wp ' . $site_env . ' -- eval ' . escapeshellarg( $sample_php ) . ' --skip-wordpress --quiet 2>/dev/null' ) ); + +if ( empty( $sample_b64 ) ) { + error_message( 'Could not read wp-tests-config-sample.php from Pantheon. Did the git clone succeed?' ); +} + +$contents = base64_decode( $sample_b64 ); + $system_logger = <<query("SELECT VERSION()")->fetch_row()[0]; -//\$mysqli->close(); file_put_contents( __DIR__ . '/tests/phpunit/build/logs/env.json', json_encode( \$env, JSON_PRETTY_PRINT ) ); if ( 'cli' === php_sapi_name() && defined( 'WP_INSTALLING' ) && WP_INSTALLING ) { echo PHP_EOL; @@ -227,135 +177,35 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve } EOT; -// Initialize a string that will be used to identify the database settings section in the configuration file. $logger_replace_string = '// ** Database settings ** //' . PHP_EOL; +$system_logger = $logger_replace_string . $system_logger; -// Prepend the logger script to the database settings identifier to ensure it gets included in the wp-tests-config.php file. -$system_logger = $logger_replace_string . $system_logger; - -// Define a string that will set the 'WP_PHP_BINARY' constant to the path of the PHP executable. -$php_binary_string = 'define( \'WP_PHP_BINARY\', \''. $WPT_PHP_EXECUTABLE . '\' );'; - -/** - * An associative array mapping configuration file placeholders to environment-specific values. - * This array is used in the subsequent str_replace operation to replace placeholders - * in the wp-tests-config-sample.php file with values from the environment or defaults if none are provided. - */ $search_replace = array( - 'wptests_' => trim( getenv( 'WPT_TABLE_PREFIX' ) ) ? : 'wptests_', - 'youremptytestdbnamehere' => trim( getenv( 'WPT_DB_NAME' ) ), - 'yourusernamehere' => trim( getenv( 'WPT_DB_USER' ) ), - 'yourpasswordhere' => trim( getenv( 'WPT_DB_PASSWORD' ) ), - 'localhost' => trim( getenv( 'WPT_DB_HOST' ) ), - 'define( \'WP_PHP_BINARY\', \'php\' );' => $php_binary_string, + 'wptests_' => trim( getenv( 'WPT_TABLE_PREFIX' ) ) ?: 'wptests_', + 'youremptytestdbnamehere' => $pantheon['name'], + 'yourusernamehere' => $pantheon['user'], + 'yourpasswordhere' => $pantheon['pass'], + 'localhost' => $pantheon_db_host, + 'define( \'WP_PHP_BINARY\', \'php\' );' => 'define( \'WP_PHP_BINARY\', \'' . $php_bin . '\' );', $logger_replace_string => $system_logger, ); -// Replace the placeholders in the wp-tests-config-sample.php file content with actual values. $contents = str_replace( array_keys( $search_replace ), array_values( $search_replace ), $contents ); -// Write the modified content to the wp-tests-config.php file, which will be used by the test suite. -file_put_contents( $WPT_PREPARE_DIR . '/wp-tests-config.php', $contents ); - -/** - * Determines the PHP version of the test environment to ensure the correct version of PHPUnit is installed. - * It constructs a command that prints out the PHP version in a format compatible with PHPUnit's version requirements. - */ -$php_version_cmd = $WPT_PHP_EXECUTABLE . " -r \"print PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;\""; - -/** - * If an SSH connection string is provided, the command to determine the PHP version is modified - * to execute remotely over SSH. This is required if the test environment is not the local machine. - */ -if ( ! empty( $WPT_SSH_CONNECT ) ) { - // The PHP version check command is prefixed with the SSH command, including SSH options, - // and the connection string, ensuring the command is executed on the remote machine. - $php_version_cmd = 'ssh ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' ' . escapeshellarg( $php_version_cmd ); -} - -// Initialize return value variable for the exec function call. -$retval = 0; - -/** - * Executes the constructed command to obtain the PHP version of the test environment. - * The output is stored in $env_php_version, and the return value of the command execution is stored in $retval. - */ -$env_php_version = exec( $php_version_cmd, $output, $retval ); - -// Check if the command execution was successful by inspecting the return value. -if ( $retval !== 0 ) { - // If the return value is not zero, an error occurred, and a message is logged. - error_message( 'Could not retrieve the environment PHP Version.' ); -} - -// Log the obtained PHP version for confirmation and debugging purposes. -log_message( 'Environment PHP Version: ' . $env_php_version ); - -/** - * Checks if the detected PHP version is below 7.2. - * The test runner requires PHP version 7.2 or above, and if the environment's PHP version - * is lower, it logs an error message and could terminate the script. - */ -if ( version_compare( $env_php_version, '7.2', '<' ) ) { - // Logs an error message indicating the test runner's incompatibility with PHP versions below 7.2. - error_message( 'The test runner is not compatible with PHP < 7.2.' ); -} - -/** - * Use Composer to manage PHPUnit and its dependencies. - * This allows for better dependency management and compatibility. - */ - -// Check if Composer is installed and available in the PATH. -$composer_cmd = 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . ' && '; -$retval = 0; -$composer_path = escapeshellarg( system( 'which composer', $retval ) ); - -if ( $retval === 0 ) { - - // If Composer is available, prepare the command to use the Composer binary. - $composer_cmd .= $composer_path . ' '; - -} else { - - // If Composer is not available, download the Composer phar file. - log_message( 'Local Composer not found. Downloading latest stable ...' ); - - perform_operations( array( - 'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/composer.phar' ) . ' https://getcomposer.org/composer-stable.phar', - ) ); - - // Update the command to use the downloaded Composer phar file. - $composer_cmd .= 'php composer.phar '; -} - -// Set the PHP version for Composer to ensure compatibility and update dependencies. +// Upload the generated config to Pantheon via base64 through terminus eval. +$config_b64 = base64_encode( $contents ); +$write_php = 'file_put_contents(' . var_export( $test_dir . '/wp-tests-config.php', true ) . ', base64_decode(' . var_export( $config_b64, true ) . ')); echo "Config written.\n";'; perform_operations( array( - $composer_cmd . 'config platform.php ' . escapeshellarg( $env_php_version ), - $composer_cmd . 'update', + 'terminus remote:wp ' . $site_env . ' -- eval ' . escapeshellarg( $write_php ) . ' --skip-wordpress', ) ); /** - * If an SSH connection is configured, use rsync to transfer the prepared files to the remote test environment. - * The -r option for rsync enables recursive copying to handle directory structures. - * Additional rsync options may be included for more verbose output if debugging is enabled. + * Run Composer on Pantheon to install PHPUnit and its dependencies. */ -if ( ! empty( $WPT_SSH_CONNECT ) ) { - // Initialize rsync options with recursive copying. - $rsync_options = '-r'; - - // If debug mode is set to verbose, append 'v' to rsync options for verbose output. - if ( 'verbose' === $WPT_DEBUG ) { - $rsync_options = $rsync_options . 'v'; - } - - // Perform the rsync operation with the configured options and exclude patterns. - // This operation synchronizes the test environment with the prepared files, excluding version control directories - // and other non-essential files for test execution. - perform_operations( array( - 'rsync ' . $rsync_options . ' --exclude=".git/" --exclude="node_modules/" --exclude="composer.phar" -e "ssh ' . $WPT_SSH_OPTIONS . '" ' . escapeshellarg( trailingslashit( $WPT_PREPARE_DIR ) ) . ' ' . escapeshellarg( $WPT_SSH_CONNECT . ':' . $WPT_TEST_DIR ), - ) ); -} +log_message( 'Running Composer on Pantheon' ); +perform_operations( array( + 'terminus remote:composer ' . $site_env . ' -- config platform.php ' . escapeshellarg( $env_php_version ) . ' --working-dir=' . escapeshellarg( $test_dir ), + 'terminus remote:composer ' . $site_env . ' -- update --working-dir=' . escapeshellarg( $test_dir ), +) ); -// Log a success message indicating that the environment has been prepared. log_message( 'Success: Prepared environment.' ); diff --git a/report.php b/report.php index b690f76..7e42ba0 100644 --- a/report.php +++ b/report.php @@ -1,179 +1,134 @@ trim(shell_exec("git -C " . escapeshellarg(' . var_export( $test_dir, true ) . ') . " log -1 --pretty=%H 2>/dev/null")), "msg"=>trim(shell_exec("git -C " . escapeshellarg(' . var_export( $test_dir, true ) . ') . " log -1 --pretty=%s 2>/dev/null"))]);'; +$git_json = trim( shell_exec( 'terminus remote:wp ' . $site_env . ' -- eval ' . escapeshellarg( $git_php ) . ' --skip-wordpress --quiet 2>/dev/null' ) ); +$git_info = json_decode( $git_json, true ); +$hash = $git_info['hash'] ?? ''; +$message = $git_info['msg'] ?? ''; + +// The WordPress.org hosting test API expects an SVN revision number for 'commit' (e.g. 62519). +// Fetch the current trunk revision from the SVN WebDAV endpoint using curl (no svn client needed). +$svn_xml = shell_exec( 'curl -s --max-time 10 -X PROPFIND "https://develop.svn.wordpress.org/trunk" -H "Depth: 0" 2>/dev/null' ); +preg_match( '/<[^>]+version-name[^>]*>(\d+)/dev/null' ) ); +log_message( $ls_out ?: '(empty)' ); + +foreach ( array( 'junit.xml', 'env.json', 'testdox.txt' ) as $result_file ) { + log_message( 'Fetching ' . $result_file . ' ...' ); + // Gzip before base64 so large files (junit.xml can be 5MB+) don't overwhelm the terminus connection. + $read_php = 'if(file_exists(' . var_export( $logs_dir . $result_file, true ) . ')){echo base64_encode(gzencode(file_get_contents(' . var_export( $logs_dir . $result_file, true ) . ')));}else{echo "";}'; + $encoded = trim( shell_exec( 'terminus remote:wp ' . $site_env . ' -- eval ' . escapeshellarg( $read_php ) . ' --skip-wordpress --quiet 2>/dev/null' ) ); + if ( ! empty( $encoded ) ) { + $decoded = gzdecode( base64_decode( $encoded ) ); + file_put_contents( $logs_local . $result_file, $decoded ); + log_message( 'Retrieved ' . $result_file . ' (' . strlen( $decoded ) . ' bytes)' ); + } else { + log_message( 'Warning: ' . $result_file . ' not found on Pantheon.' ); + } } /** - * Sets the options for the rsync command based on the debug mode. - * Initializes the rsync options with the recursive flag. If the debug mode is set to 'verbose', - * appends the 'v' flag to the rsync options to enable verbose output during the rsync operation, - * providing more detailed information about the file transfer process. + * Process and upload results. */ -$rsync_options = '-r'; +log_message( 'Processing junit.xml' ); -if ( 'verbose' === $WPT_DEBUG ) { - $rsync_options = $rsync_options . 'v'; +if ( ! file_exists( $logs_local . 'junit.xml' ) ) { + error_message( 'junit.xml not found — test run did not complete (probable PHP crash). This is a hard failure.' ); } -/** - * Constructs the rsync command for executing the synchronization of junit.xml files. - * Concatenates the rsync command with the previously defined options and the source and - * destination paths. The destination path is sanitized for shell execution. This command is - * then passed to the `perform_operations` function, which executes the command to synchronize - * the junit.xml files from the source to the destination directory. - */ -$junit_exec = 'rsync ' . $rsync_options . ' ' . $junit_location . ' ' . escapeshellarg( $WPT_PREPARE_DIR ); -perform_operations( array( - $junit_exec, -) ); - -/** - * Processes and uploads the junit.xml file. - * First, a log message is recorded to indicate the start of processing the junit.xml file. - * Then, the contents of the junit.xml file are read from the prepared directory into a string. - * This XML string is then passed to a function that processes the XML data, presumably to prepare - * it for upload or to extract relevant test run information. - */ -log_message( 'Processing and uploading junit.xml' ); -$xml = file_get_contents( $WPT_PREPARE_DIR . '/junit.xml' ); +$xml = file_get_contents( $logs_local . 'junit.xml' ); $results = process_junit_xml( $xml ); -/** - * Retrieves environment details from a JSON file or generates them if not available. - * Initializes the environment details string. If an 'env.json' file exists in the prepared - * directory, its contents are read into the environment details string. If the file doesn't - * exist but the prepared directory is the same as the test directory, the environment details - * are generated by calling a function that retrieves these details, then encoded into JSON format. - */ $env = ''; -if ( file_exists( $WPT_PREPARE_DIR . '/env.json' ) ) { - $env = file_get_contents( $WPT_PREPARE_DIR . '/env.json' ); -} elseif ( $WPT_PREPARE_DIR === $WPT_TEST_DIR ) { - $env = json_encode( get_env_details(), JSON_PRETTY_PRINT ); +if ( file_exists( $logs_local . 'env.json' ) ) { + $env = file_get_contents( $logs_local . 'env.json' ); + log_message( 'env.json loaded' ); } /** - * Attempts to upload test results if an API key is available, otherwise logs the results locally. - * Checks if an API key for reporting is present. If so, it attempts to upload the test results - * using the `upload_results` function and processes the HTTP response. A success message is logged - * if the upload is successful, indicated by a 20x HTTP status code. If the upload fails, an error - * message is logged along with the HTTP status. If no API key is provided, it logs the test results - * and environment details locally. + * Write a GHA step summary with key run info. */ -if( ! empty( $WPT_REPORT_API_KEY ) ) { +$summary_file = getenv( 'GITHUB_STEP_SUMMARY' ); +if ( $summary_file ) { + $env_data = $env ? json_decode( $env, true ) : array(); + $summary = "## WordPress PHPUnit Test Results\n\n"; + $summary .= '| | |' . "\n" . '|---|---|' . "\n"; + $summary .= '| **Site** | ' . $PANTHEON_SITE_NAME . '.' . $PANTHEON_SITE_ENV . " |\n"; + $summary .= '| **Revision** | ' . ( $rev ?: 'unknown' ) . " |\n"; + $summary .= '| **Commit** | ' . ( $message ?: 'unknown' ) . " |\n"; + $summary .= '| **PHP** | ' . ( $env_data['php_version'] ?? 'unknown' ) . " |\n"; + $summary .= '| **MySQL** | ' . ( $env_data['mysql_version'] ?? 'unknown' ) . " |\n"; + file_put_contents( $summary_file, $summary, FILE_APPEND ); +} - // Upload the results and capture the HTTP status and response body - list( $http_status, $response_body ) = upload_results( $results, $rev, $message, $env, $WPT_REPORT_API_KEY ); +log_message( 'Uploading results' ); - // Decode the JSON response body - $response = json_decode( $response_body, true ); - if ( 20 == substr( $http_status, 0, 2 ) ) { +if ( ! empty( $runner_vars['WPT_REPORT_API_KEY'] ) ) { - // Construct and log a success message with a link if provided in the response - $message = 'Results successfully uploaded'; - $message .= isset( $response['link'] ) ? ': ' . $response['link'] : ''; - log_message( $message ); + list( $http_status, $response_body ) = upload_results( $results, $rev, $message, $env, $runner_vars['WPT_REPORT_API_KEY'] ); + $response = json_decode( $response_body, true ); + if ( 20 == substr( $http_status, 0, 2 ) ) { + $upload_msg = 'Results successfully uploaded'; + $upload_msg .= isset( $response['link'] ) ? ': ' . $response['link'] : ''; + log_message( $upload_msg ); + if ( $summary_file ) { + $link_line = isset( $response['link'] ) ? '| **Results** | [View on WordPress.org](' . $response['link'] . ") |\n" : ''; + file_put_contents( $summary_file, $link_line, FILE_APPEND ); + } } else { - - // Construct and log an error message with additional details if provided in the response - $message = 'Error uploading results'; - $message .= isset( $response['message'] ) ? ': ' . $response['message'] : ''; - $message .= ' (HTTP status ' . (int) $http_status . ')'; - error_message( $message ); - + $err = 'Error uploading results'; + $err .= isset( $response['message'] ) ? ': ' . $response['message'] : ''; + $err .= ' (HTTP ' . (int) $http_status . ')'; + error_message( $err ); } } else { - - // Log the test results and environment details locally if no API key is provided - log_message( '[+] TEST RESULTS' . "\n\n" . $results. "\n\n" ); + log_message( 'No API key — logging results locally only' ); + log_message( '[+] TEST RESULTS' . "\n\n" . $results . "\n\n" ); log_message( '[+] ENVIRONMENT' . "\n\n" . $env . "\n\n" ); - } diff --git a/test.php b/test.php index f99379f..0dc620c 100644 --- a/test.php +++ b/test.php @@ -1,48 +1,29 @@