diff --git a/.github/workflows/deploy-standalone-plugins.yml b/.github/workflows/deploy-standalone-plugins.yml index 0515b03bef..e9fb36e098 100644 --- a/.github/workflows/deploy-standalone-plugins.yml +++ b/.github/workflows/deploy-standalone-plugins.yml @@ -1,6 +1,18 @@ name: Deploy standalone plugins to WordPress.org on: + # TODO The pull_request will be removed once the workflow is tested. + pull_request: + branches: + - trunk + - 'release/**' + - 'feature/**' + paths: + - '.github/workflows/deploy-standalone-plugins.yml' + types: + - opened + - reopened + - synchronize release: types: [published] workflow_dispatch: @@ -50,7 +62,7 @@ jobs: # for use in the matrix. # The "dry-run" parameter is included here to set the deployment mode. # When running the manual (workflow_dispatch) workflow, this value will be set from manual input type. - echo "matrix="$(jq -c '{include:[keys[] as $k | {name:$k,slug:.[$k].slug,version:.[$k].version,"dry-run":false }]}' plugins.json) >> $GITHUB_OUTPUT + echo "matrix="$(jq -c '{include:[.modules | to_entries[] | {name:.key,slug:.value.slug,version:.value.version,"dry-run":true }]}' plugins.json) >> $GITHUB_OUTPUT fi deploy: name: Deploy Plugin @@ -75,8 +87,12 @@ jobs: with: dry-run: ${{ matrix.dry-run }} env: - SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} - SVN_USERNAME: ${{ secrets.SVN_USERNAME }} + # TODO Once the workflow is tested, we will remove the comment and use the secret SVN access. + #SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} + #SVN_USERNAME: ${{ secrets.SVN_USERNAME }} + # TODO Once the workflow is tested, we will remove this test credential. + SVN_PASSWORD: SVN_PASSWORD + SVN_USERNAME: SVN_USERNAME SLUG: ${{ matrix.slug }} VERSION: ${{ matrix.version }} BUILD_DIR: ./build/${{ matrix.slug }} diff --git a/bin/plugin/commands/build-plugins.js b/bin/plugin/commands/build-plugins.js index 0564547c6d..7ad689c409 100644 --- a/bin/plugin/commands/build-plugins.js +++ b/bin/plugin/commands/build-plugins.js @@ -24,7 +24,16 @@ exports.handler = async () => { } try { - const plugins = JSON.parse( jsonString ); + const pluginsConfig = JSON.parse( jsonString ); + const plugins = pluginsConfig.modules; + if ( ! plugins ) { + log( + formats.error( + 'The given module configuration is invalid, the modules is missing, or they are misspelled.' + ) + ); + return; + } for ( const moduleDir in plugins ) { const pluginVersion = plugins[ moduleDir ]?.version; const pluginSlug = plugins[ moduleDir ]?.slug; diff --git a/bin/plugin/commands/get-plugin-version.js b/bin/plugin/commands/get-plugin-version.js index ad04defe48..f898dd0adc 100644 --- a/bin/plugin/commands/get-plugin-version.js +++ b/bin/plugin/commands/get-plugin-version.js @@ -56,15 +56,25 @@ function doRunGetPluginVersion( settings ) { ); } - const plugins = JSON.parse( pluginsFileContent ); + const pluginsConfig = JSON.parse( pluginsFileContent ); // Check for valid and not empty object resulting from plugins JSON file parse. - if ( 'object' !== typeof plugins || 0 === Object.keys( plugins ).length ) { + if ( + 'object' !== typeof pluginsConfig || + 0 === Object.keys( pluginsConfig ).length + ) { throw Error( `File at "${ pluginsFile }" parsed, but detected empty/non valid JSON object.` ); } + const plugins = pluginsConfig.modules; + if ( ! plugins ) { + throw Error( + `File at "${ pluginsFile }" parsed, but the modules is missing, or they are misspelled.` + ); + } + for ( const moduleDir in plugins ) { const pluginVersion = plugins[ moduleDir ]?.version; const pluginSlug = plugins[ moduleDir ]?.slug; diff --git a/bin/plugin/commands/test-plugins.js b/bin/plugin/commands/test-plugins.js index 08a7b85a6b..9cf4578070 100644 --- a/bin/plugin/commands/test-plugins.js +++ b/bin/plugin/commands/test-plugins.js @@ -413,12 +413,12 @@ function doRunStandalonePluginTests( settings ) { ); } - const pluginsJsonFileContentAsJson = JSON.parse( pluginsJsonFileContent ); + const pluginsConfig = JSON.parse( pluginsJsonFileContent ); // Check for valid and not empty object resulting from plugins JSON file parse. if ( - 'object' !== typeof pluginsJsonFileContentAsJson || - 0 === Object.keys( pluginsJsonFileContentAsJson ).length + 'object' !== typeof pluginsConfig || + 0 === Object.keys( pluginsConfig ).length ) { log( formats.error( @@ -430,24 +430,36 @@ function doRunStandalonePluginTests( settings ) { process.exit( 1 ); } + const plugins = pluginsConfig.modules; + if ( ! plugins ) { + log( + formats.error( + 'The given module configuration is invalid, the modules are missing, or they are misspelled.' + ) + ); + + // Return with exit code 1 to trigger a failure in the test pipeline. + process.exit( 1 ); + } + // Create an array of plugins from entries in plugins JSON file. - builtPlugins = Object.keys( pluginsJsonFileContentAsJson ) + builtPlugins = Object.keys( plugins ) .filter( ( item ) => { if ( ! fs.pathExistsSync( - `${ settings.builtPluginsDir }${ pluginsJsonFileContentAsJson[ item ].slug }` + `${ settings.builtPluginsDir }${ plugins[ item ].slug }` ) ) { log( formats.error( - `Built plugin path "${ settings.builtPluginsDir }${ pluginsJsonFileContentAsJson[ item ].slug }" not found, skipping and removing from plugin list` + `Built plugin path "${ settings.builtPluginsDir }${ plugins[ item ].slug }" not found, skipping and removing from plugin list` ) ); return false; } return true; } ) - .map( ( item ) => pluginsJsonFileContentAsJson[ item ].slug ); + .map( ( item ) => plugins[ item ].slug ); // For each built plugin, copy the test assets. builtPlugins.forEach( ( plugin ) => { diff --git a/load.php b/load.php index 5d1d9970d9..19afebabdb 100644 --- a/load.php +++ b/load.php @@ -426,7 +426,7 @@ function perflab_maybe_remove_object_cache_dropin() { $dropin_path = WP_CONTENT_DIR . '/object-cache.php'; $dropin_backup_path = WP_CONTENT_DIR . '/object-cache-plst-orig.php'; - /** + /* * If there is an object-cache-plst-orig.php file, restore it and * override the Performance Lab file. This is only relevant for * backward-compatibility with previous Performance Lab versions diff --git a/plugins.json b/plugins.json index ab4f2323c2..b171fa5cda 100644 --- a/plugins.json +++ b/plugins.json @@ -1,10 +1,13 @@ { - "images/dominant-color-images": { - "slug": "dominant-color-images", - "version": "1.0.1" + "modules": { + "images/dominant-color-images": { + "slug": "dominant-color-images", + "version": "1.0.1" + }, + "images/webp-uploads": { + "slug": "webp-uploads", + "version": "1.0.5" + } }, - "images/webp-uploads": { - "slug": "webp-uploads", - "version": "1.0.5" - } + "plugins": ["dominant-color-images", "webp-uploads"] }