diff --git a/.github/workflows/build-release-zip.yml b/.github/workflows/build-release-zip.yml index 126c2ad..04a7ac6 100644 --- a/.github/workflows/build-release-zip.yml +++ b/.github/workflows/build-release-zip.yml @@ -2,6 +2,7 @@ name: Build release zip on: workflow_dispatch: + workflow_call: push: branches: - trunk diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 746e20a..b6fe453 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -5,7 +5,10 @@ on: branches: - develop jobs: + build: + uses: 10up/maps-block-apple/.github/workflows/build-release-zip.yml@update/151 # TODO: Update this to develop branch. cypress: + needs: build name: ${{ matrix.core.name }} runs-on: ubuntu-latest strategy: @@ -17,13 +20,30 @@ jobs: - {name: 'WP trunk', version: 'WordPress/WordPress#master'} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 + - name: Download build zip + uses: actions/download-artifact@v3 + with: + name: ${{ github.event.repository.name }} + path: ${{ github.event.repository.name }} + - name: Display structure of downloaded files + run: ls -R + working-directory: ${{ github.event.repository.name }} + - name: Cache node_modules + id: cache-node-modules + uses: actions/cache@v3 + env: + cache-name: cache-node-modules + with: + path: | + node_modules + ~/.cache + ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} - name: Install dependencies run: npm install - - name: Build (optional) - run: npm run build - - name: Set the core version - run: ./tests/bin/set-core-version.js ${{ matrix.core.version }} + - name: Set the core version and plugins config + run: ./tests/bin/set-wp-config.js --core=${{ matrix.core.version }} --plugins=./${{ github.event.repository.name }} - name: Set up WP environment run: npm run env:start - name: Test diff --git a/package-lock.json b/package-lock.json index 64f4e22..8a1a132 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,8 +20,8 @@ } }, "node_modules/@10up/cypress-wp-utils": { - "version": "0.0.1", - "resolved": "git+ssh://git@github.com/10up/cypress-wp-utils.git#d52e775fec2e9eb0ec28e1f3e17e9de4ed50ab7b", + "version": "0.1.0", + "resolved": "git+ssh://git@github.com/10up/cypress-wp-utils.git#0323741d6cecc8efe2ab5f1c7e2298b4d120a4ff", "dev": true, "license": "MIT", "engines": { @@ -20304,7 +20304,7 @@ }, "dependencies": { "@10up/cypress-wp-utils": { - "version": "git+ssh://git@github.com/10up/cypress-wp-utils.git#d52e775fec2e9eb0ec28e1f3e17e9de4ed50ab7b", + "version": "git+ssh://git@github.com/10up/cypress-wp-utils.git#0323741d6cecc8efe2ab5f1c7e2298b4d120a4ff", "dev": true, "from": "@10up/cypress-wp-utils@github:10up/cypress-wp-utils#build" }, diff --git a/tests/bin/set-core-version.js b/tests/bin/set-core-version.js deleted file mode 100755 index 2242d03..0000000 --- a/tests/bin/set-core-version.js +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env node - -const fs = require("fs"); -const { exit } = require("process"); - -const path = `${process.cwd()}/.wp-env.override.json`; - -let config = fs.existsSync(path) ? require(path) : {}; - -const args = process.argv.slice(2); - -if (args.length == 0) exit(0); - -if (args[0] == "latest") { - if (fs.existsSync(path)) { - fs.unlinkSync(path); - } - exit(0); -} - -config.core = args[0]; - -if (!config.core.match(/^WordPress\/WordPress\#/)) { - config.core = "WordPress/WordPress#" + config.core; -} - -try { - fs.writeFileSync(path, JSON.stringify(config)); -} catch (err) { - console.error(err); -} diff --git a/tests/bin/set-wp-config.js b/tests/bin/set-wp-config.js new file mode 100755 index 0000000..1fd1c82 --- /dev/null +++ b/tests/bin/set-wp-config.js @@ -0,0 +1,46 @@ +#!/usr/bin/env node + +const fs = require( 'fs' ); + +const path = `${ process.cwd() }/.wp-env.override.json`; + +let config = fs.existsSync( path ) ? require( path ) : { plugins: [ '.' ] }; + +const args = {}; +process.argv + .slice(2, process.argv.length) + .forEach( arg => { + if (arg.slice(0,2) === '--') { + const param = arg.split('='); + const paramName = param[0].slice(2,param[0].length); + const paramValue = param.length > 1 ? param[1] : true; + args[paramName] = paramValue; + } + }); + +if ( ! args.core && ! args.plugins ) { + return; +} + +if ( 'latest' === args.core ) { + delete args.core; +} + +if( Object.keys(args).length === 0 ) { + return; +} + +if ( args.plugins ) { + args.plugins = args.plugins.split(','); +} + +config = { + ...config, + ...args, +} + +try { + fs.writeFileSync( path, JSON.stringify( config ) ); +} catch ( err ) { + console.error( err ); +}