diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e03133f21e..763ca18f286 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -194,9 +194,9 @@ jobs: env: RELEASE_TAG: ${{ github.ref_name }} ARTIFACT_NAME: ${{ github.ref_name == 'nightly' && 'woocommerce-trunk-nightly.zip' || 'woocommerce.zip' }} - WP_ENV_CONFIG_PATH: ${{ matrix.projectPath }} - working-directory: ${{ matrix.projectPath }} - run: node ./github/workflows/scripts/override-wp-env-plugins.js + # band-aid to get the path to wp-env.json for blocks e2e tests, until they're migrated to plugins/woocommerce + WP_ENV_CONFIG_PATH: ${{ github.workspace }}/${{ matrix.testEnv.start == 'env:start:blocks' && 'plugins/woocommerce-blocks' || matrix.projectPath }} + run: node .github/workflows/scripts/override-wp-env-plugins.js - name: 'Start Test Environment' id: 'prepare-test-environment' diff --git a/.github/workflows/scripts/override-wp-env-plugins.js b/.github/workflows/scripts/override-wp-env-plugins.js index c35363446a0..33f05c9569b 100644 --- a/.github/workflows/scripts/override-wp-env-plugins.js +++ b/.github/workflows/scripts/override-wp-env-plugins.js @@ -20,24 +20,50 @@ if ( ! WP_ENV_CONFIG_PATH ) { const artifactUrl = `https://github.com/woocommerce/woocommerce/releases/download/${ RELEASE_TAG }/${ ARTIFACT_NAME }`; -const testEnvPlugins = { - env: { - tests: { - plugins: [], - }, - }, -}; -const data = fs.readFileSync( `${ WP_ENV_CONFIG_PATH }/.wp-env.json`, 'utf8' ); +const configPath = `${ WP_ENV_CONFIG_PATH }/.wp-env.json`; +console.log( `Reading ${ configPath }` ); +const data = fs.readFileSync( configPath, 'utf8' ); const wpEnvConfig = JSON.parse( data ); -testEnvPlugins.env.tests.plugins = wpEnvConfig.env.tests.plugins; -const currentDirEntry = testEnvPlugins.env.tests.plugins.indexOf( '.' ); +const overrideConfig = {}; -if ( currentDirEntry !== -1 ) { - testEnvPlugins.env.tests.plugins[ currentDirEntry ] = artifactUrl; +if ( wpEnvConfig.plugins ) { + overrideConfig.plugins = wpEnvConfig.plugins; } +if ( wpEnvConfig.env?.tests?.plugins ) { + overrideConfig.env = { + tests: { + plugins: wpEnvConfig.env.tests.plugins, + }, + }; +} + +const entriesToReplace = [ '.', '../woocommerce' ]; + +for ( const entry of entriesToReplace ) { + // Search and replace in root plugins + let found = overrideConfig.plugins.indexOf( entry ); + if ( found >= 0 ) { + console.log( + `Replacing ${ entry } with ${ artifactUrl } in root plugins` + ); + overrideConfig.plugins[ found ] = artifactUrl; + } + + // Search and replace in test env plugins + found = overrideConfig.env?.tests?.plugins?.indexOf( entry ); + if ( found >= 0 ) { + console.log( + `Replacing ${ entry } with ${ artifactUrl } in env.tests.plugins` + ); + overrideConfig.env.tests.plugins[ found ] = artifactUrl; + } +} + +const overrideConfigPath = `${ WP_ENV_CONFIG_PATH }/.wp-env.override.json`; +console.log( `Saving ${ overrideConfigPath }` ); fs.writeFileSync( - `${ WP_ENV_CONFIG_PATH }/.wp-env.override.json`, - JSON.stringify( testEnvPlugins, null, 2 ) + overrideConfigPath, + JSON.stringify( overrideConfig, null, 2 ) );