Skip to content

Commit

Permalink
Update plugins config
Browse files Browse the repository at this point in the history
  • Loading branch information
mukeshpanchal27 committed Feb 20, 2024
1 parent 2a0c800 commit df66f19
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 45 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/deploy-standalone-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,16 @@ jobs:
echo "directory=$(node ./bin/plugin/cli.js get-plugin-dir --slug=${{ inputs.slug }})" >> $GITHUB_OUTPUT
- name: Get plugin version
id: get-version
if: ${{ github.event_name == 'workflow_dispatch' && steps.get-plugin-directory.outputs.directory == 'build' }}
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
echo "version=$(node ./bin/plugin/cli.js get-plugin-version --slug=${{ inputs.slug }})" >> $GITHUB_OUTPUT
- name: Set matrix
id: set-matrix
run: |
if ${{ github.event_name == 'workflow_dispatch' }}; then
result=$(echo "${{ steps.get-version.outputs.version }}" | awk '/^(\*|[0-9]+(\.[0-9]+){0,2}(-[a-zA-Z0-9.]+)?)$/ {print "Matched"}')
if ${{ steps.get-plugin-directory.outputs.directory == 'plugins' }}; then
# Set the manual input values in JSON format for use in the matrix for plugins.
echo "matrix={\"include\":[{\"slug\":\"${{ inputs.slug }}\",\"directory\":\"${{ steps.get-plugin-directory.outputs.directory }}\",\"dry-run\":\"true\"}]}" >> $GITHUB_OUTPUT
elif [[ -n "$result" ]]; then
# Set the manual input values in JSON format for use in the matrix for modules.
if [[ -n "$result" ]]; then
# Set the manual input values in JSON format for use in the matrix.
echo "matrix={\"include\":[{\"slug\":\"${{ inputs.slug }}\",\"version\":\"${{ steps.get-version.outputs.version }}\",\"directory\":\"${{ steps.get-plugin-directory.outputs.directory }}\",\"dry-run\":\"true\"}]}" >> $GITHUB_OUTPUT
else
echo "The ${{ inputs.slug }} module slug is missing in the file plugins.json."
Expand All @@ -70,7 +67,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: ([.modules | to_entries[] | {name:.key,slug:.value.slug,version:.value.version,directory:"build","dry-run":true }] + [.plugins[] | {slug:. , directory:"plugins", "dry-run":true}])}' plugins.json)" >> $GITHUB_OUTPUT
echo "matrix=$(jq -c '{include: ([.modules | to_entries[] | {name:.key,slug:.value.slug,version:.value.version,directory:"build","dry-run":true }] + [.plugins | to_entries[] | {name:.key,slug:.value.slug,version:.value.version,directory:"plugins","dry-run":true }])}' plugins.json)" >> $GITHUB_OUTPUT
fi
deploy:
name: Deploy Plugin
Expand All @@ -89,6 +86,7 @@ jobs:
- name: Install npm dependencies
run: npm ci
- name: Building standalone plugins
if: ${{ matrix.directory != 'plugins' }}
run: npm run build-plugins
- name: Deploy Standalone Plugin - ${{ matrix.slug }}
uses: 10up/action-wordpress-plugin-deploy@stable
Expand Down
8 changes: 5 additions & 3 deletions bin/plugin/commands/get-plugin-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ function doRunGetPluginDir( settings ) {

const plugins = pluginsConfig.plugins;
if ( plugins ) {
for ( const plugin in plugins ) {
if ( plugins[ plugin ] && settings.slug === plugins[ plugin ] ) {
for ( const pluginDir in plugins ) {
const pluginVersion = plugins[ pluginDir ]?.version;
const pluginSlug = plugins[ pluginDir ]?.slug;
if ( pluginVersion && pluginSlug && settings.slug === pluginSlug ) {
return log( 'plugins' );
}
}
}

throw Error(
`The "${ settings.slug }" module slug is missing in the file "${ pluginsFile }".`
`The "${ settings.slug }" module/plugin slug is missing in the file "${ pluginsFile }".`
);
}
29 changes: 18 additions & 11 deletions bin/plugin/commands/get-plugin-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,29 @@ function doRunGetPluginVersion( settings ) {
);
}

const plugins = pluginsConfig.modules;
if ( ! plugins ) {
throw Error(
`File at "${ pluginsFile }" parsed, but the modules are missing, or they are misspelled.`
);
const stPlugins = pluginsConfig.modules;
if ( stPlugins ) {
for ( const moduleDir in stPlugins ) {
const pluginVersion = stPlugins[ moduleDir ]?.version;
const pluginSlug = stPlugins[ moduleDir ]?.slug;
if ( pluginVersion && pluginSlug && settings.slug === pluginSlug ) {
return log( pluginVersion );
}
}
}

for ( const moduleDir in plugins ) {
const pluginVersion = plugins[ moduleDir ]?.version;
const pluginSlug = plugins[ moduleDir ]?.slug;
if ( pluginVersion && pluginSlug && settings.slug === pluginSlug ) {
return log( pluginVersion );
const plugins = pluginsConfig.plugins;
if ( plugins ) {
for ( const moduleDir in plugins ) {
const pluginVersion = plugins[ moduleDir ]?.version;
const pluginSlug = plugins[ moduleDir ]?.slug;
if ( pluginVersion && pluginSlug && settings.slug === pluginSlug ) {
return log( pluginVersion );
}
}
}

throw Error(
`The "${ settings.slug }" module slug is missing in the file "${ pluginsFile }".`
`The "${ settings.slug }" module/plugin slug is missing in the file "${ pluginsFile }".`
);
}
62 changes: 39 additions & 23 deletions bin/plugin/commands/test-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,32 +480,48 @@ function doRunStandalonePluginTests( settings ) {

// Append plugins into array.
const plugins = pluginsConfig.plugins;
if ( plugins && Object.keys( plugins ).length > 0 ) {
plugins.forEach( ( plugin ) => {
// Copy plugins to build for testing.
try {
fs.copySync(
`${ settings.pluginsDir }${ plugin }/`,
`${ settings.builtPluginsDir }${ plugin }/`,
{
overwrite: true,
}
);
log( formats.success( `Copied plugin "${ plugin }".\n` ) );
builtPlugins = builtPlugins.concat( plugin );
} catch ( e ) {
log(
formats.error(
`Error copying plugin "${ plugin }". ${ e }`
)
);
if ( ! plugins ) {
log(
formats.error(
'The given plugin configuration is invalid, the plugins are missing, or they are misspelled.'
)
);

// Return with exit code 1 to trigger a failure in the test pipeline.
process.exit( 1 );
}
} );
// 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 = builtPlugins.concat(
Object.keys( plugins )
.filter( ( item ) => {
try {
fs.copySync(
`${ settings.pluginsDir }${ plugins[ item ].slug }/`,
`${ settings.builtPluginsDir }${ plugins[ item ].slug }/`,
{
overwrite: true,
}
);
log(
formats.success(
`Copied plugin "${ plugins[ item ].slug }".\n`
)
);
return true;
} catch ( e ) {
// Handle the error appropriately
log(
formats.error(
`Error copying plugin "${ plugins[ item ].slug }": ${ e.message }`
)
);
return false;
}
} )
.map( ( item ) => plugins[ item ].slug )
);

// For each built plugin, copy the test assets.
builtPlugins.forEach( ( plugin ) => {
log(
Expand Down
7 changes: 6 additions & 1 deletion plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@
"version": "1.0.5"
}
},
"plugins": []
"plugins": {
"auto-sizes": {
"slug": "auto-sizes",
"version": "1.0.1"
}
}
}

0 comments on commit df66f19

Please sign in to comment.