Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a CI job for WPCloud testing of wpcomsh. #39258

Open
wants to merge 22 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3a57a51
Added a CI job for WPCloud testing of wpcomsh.
zinigor Sep 5, 2024
2ab2c4a
Add pnpm and install.
zinigor Sep 5, 2024
0d40db9
Testing WPCloud on a new test site for jetpackisbestpack.
zinigor Oct 7, 2024
a8da4b4
Merge branch 'trunk' into add/wpcomsh-wpcloud-testing
zinigor Oct 7, 2024
a3a5533
Temporarily marking wpcomsh as always changed.
zinigor Oct 7, 2024
8b74cdf
Merge branch 'trunk' into add/wpcomsh-wpcloud-testing
zinigor Oct 23, 2024
4df8ed7
Added transferring of tests.
zinigor Oct 23, 2024
b102738
Added DB password slash escaping.
zinigor Oct 23, 2024
27bbd07
changelog
zinigor Oct 23, 2024
aad27e3
Added a mock for get_option_and_ensure_autoload.
zinigor Oct 23, 2024
9e892e4
Added a missing cache expulsion function.
zinigor Oct 24, 2024
dfb7439
Removed set -x from test installer.
zinigor Oct 24, 2024
bf302d5
Using pnpm to not bother with linking binaries.
zinigor Oct 24, 2024
8f1f194
Added a build step.
zinigor Oct 24, 2024
df0ed81
Merge branch 'trunk' into add/wpcomsh-wpcloud-testing
zinigor Oct 25, 2024
3618211
Created a separate job to avoid re-building on a re-run, h/t @anomiex.
zinigor Oct 25, 2024
510482f
Added cache saving and restoring, moved if to parent job.
zinigor Oct 25, 2024
747555d
Added the before file.
zinigor Oct 25, 2024
cdff320
Trying with instead of .
zinigor Oct 25, 2024
a60df09
Fixing var schema.
zinigor Oct 25, 2024
4f4f451
Merge branch 'trunk' into add/wpcomsh-wpcloud-testing
zinigor Nov 21, 2024
f2ff12f
Merge branch 'trunk' into add/wpcomsh-wpcloud-testing
zinigor Dec 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions .github/workflows/wpcloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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: 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: |
CHANGED="$(EXTRA=test .github/files/list-changed-projects.sh)"

# 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
if: steps.changed.outputs.wpcomsh == 'true'
run: |
echo "::group::Intializing"

mkdir -vp ~/.ssh/
chmod -v 700 ~/.ssh

touch ~/.ssh/id_site
touch ~/.ssh/known_hosts
chmod 600 ~/.ssh/id_site
chmod 600 ~/.ssh/known_hosts
echo "$SSH_KEY" > ~/.ssh/id_site
echo "wrote ~/.ssh/id_site"
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
echo "wrote ~/.ssh/known_hosts"

echo "::endgroup::"

echo "::group::Installing and building wpcomsh"
pnpm jetpack build plugins/wpcomsh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably need to include --deps, and adding -v would probably be helpful in case anything fails.

Personally, I'd do the build as a separate step, if not as a separate job to make re-runs not have to re-build (cf. #32686).

echo "::endgroup::"

echo "::group::Transferring wpcomsh to the testing server"
pnpm jetpack rsync wpcomsh [email protected]:~/htdocs/wp-content/mu-plugins
scp -r projects/plugins/wpcomsh/bin [email protected]:/srv/htdocs/wp-content/mu-plugins/wpcomsh
scp -r projects/plugins/wpcomsh/tests [email protected]:/srv/htdocs/wp-content/mu-plugins/wpcomsh/
scp projects/plugins/wpcomsh/phpunit.xml.dist [email protected]:/srv/htdocs/wp-content/mu-plugins/wpcomsh/

echo "::engroup::"

echo "::group::execution"
ssh -i ~/.ssh/id_site [email protected] "~/htdocs/github-action-handler.sh" || CODE=$?
echo "::endgroup::"

echo "::group::teardown"
rm -rvf ~/.ssh/
echo "::endgroup::"
echo "Exiting with exit code $CODE"
exit $CODE
env:
SSH_KEY: ${{ secrets.UPDATEJETPACKSTAGING_SSH_KEY }}
SSH_KNOWN_HOSTS: ${{ secrets.UPDATEJETPACKSTAGING_SSH_KNOWN_HOSTS }}
4 changes: 2 additions & 2 deletions projects/plugins/wpcomsh/bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ else
fi
WP_TESTS_TAG="tags/$LATEST_VERSION"
fi
set -ex
set -e

install_wp() {

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed a database password escaping issue when installing tests.
20 changes: 16 additions & 4 deletions projects/plugins/wpcomsh/tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 10 in projects/plugins/wpcomsh/tests/bootstrap.php

View workflow job for this annotation

GitHub Actions / Static analysis

TypeError PhanCoalescingNeverNull Using non-null getenv('WP_CONTENT_DIR') of type false|string as the left hand side of a null coalescing (??) operation. The right hand side may be unnecessary.
$wp_branch = getenv( 'WP_BRANCH' );

if ( ! $_tests_dir ) {
if ( $wp_branch ) {
Expand All @@ -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
Expand All @@ -53,5 +54,16 @@
}
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() {

Check failure on line 63 in projects/plugins/wpcomsh/tests/bootstrap.php

View workflow job for this annotation

GitHub Actions / Static analysis

RedefineError PhanRedefineFunction Function wp_cache_flush_runtime defined at tests/bootstrap.php:63 was previously defined at /home/runner/work/jetpack/jetpack/vendor/php-stubs/wordpress-stubs/wordpress-stubs.php:96276
return wp_cache_flush();
}
}

// Start up the WP testing environment.
require_once $_tests_dir . '/includes/bootstrap.php';
13 changes: 13 additions & 0 deletions projects/plugins/wpcomsh/tests/lib/mocks/class-jetpack-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}
Loading