From 3ec049c967938b4eaaec782c4064126e33960016 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Wed, 7 May 2025 12:34:03 +0100 Subject: [PATCH 1/9] Check new WC variables --- tasks/deploy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/deploy.js b/tasks/deploy.js index a7d8fd4..e83b603 100644 --- a/tasks/deploy.js +++ b/tasks/deploy.js @@ -44,7 +44,7 @@ function validateEnvVariables () { let variables = ['GITHUB_API_KEY', 'GITHUB_USERNAME', 'SAKE_PRE_RELEASE_PATH'] if (sake.config.deploy.type === 'wc') { - variables = variables.concat(['WC_CONSUMER_KEY', 'WC_CONSUMER_SECRET']) + variables = variables.concat(['WC_USERNAME', 'WC_APPLICATION_PASSWORD']) } if (sake.config.deploy.type === 'wp') { From 9dff11a597c727ace97c3a799283fc84d1dc2ec1 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Wed, 7 May 2025 12:34:12 +0100 Subject: [PATCH 2/9] Propagate up exit --- bin/sake.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/sake.js b/bin/sake.js index b8e856d..4911af4 100755 --- a/bin/sake.js +++ b/bin/sake.js @@ -27,5 +27,9 @@ const args = [ '--cwd', process.cwd() ])) -// fire up gulp -spawn('node', args, { cwd: process.cwd(), stdio: 'inherit' }) +const child = spawn('node', args, { cwd: process.cwd(), stdio: 'inherit' }) + +// we need the exit code of the child process to propagate up to the main process +child.on('exit', function(code) { + process.exitCode = code +}) From 880b09f7c3d3f294e78d0812821ef3de70d9c297 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Wed, 7 May 2025 12:34:18 +0100 Subject: [PATCH 3/9] Add helpers --- helpers/arguments.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 helpers/arguments.js diff --git a/helpers/arguments.js b/helpers/arguments.js new file mode 100644 index 0000000..99cadfd --- /dev/null +++ b/helpers/arguments.js @@ -0,0 +1,30 @@ +import minimist from 'minimist' + +/** + * Determines if the command is being run in "non-interactive mode". If true, we should never present with prompts. + * @returns {boolean} + */ +export function isNonInteractive() +{ + return process.argv.includes('--non-interactive'); +} + +/** + * Whether this is a dry run deployment. If true, the deploy to WooCommerce will not actually happen. + * @returns {boolean} + */ +export function isDryRunDeploy() +{ + return process.argv.includes('--dry-run'); +} + +/** + * The new version of the plugin to deploy. This can be provided via arguments instead of using the prompt. + * This will likely be supplied when using non-interactive mode (e.g. CI/CD). + * @returns {string|null} The version of the plugin to be deployed, if provided. + */ +export const newPluginVersion = () => { + const argv = minimist(process.argv.slice(2)) + + return argv['new-version'] || null; + } From 64c1fd487708939ad1b1d6b8675b865d45fce3c2 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Wed, 7 May 2025 14:42:41 +0100 Subject: [PATCH 4/9] Export as const --- helpers/arguments.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/helpers/arguments.js b/helpers/arguments.js index 99cadfd..c5c4092 100644 --- a/helpers/arguments.js +++ b/helpers/arguments.js @@ -13,8 +13,7 @@ export function isNonInteractive() * Whether this is a dry run deployment. If true, the deploy to WooCommerce will not actually happen. * @returns {boolean} */ -export function isDryRunDeploy() -{ +export const isDryRunDeploy = () =>{ return process.argv.includes('--dry-run'); } From b3fc82330b6c71333c89f3613a2f4b045f8506c2 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Wed, 7 May 2025 14:46:30 +0100 Subject: [PATCH 5/9] Check if dry run deploy --- tasks/deploy.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tasks/deploy.js b/tasks/deploy.js index e83b603..e0d99e2 100644 --- a/tasks/deploy.js +++ b/tasks/deploy.js @@ -33,6 +33,7 @@ import { zipTask } from './zip.js' import { validateReadmeHeadersTask } from './validate.js' import { lintScriptsTask, lintStylesTask } from './lint.js' import { copyWcRepoTask, copyWpAssetsTask, copyWpTagTask, copyWpTrunkTask } from './copy.js' +import { isDryRunDeploy } from '../helpers/arguments.js'; let validatedEnvVariables = false @@ -110,12 +111,20 @@ const deployTask = (done) => { deployCreateReleasesTask, ] - if (sake.config.deploy.wooId && sake.config.deploy.type === 'wc') { - tasks.push(promptWcUploadTask) - } + if (isDryRunDeploy()) { + tasks.push(function(cb) { + log.info('Dry run deployment successful') - if (sake.config.deploy.type === 'wp') { - tasks.push(deployToWpRepoTask) + return cb() + }) + } else { + if (sake.config.deploy.wooId && sake.config.deploy.type === 'wc') { + tasks.push(promptWcUploadTask) + } + + if (sake.config.deploy.type === 'wp') { + tasks.push(deployToWpRepoTask) + } } // finally, create a docs issue, if necessary From 0001544222a5453bc63b0f6b94bebfd7db22ac92 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Wed, 7 May 2025 14:54:15 +0100 Subject: [PATCH 6/9] Add additional checks for non interactive mode --- tasks/prompt.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tasks/prompt.js b/tasks/prompt.js index 94f4392..d2eb6a8 100644 --- a/tasks/prompt.js +++ b/tasks/prompt.js @@ -6,6 +6,7 @@ import _ from 'lodash' import sake from '../lib/sake.js' import gulp from 'gulp' import { wcDeployTask } from './wc.js' +import { isNonInteractive } from '../helpers/arguments.js' function filterIncrement (value) { if (value[1] === 'custom') { @@ -102,13 +103,21 @@ promptDeployTask.displayName = 'prompt:deploy' * Internal task for prompting whether to upload the plugin to WooCommerce */ const promptWcUploadTask = (done) => { + const runWcDeployTask = () => gulp.series(wcDeployTask)(done); + + // Skip the prompt if in non-interactive mode + if (isNonInteractive()) { + log.info('Running in non-interactive mode, automatically uploading to WooCommerce.com') + return runWcDeployTask(); + } + inquirer.prompt([{ type: 'confirm', name: 'upload_to_wc', message: 'Upload plugin to WooCommerce.com?' }]).then((answers) => { if (answers.upload_to_wc) { - gulp.series(wcDeployTask)(done) + runWcDeployTask(); } else { log.error(chalk.red('Skipped uploading to WooCommerce.com')) done() @@ -121,6 +130,12 @@ promptWcUploadTask.displayName = 'prompt:wc_upload' * Internal task for prompting whether the release has been tested */ const promptTestedReleaseZipTask = (done) => { + // Skip the prompt if in non-interactive mode + if (isNonInteractive()) { + log.info('Running in non-interactive mode, skipping release zip testing confirmation') + return done() + } + inquirer.prompt([{ type: 'confirm', name: 'tested_release_zip', From d0cd0eda58e73cbec025d73d1b98b89676d33260 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Wed, 7 May 2025 15:10:56 +0100 Subject: [PATCH 7/9] Do not prompt docs in non-interactive --- tasks/deploy.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tasks/deploy.js b/tasks/deploy.js index e0d99e2..0a6d9fd 100644 --- a/tasks/deploy.js +++ b/tasks/deploy.js @@ -33,7 +33,7 @@ import { zipTask } from './zip.js' import { validateReadmeHeadersTask } from './validate.js' import { lintScriptsTask, lintStylesTask } from './lint.js' import { copyWcRepoTask, copyWpAssetsTask, copyWpTagTask, copyWpTrunkTask } from './copy.js' -import { isDryRunDeploy } from '../helpers/arguments.js'; +import { isDryRunDeploy, isNonInteractive } from '../helpers/arguments.js'; let validatedEnvVariables = false @@ -127,8 +127,12 @@ const deployTask = (done) => { } } - // finally, create a docs issue, if necessary - tasks.push(gitHubCreateDocsIssueTask) + // finally, create a docs issue, if necessary, but only in interactive mode + if (!isNonInteractive()) { + tasks.push(gitHubCreateDocsIssueTask) + } else { + log.info('Running in non-interactive mode, skipping docs issue creation') + } return gulp.series(tasks)(done) } From a8da9c0654b80a11874dafcf7fd2f19c0c1df688 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Thu, 15 May 2025 16:10:29 +0100 Subject: [PATCH 8/9] Use plugin version from arguments --- tasks/prompt.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tasks/prompt.js b/tasks/prompt.js index d2eb6a8..eb8266b 100644 --- a/tasks/prompt.js +++ b/tasks/prompt.js @@ -6,7 +6,7 @@ import _ from 'lodash' import sake from '../lib/sake.js' import gulp from 'gulp' import { wcDeployTask } from './wc.js' -import { isNonInteractive } from '../helpers/arguments.js' +import { isNonInteractive, newPluginVersion } from '../helpers/arguments.js' function filterIncrement (value) { if (value[1] === 'custom') { @@ -40,6 +40,12 @@ function getDefault () { * Internal task for prompting the deploy action */ const promptDeployTask = (done) => { + if (newPluginVersion()) { + log.info(`Using new version from arguments: ${newPluginVersion()}`) + sake.options = _.merge(sake.options, {version: newPluginVersion()}) + return done() + } + let currentVersion = sake.getPluginVersion() inquirer.prompt([ From b47c0915c045535ff466eb514216d0f3f67475f7 Mon Sep 17 00:00:00 2001 From: Ashley Gibson Date: Thu, 15 May 2025 16:18:50 +0100 Subject: [PATCH 9/9] Support skipping linting --- helpers/arguments.js | 6 +++++- tasks/compile.js | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/helpers/arguments.js b/helpers/arguments.js index c5c4092..4d85486 100644 --- a/helpers/arguments.js +++ b/helpers/arguments.js @@ -26,4 +26,8 @@ export const newPluginVersion = () => { const argv = minimist(process.argv.slice(2)) return argv['new-version'] || null; - } +} + +export const skipLinting = () => { + return process.argv.includes('--skip-linting'); +} diff --git a/tasks/compile.js b/tasks/compile.js index 1fb1de0..87569f8 100644 --- a/tasks/compile.js +++ b/tasks/compile.js @@ -18,6 +18,7 @@ import { lintPhpTask } from './lint.js' import { minifyImagesTask } from './imagemin.js' import { makepotTask } from './makepot.js' import { stylesTask } from './styles.js' +import { skipLinting } from '../helpers/arguments.js'; const sass = gulpSaas(dartSaas); /************************** Scripts */ @@ -152,7 +153,12 @@ compileStyles.displayName = 'compile:styles' // Compile all plugin assets const compile = (done) => { // default compile tasks - let tasks = [lintPhpTask, 'scripts', stylesTask, minifyImagesTask] // NOTE: do not import the `scripts` constant here, otherwise it creates a circular dependency + let tasks = ['scripts', stylesTask, minifyImagesTask] // NOTE: do not import the `scripts` constant here, otherwise it creates a circular dependency + + // lint PHP unless told not to + if (! skipLinting) { + tasks.push(lintPhpTask) + } // unless exclusively told not to, generate the POT file as well if (!sake.options.skip_pot) {