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

1.0.0 Release #116

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2c4513c
Add basic no docker mode. This allows wp cypress to run commands on h…
jasonagnew Feb 7, 2022
1e1819d
Linting issues
jasonagnew Feb 7, 2022
bd6b819
Sample commit
jasonagnew Feb 8, 2022
841c42b
Allow DB details to set in env variables
jasonagnew Feb 8, 2022
f9b25a1
Fix module exports
jasonagnew Feb 8, 2022
fa073e7
Add logic to set working dir and download wp core in no docker mode
jasonagnew Feb 8, 2022
93b0cee
Enable copy volumes in no docker mode
jasonagnew Feb 8, 2022
3168e07
Switch to install command
jasonagnew Feb 8, 2022
d83752f
Add workingDir to reset command
jasonagnew Feb 8, 2022
ca54286
Fix aync for downloading core
jasonagnew Feb 8, 2022
6c8a5fd
Try symlinks for speed
jasonagnew Feb 8, 2022
43d77c8
force core downloads
jasonagnew Feb 8, 2022
d0a2c82
Formatting
jasonagnew Feb 8, 2022
1b3aa98
Need to switch to working directory if in no docker mode
jasonagnew Feb 8, 2022
88ff342
commands should run inside html dir
jasonagnew Feb 8, 2022
eda1e41
Switch faker for php8 support
jasonagnew Feb 10, 2022
f3ebe7a
feature: created a new property called pluginsActivatedAfterTheme in …
Jul 21, 2022
57def25
Merge branch 'master' into feature/no-docker-mode
jasonagnew Jul 25, 2022
c42856d
Merge branch 'release/1.0.0' into feature/no-docker-mode
jasonagnew Jul 25, 2022
2b4ae97
Merge branch 'cypress-10-compat' into feature/no-docker-mode
jasonagnew Jul 25, 2022
7a824ee
chore: added pluginsActivatedAfterTheme property to config-validation…
Jul 26, 2022
4d70b29
Merge pull request #106 from bigbite/feature/load-theme-before-plugin
ampersarnie Jul 26, 2022
fdbde04
add get config function and remove request from hooks
jasonagnew Jul 27, 2022
e895ba0
Merge branch 'release/1.0.0' into feature/no-docker-mode
jasonagnew Jul 29, 2022
19f4932
chore: update version to rc3
ampersarnie Sep 27, 2022
93afb48
Merge branch 'master' into release/1.0.0
Jan 24, 2023
798cd45
fix: finds cypress/package.json and extract cypress version
Jan 24, 2023
1896a89
chore: bump version
Jan 25, 2023
9dd4cf4
chore: merge conflict with master branch
Jan 25, 2023
21c3ca9
Merge pull request #115 from bigbite/fix/extract-cypress-version
PaulREnglish Jan 26, 2023
344bb9f
chore: bump release candidate version
ampersarnie Jan 26, 2023
f33c8f7
Updated polyfill
jasonagnew Nov 20, 2023
cf05ba1
fix(hooks): change variable declaration to a string
chrishbite Nov 21, 2023
cabacc5
Merge branch 'release/1.0.0' into feature/no-docker-mode
g-elwell Nov 27, 2023
13d9504
fix: linting issues
g-elwell Nov 27, 2023
c725628
Merge pull request #109 from bigbite/feature/no-docker-mode
g-elwell Nov 27, 2023
044969d
Merge branch 'master' into release/1.0.0
g-elwell Nov 27, 2023
b48799a
docs: version bump
g-elwell Nov 27, 2023
d84b413
fix: re-apply fix from #115
g-elwell Jul 2, 2024
b9b1c35
fix: disable eslint dynamic require rule where needed
g-elwell Jul 2, 2024
1f3d491
Merge branch 'master' into release/1.0.0
g-elwell Jul 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions lib/cli/commands/reset.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const { wpcli, cli } = require('../../modules/exec');
const run = require('../../modules/run');
const copyVolumes = require('../../modules/copyVolumes');
const getWPInstallType = require('../../modules/getWPInstallType');
const getEnv = require('../../modules/getEnv');

