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

Introduce plugins folder for standalone plugins #948

Merged
merged 11 commits into from
Jan 19, 2024
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/docs export-ignore
/tests export-ignore
/plugin-tests export-ignore
/plugins export-ignore

/*.DS_store export-ignore
/.DS_store? export-ignore
Expand Down
22 changes: 19 additions & 3 deletions .github/workflows/deploy-standalone-plugins.yml
Original file line number Diff line number Diff line change
@@ -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
mukeshpanchal27 marked this conversation as resolved.
Show resolved Hide resolved
release:
types: [published]
workflow_dispatch:
Expand Down Expand Up @@ -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
mukeshpanchal27 marked this conversation as resolved.
Show resolved Hide resolved
fi
deploy:
name: Deploy Plugin
Expand All @@ -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
mukeshpanchal27 marked this conversation as resolved.
Show resolved Hide resolved
SLUG: ${{ matrix.slug }}
VERSION: ${{ matrix.version }}
BUILD_DIR: ./build/${{ matrix.slug }}
Expand Down
11 changes: 10 additions & 1 deletion bin/plugin/commands/build-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 are missing, or they are misspelled.'
)
);
return;
}
for ( const moduleDir in plugins ) {
const pluginVersion = plugins[ moduleDir ]?.version;
const pluginSlug = plugins[ moduleDir ]?.slug;
Expand Down
14 changes: 12 additions & 2 deletions bin/plugin/commands/get-plugin-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 are missing, or they are misspelled.`
);
}

for ( const moduleDir in plugins ) {
const pluginVersion = plugins[ moduleDir ]?.version;
const pluginSlug = plugins[ moduleDir ]?.slug;
Expand Down
21 changes: 18 additions & 3 deletions bin/plugin/commands/test-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,14 @@ function doRunStandalonePluginTests( settings ) {
);
}

const pluginsJsonFileContentAsJson = JSON.parse( pluginsJsonFileContent );
const pluginsJsonFileContentAsEntireJsonData = 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 pluginsJsonFileContentAsEntireJsonData ||
0 === Object.keys( pluginsJsonFileContentAsEntireJsonData ).length
) {
log(
formats.error(
Expand All @@ -430,6 +432,19 @@ function doRunStandalonePluginTests( settings ) {
process.exit( 1 );
}

const pluginsJsonFileContentAsJson =
pluginsJsonFileContentAsEntireJsonData.modules;
if ( ! pluginsJsonFileContentAsJson ) {
mukeshpanchal27 marked this conversation as resolved.
Show resolved Hide resolved
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 )
.filter( ( item ) => {
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<file>./admin</file>
<file>./load.php</file>
<file>./modules</file>
<file>./plugins</file>
<file>./server-timing</file>
<file>./tests</file>

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ parameters:
- load.php
- module-i18n.php
- modules/
- plugins/
- server-timing/
- tests/
- uninstall.php
Expand Down
17 changes: 10 additions & 7 deletions plugins.json
Original file line number Diff line number Diff line change
@@ -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": []
}
Empty file added plugins/.gitkeep
Empty file.