From bbebb98a2b25ffe5f1999561a6d8cfa86cf330df Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Thu, 5 Dec 2024 15:38:11 -0500 Subject: [PATCH 1/3] add versioning script and command --- package.json | 1 + set-version-bump.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 set-version-bump.js diff --git a/package.json b/package.json index 7264245e..ebdd8b6b 100644 --- a/package.json +++ b/package.json @@ -72,6 +72,7 @@ "php-deps": "composer install --no-dev --optimize-autoloader", "postprepare": "npm run set-wp-version", "prebuild:cleanup": "rm -rf ./build ./wp-plugin-web ./wp-plugin-web.zip ./vendor", + "set-version-bump": "node ./set-version-bump.js && npm i && rm -rf ./build && npm run build && composer run i18n", "set-wp-version": "node ./set-latest-wp-version.js", "simulate-runner-build": "npm run prebuild:cleanup && npm i && npm run php-deps && npm run build && npm run create:dist && npm run create:zip", "srb": "npm run simulate-runner-build", diff --git a/set-version-bump.js b/set-version-bump.js new file mode 100644 index 00000000..20d424cc --- /dev/null +++ b/set-version-bump.js @@ -0,0 +1,32 @@ +const fs = require( 'fs' ); +const semver = require( 'semver' ); +const packagefile = './package.json'; +const pluginfile = './wp-plugin-web.php'; + +if ( fs.existsSync( packagefile ) && fs.existsSync( pluginfile ) ) { + const packageData = require( packagefile ); + const currentVersion = packageData.version; + let type = process.argv[ 2 ]; + if ( ! [ 'major', 'minor', 'patch' ].includes( type ) ) { + type = 'patch'; + } + + const newVersion = semver.inc( packageData.version, type ); + packageData.version = newVersion; + fs.writeFileSync( packagefile, JSON.stringify( packageData, null, 4 ) ); + + fs.readFile( pluginfile, 'utf8', function ( err, data ) { + if ( err ) { + return console.log( err ); + } + const result = data.replaceAll( currentVersion, newVersion ); + + fs.writeFile( pluginfile, result, 'utf8', function ( err ) { + if ( err ) { + return console.log( err ); + } + } ); + } ); + + console.log( 'Version updated', currentVersion, '=>', newVersion ); +} From a17bdf58a87366b2e017bdee270e4a3dd0b6cbb3 Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Thu, 5 Dec 2024 15:43:07 -0500 Subject: [PATCH 2/3] update cypress config to exclude coming soon woo depdendent test when woo is not suppported --- cypress.config.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/cypress.config.js b/cypress.config.js index 7fd9ea17..a3371b9e 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -29,7 +29,52 @@ module.exports = defineConfig({ // We've imported your old cypress plugins here. // You may want to clean this up later by importing these. setupNodeEvents(on, config) { - return require('./tests/cypress/plugins/index.js')(on, config) + + const semver = require('semver'); + + // Ensure that the base URL is always properly set. + if (config.env && config.env.baseUrl) { + config.baseUrl = config.env.baseUrl; + } + + // Ensure that we have a semantically correct WordPress version number for comparisons. + if (config.env.wpVersion) { + if (config.env.wpVersion.split('.').length !== 3) { + config.env.wpSemverVersion = `${config.env.wpVersion}.0`; + } else { + config.env.wpSemverVersion = config.env.wpVersion; + } + } + + if (config.env.phpVersion) { + if (config.env.phpVersion.split('.').length !== 3) { + config.env.phpSemverVersion = `${config.env.phpVersion}.0`; + } else { + config.env.phpSemverVersion = config.env.phpVersion; + } + } + + // Tests requires Woo, so exclude if not supported due to WP or PHP versions + if ( ! supportsWoo( config.env ) ) { + config.excludeSpecPattern = config.excludeSpecPattern.concat( [ + 'vendor/newfold-labs/wp-module-coming-soon/tests/cypress/integration/coming-soon-woo.cy.js', + ] ); + } + + on('task', { + log(message) { + console.log(message) + + return null + }, + table(message) { + console.table(message) + + return null + } + }) + + return config; }, baseUrl: 'http://localhost:8886', specPattern: [ @@ -46,3 +91,15 @@ module.exports = defineConfig({ retries: 1, experimentalMemoryManagement: true, }) + +// Check against plugin support at https://wordpress.org/plugins/woocommerce/ +const supportsWoo = ( env ) => { + const semver = require( 'semver' ); + if ( + semver.satisfies( env.wpSemverVersion, '>=6.5.0' ) && + semver.satisfies( env.phpSemverVersion, '>=7.4.0' ) + ) { + return true; + } + return false; +}; \ No newline at end of file From e7142e0939d164bd3fbcf85b92beb4d64fb9c94d Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Thu, 5 Dec 2024 16:03:45 -0500 Subject: [PATCH 3/3] auto retry workflow step when wp install fails --- .github/workflows/cypress-matrix.yml | 6 +++++- .github/workflows/cypress.yml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cypress-matrix.yml b/.github/workflows/cypress-matrix.yml index 565efe03..d9c86003 100644 --- a/.github/workflows/cypress-matrix.yml +++ b/.github/workflows/cypress-matrix.yml @@ -111,7 +111,11 @@ jobs: echo '{"wpVersion": "${{ matrix.wpVersion }}","phpVersion": "${{ matrix.phpVersion }}"}' > cypress.env.json - name: Install WordPress - run: npx wp-env start --debug + uses: nick-fields/retry@v3 + with: + timeout_minutes: 4 + max_attempts: 3 + command: npx wp-env start --debug - name: Run Cypress Tests if: ${{ github.repository != 'newfold-labs/wp-plugin-web' || github.actor == 'dependabot[bot]' }} diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index b5a21d9b..ef66e97f 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -110,7 +110,11 @@ jobs: run: echo '{"config":{"WP_DEBUG_DISPLAY":false},"plugins":["${{ steps.workflow.outputs.DIST }}/${{ steps.workflow.outputs.PACKAGE }}"]}' > .wp-env.override.json - name: Install WordPress - run: npx @wordpress/env@latest start + uses: nick-fields/retry@v3 + with: + timeout_minutes: 4 + max_attempts: 3 + command: npx wp-env start --debug - name: Run Cypress Tests if: ${{ github.repository != 'newfold-labs/wp-plugin-web' || github.actor == 'dependabot[bot]' }}