/**
* Restore WP to its initial state.
Expand All @@ -25,16 +26,32 @@ const reset = async (packageDir, logFile, options) => {

await cli(`bash update.sh ${version} true`, logFile);

if (!options.volumes) {
const workingDir = getEnv('WORKING_DIR');
const noDockerMode = getEnv('NO_DOCKER_MODE');

if (!options.volumes || noDockerMode === 'true') {
await copyVolumes(config.volumes, config.wpContent, logFile);
}

await run(
async () =>
cli(`composer install -d ${workingDir}/html/wp-content/plugins/wp-cypress`, logFile),
'Installing wp-cypress dependencies',
'Dependencies installed',
logFile,
);

const locale = get(config, ['locale'], 'en_US');

const dbHost = getEnv('DB_HOST');
const dbName = getEnv('DB_NAME');
const dbUser = getEnv('DB_USER');
const dbPass = getEnv('DB_PASS');

await run(
async () =>
wpcli(
`core config --dbhost=db --dbname=wordpress --dbuser=root --dbpass="" --locale=${locale} --extra-php`,
`core config --dbhost=${dbHost} --dbname=${dbName} --dbuser=${dbUser} --dbpass="${dbPass}" --locale=${locale} --extra-php`,
logFile,
`

Expand Down Expand Up @@ -138,6 +155,22 @@ if( file_exists ( ABSPATH . '.userid' ) ) {
);
}

if (config.pluginsActivatedAfterTheme.length > 0) {
await run(
async () =>
wpcli(
`plugin activate wp-cypress ${config.pluginsActivatedAfterTheme.join(' ')} ${
config.multisite ? '--network' : ''
}`,
logFile,
),
'Activating theme-dependent plugins',
'Activated theme-dependent plugins',
logFile,
false,
);
}

await run(
async () => wpcli('seed DefaultUsers', logFile),
'Creating default users',
Expand Down
91 changes: 64 additions & 27 deletions lib/cli/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const shell = require('shelljs');

const retryCommand = require('../../modules/retryCommand');
const createConfig = require('../../modules/createConfig');
const { exec, cli } = require('../../modules/exec');
const { exec, cli, wpcli } = require('../../modules/exec');
const run = require('../../modules/run');
const reset = require('./reset');

const getEnv = require('../../modules/getEnv');
/**
* Start the docker the test container and wait for the database to be connected.
*
Expand All @@ -17,37 +17,74 @@ const reset = require('./reset');
*/
const start = async (packageDir, options, logFile) => {
const config = await createConfig(packageDir, options.volumes);
const workingDir = getEnv('WORKING_DIR');

await run(
async () => exec('docker ps -q', logFile),
'Checking for Docker',
'Docker found',
logFile,
);
if (getEnv('NO_DOCKER_MODE') !== 'true') {
await run(
async () => exec('docker ps -q', logFile),
'Checking for Docker',
'Docker found',
logFile,
);

if (config.wpContent) {
shell.rm('-rf', `${config.wpContent.path}/plugins/wp-cypress`);
}
shell.cd(packageDir);

shell.cd(packageDir);
await run(
async () =>
exec(
'docker-compose down --volumes && docker-compose build && docker-compose up -d',
logFile,
),
'Creating test container',
'Test container created',
logFile,
);

await run(
async () =>
exec(
'docker-compose down --volumes && docker-compose build && docker-compose up -d',
await run(
async () => retryCommand(() => cli('mysqladmin ping -h"db"', logFile), 2000, 30),
'Waiting for database connection',
'Database connected',
logFile,
);
} else {
shell.mkdir('-p', `${workingDir}/html`);
shell.cp(`${packageDir}/update.sh`, `${workingDir}/html`);
shell.cp(`${packageDir}/config/${config.htaccessFile}`, `${workingDir}/html/.htaccess`);

const coreDownloads = config.version.map(async (version) =>
run(
async () =>
wpcli(
`core download --version="${version}" --path="${workingDir}/${version}" --force`,
logFile,
),
`Downloading WordPress ${version}`,
`Downloaded WordPress ${version}`,
logFile,
),
'Creating test container',
'Test container created',
logFile,
);

await run(
async () => retryCommand(() => cli('mysqladmin ping -h"db"', logFile), 2000, 30),
'Waiting for database connection',
'Database connected',
logFile,
);
);

await Promise.all(coreDownloads);

if (config.wpContent) {
config.version.forEach((version) => {
shell.rm('-rf', `${workingDir}/${version}/wp-content`);
});
}

if (config.vip) {
await run(
async () =>
exec(
`curl https://github.com/Automattic/vip-go-mu-plugins-built/archive/master.zip -L -o /usr/src/vip-mu-plugins.zip && unzip /usr/src/vip-mu-plugins.zip -d ${workingDir}/html/wp-content && cd ${workingDir}/html/wp-content && mv vip-go-mu-plugins-built-master mu-plugins`,
logFile,
),
'Downloading VIP MU Plugins',
'Downloaded VIP MU Plugins',
logFile,
);
}
}

await reset(packageDir, logFile, options);
};
Expand Down
13 changes: 9 additions & 4 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const fs = require('fs');
const fs = require('fs-extra');
const { program } = require('commander');
const applyEnvDefaults = require('../modules/applyEnvDefaults');
const getConfigFile = require('../utils/get-config-file');

require('pretty-error').start();

const { version, name } = require('../../package.json');

const packageDir = `${process.cwd()}/node_modules/${name}`;
const logFile = fs.createWriteStream(`${packageDir}/debug.log`, {
flags: 'a',
});
const config = getConfigFile();

// Set ENV variables
applyEnvDefaults(config);

const logFile = fs.createWriteStream(`${packageDir}/debug.log`);

const start = require('./commands/start');
const stop = require('./commands/stop');
Expand Down
47 changes: 47 additions & 0 deletions lib/modules/applyEnvDefaults.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const applyEnvDefaults = (config) => {
// All env vars will be prefixed with `WP_CYPRESS_`
const defaults = [
{
name: 'WORKING_DIR',
config: config.wp.workingDir,
default: '/var/www',
},
{
name: 'NO_DOCKER_MODE',
config: config.wp.noDocker,
default: 'false',
},
{
name: 'DB_NAME',
config: config.wp.dbName,
default: 'wordpress',
},
{
name: 'DB_USER',
config: config.wp.dbUser,
default: 'root',
},
{
name: 'DB_PASS',
config: config.wp.dbPass,
default: '',
},
{
name: 'DB_HOST',
config: config.wp.dbHost,
default: 'db',
},
];

defaults.forEach((env) => {
if (!process.env[`WP_CYPRESS_${env.name}`]) {
if (env.config) {
process.env[`WP_CYPRESS_${env.name}`] = env.config;
} else {
process.env[`WP_CYPRESS_${env.name}`] = env.default;
}
}
});
};

module.exports = applyEnvDefaults;
37 changes: 33 additions & 4 deletions lib/modules/copyVolumes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const path = require('path');
const { exec, cli } = require('./exec');
const run = require('./run');
const getEnv = require('./getEnv');

/**
* Copy a file|folder on the host to the container.
Expand Down Expand Up @@ -28,6 +29,26 @@ const copyToContainer = async (location, destination, logFile) => {
}
};

/**
* Copy a file|folder on the host to the working directory.
* @param {string} location
* @param {location} destination
* @param {*} logFile
*/
const copyToWorkingDir = async (location, destination, logFile) => {
if (destination) {
const name = path.basename(destination);
// eslint-disable-next-line no-await-in-loop
await run(
async () =>
exec(`mkdir -p $(dirname ${destination}) && cp -R ${location} ${destination}`, logFile),
`Copying ${name}`,
`Copied ${name}`,
logFile,
);
}
};

/**
* Copy volumes instead of mounting.
*
Expand All @@ -38,15 +59,23 @@ const copyToContainer = async (location, destination, logFile) => {
* @return {Promise<void>}
*/
const copyVolumes = async (volumes, isWpContent, logFile) => {
const workingDir = getEnv('WORKING_DIR');
const noDockerMode = getEnv('NO_DOCKER_MODE');
// eslint-disable-next-line no-restricted-syntax
for (const [i, volume] of volumes.entries()) {
const [location, destination] = volume.split(':');
// eslint-disable-next-line no-await-in-loop
await copyToContainer(location, destination, logFile);

if (isWpContent && i === 0) {
if (noDockerMode === 'true') {
// eslint-disable-next-line no-await-in-loop
await cli('mkdir -p /var/www/html/wp-content/plugins');
await copyToWorkingDir(location, destination, logFile);
} else {
// eslint-disable-next-line no-await-in-loop
await copyToContainer(location, destination, logFile);

if (isWpContent && i === 0) {
// eslint-disable-next-line no-await-in-loop
await cli(`mkdir -p ${workingDir}/html/wp-content/plugins`);
}
}
}
};
Expand Down
Loading