Skip to content

Commit

Permalink
Merge pull request #1892 from Automattic/add/cron
Browse files Browse the repository at this point in the history
feat(dev-env): add support for cron
  • Loading branch information
sjinks authored Jun 27, 2024
2 parents d14993e + 38ec96a commit 91e29cf
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 4 deletions.
5 changes: 5 additions & 0 deletions __tests__/devenv-e2e/001-create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe( 'vip dev-env create', () => {
const expectedXDebug = false;
const expectedMailpit = false;
const expectedPhoton = false;
const expectedCron = false;

expect( await checkEnvExists( slug ) ).toBe( false );

Expand Down Expand Up @@ -102,6 +103,7 @@ describe( 'vip dev-env create', () => {
xdebug: expectedXDebug,
mailpit: expectedMailpit,
photon: expectedPhoton,
cron: expectedCron,
} );
} );

Expand All @@ -116,6 +118,7 @@ describe( 'vip dev-env create', () => {
const expectedXDebug = true;
const expectedMailpit = true;
const expectedPhoton = true;
const expectedCron = true;

expect( await checkEnvExists( slug ) ).toBe( false );

Expand All @@ -135,6 +138,7 @@ describe( 'vip dev-env create', () => {
'-x', `${ expectedXDebug }`,
'-A', `${ expectedMailpit }`,
'-H', `${ expectedPhoton }`,
'-c', `${ expectedCron }`,
], { env }, true );

expect( result.rc ).toBe( 0 );
Expand All @@ -156,6 +160,7 @@ describe( 'vip dev-env create', () => {
xdebug: expectedXDebug,
mailpit: expectedMailpit,
photon: expectedPhoton,
cron: expectedCron,
} );
} );
} );
4 changes: 4 additions & 0 deletions __tests__/devenv-e2e/005-update.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe( 'vip dev-env update', () => {
const expectedXDebug = false;
const expectedMailpit = false;
const expectedPhoton = false;
const expectedCron = false;

expect( await checkEnvExists( slug ) ).toBe( false );

Expand All @@ -95,6 +96,7 @@ describe( 'vip dev-env update', () => {
xdebug: expectedXDebug,
mailpit: expectedMailpit,
photon: expectedPhoton,
cron: expectedCron,
} );

// prettier-ignore
Expand All @@ -106,6 +108,7 @@ describe( 'vip dev-env update', () => {
'-x', `${ ! expectedXDebug }`,
'-A', `${ ! expectedMailpit }`,
'-H', `${ ! expectedPhoton }`,
'-c', `${ ! expectedCron }`,
], { env }, true );

expect( result.rc ).toBe( 0 );
Expand All @@ -119,6 +122,7 @@ describe( 'vip dev-env update', () => {
xdebug: ! expectedXDebug,
mailpit: ! expectedMailpit,
photon: ! expectedPhoton,
cron: ! expectedCron,
} );
} );

Expand Down
8 changes: 8 additions & 0 deletions __tests__/devenv-e2e/013-configuration-file.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ describe( 'vip dev-env configuration file', () => {
const expectedXDebug = true;
const expectedMailpit = true;
const expectedPhoton = true;
const expectedCron = true;

expect( await checkEnvExists( expectedSlug ) ).toBe( false );

Expand All @@ -222,6 +223,7 @@ describe( 'vip dev-env configuration file', () => {
xdebug: expectedXDebug,
mailpit: expectedMailpit,
photon: expectedPhoton,
cron: expectedCron,
'mu-plugins': 'image',
'app-code': 'image',
} );
Expand Down Expand Up @@ -256,6 +258,7 @@ describe( 'vip dev-env configuration file', () => {
xdebug: expectedXDebug,
mailpit: expectedMailpit,
photon: expectedPhoton,
cron: expectedCron,
} );

return expect( checkEnvExists( expectedSlug ) ).resolves.toBe( true );
Expand All @@ -268,6 +271,7 @@ describe( 'vip dev-env configuration file', () => {
const expectedXDebug = false;
const expectedMailpit = false;
const expectedPhoton = false;
const expectedCron = false;

expect( await checkEnvExists( slug ) ).toBe( false );

Expand All @@ -280,6 +284,7 @@ describe( 'vip dev-env configuration file', () => {
xdebug: expectedXDebug,
mailpit: expectedMailpit,
photon: expectedPhoton,
cron: expectedCron,
} );

const spawnOptions = {
Expand All @@ -299,6 +304,7 @@ describe( 'vip dev-env configuration file', () => {
xdebug: expectedXDebug,
mailpit: expectedMailpit,
photon: expectedPhoton,
cron: expectedCron,
} );

// Update environment from changed configuration file
Expand All @@ -310,6 +316,7 @@ describe( 'vip dev-env configuration file', () => {
xdebug: ! expectedXDebug,
mailpit: ! expectedMailpit,
photon: ! expectedPhoton,
cron: ! expectedCron,
} );

result = await cliTest.spawn( [ process.argv[ 0 ], vipDevEnvUpdate ], spawnOptions, true );
Expand All @@ -324,6 +331,7 @@ describe( 'vip dev-env configuration file', () => {
xdebug: ! expectedXDebug,
mailpit: ! expectedMailpit,
photon: ! expectedPhoton,
cron: ! expectedCron,
} );
} );
} );
6 changes: 3 additions & 3 deletions __tests__/lib/dev-environment/dev-environment-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ describe( 'lib/dev-environment/dev-environment-cli', () => {
expect( prompt ).toHaveBeenCalledTimes( 0 );
} else {
expect( prompt ).toHaveBeenCalledTimes( 1 );
expect( confirmRunMock ).toHaveBeenCalledTimes( 5 );
expect( confirmRunMock ).toHaveBeenCalledTimes( 6 );
}

const expectedValue =
Expand Down Expand Up @@ -506,9 +506,9 @@ describe( 'lib/dev-environment/dev-environment-cli', () => {
const result = await promptForArguments( input.preselected, input.default, false, true );

if ( input.preselected.mediaRedirectDomain ) {
expect( confirmRunMock ).toHaveBeenCalledTimes( 5 );
} else {
expect( confirmRunMock ).toHaveBeenCalledTimes( 6 );
} else {
expect( confirmRunMock ).toHaveBeenCalledTimes( 7 );
}

const expectedValue = input.preselected.mediaRedirectDomain
Expand Down
4 changes: 4 additions & 0 deletions assets/dev-env.lando.template.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ services:
<% } %>
<% if ( autologinKey ) { %>
VIP_DEV_AUTOLOGIN_KEY: "<%= autologinKey %>"
<% } %>
<% if ( cron ) { %>
ENABLE_CRON: 1
<% } %>
LANDO_NO_USER_PERMS: 'enable'
LANDO_NEEDS_EXEC: 1
Expand All @@ -83,6 +86,7 @@ services:
--domain "http://<%= siteSlug %>.<%= domain %>/"
--title "<%= wpTitle %>"
<% if ( multisite ) { %>--ms-domain "<%= siteSlug %>.<%= domain %>" <% if ( multisite === true || multisite === 'subdomain' ) { %>--subdomain <% } %> <% } %>

database:
type: compose
services:
Expand Down
10 changes: 9 additions & 1 deletion src/lib/dev-environment/dev-environment-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,15 @@ export async function promptForArguments(
siteSlug: '',
mailpit: false,
photon: false,
cron: false,
};

const promptLabels = {
xdebug: 'XDebug',
phpmyadmin: 'phpMyAdmin',
mailpit: 'Mailpit',
photon: 'Photon',
cron: 'Cron',
};

if ( create && ! instanceData.mediaRedirectDomain && defaultOptions.mediaRedirectDomain ) {
Expand Down Expand Up @@ -380,7 +382,7 @@ export async function promptForArguments(
);
}

const services = [ 'phpmyadmin', 'xdebug', 'mailpit', 'photon' ] as const;
const services = [ 'phpmyadmin', 'xdebug', 'mailpit', 'photon', 'cron' ] as const;
for ( const service of services ) {
if ( service in instanceData ) {
const preselected = preselectedOptions[ service ];
Expand Down Expand Up @@ -921,6 +923,12 @@ export function addDevEnvConfigurationOptions( command: Args ): Args {
undefined,
processVersionOption
)
.option(
'cron',
'Enable or disable cron, disabled by default. Accepts "y" (default value) to enable or "n" to disable.',
undefined,
processBooleanOption
)
.option(
[ 'A', 'mailpit' ],
'Enable or disable Mailpit, disabled by default. Accepts "y" (default value) to enable or "n" to disable.',
Expand Down
3 changes: 3 additions & 0 deletions src/lib/dev-environment/dev-environment-configuration-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function sanitizeConfiguration(
mailpit: stringToBooleanIfDefined( configuration.mailpit ),
'media-redirect-domain': configuration[ 'media-redirect-domain' ]?.toString(),
photon: stringToBooleanIfDefined( configuration.photon ),
cron: stringToBooleanIfDefined( configuration.cron ),
meta: configurationMeta,
};

Expand Down Expand Up @@ -169,6 +170,7 @@ export function mergeConfigurationFileOptions(
mailpit: configurationFileOptions.mailpit,
mediaRedirectDomain: configurationFileOptions[ 'media-redirect-domain' ],
photon: configurationFileOptions.photon,
cron: configurationFileOptions.cron,
};

const mergedOptions: InstanceOptions = {};
Expand Down Expand Up @@ -247,5 +249,6 @@ elasticsearch: false
xdebug: false
mailpit: false
photon: false
cron: false
`;
}
4 changes: 4 additions & 0 deletions src/lib/dev-environment/dev-environment-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ function preProcessInstanceData( instanceData: InstanceData ): InstanceData {
newInstanceData.photon = false;
}

if ( ! newInstanceData.cron ) {
newInstanceData.cron = false;
}

// Mailpit migration
newInstanceData.mailpit ??= false;

Expand Down
3 changes: 3 additions & 0 deletions src/lib/dev-environment/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface InstanceOptions {
xdebugConfig?: string;
mailpit?: boolean;
photon?: boolean;
cron?: boolean;

[ index: string ]: unknown;
}
Expand Down Expand Up @@ -71,6 +72,7 @@ export interface ConfigurationFileOptions {
mailpit?: boolean;
'media-redirect-domain'?: string;
photon?: boolean;
cron?: boolean;

meta?: ConfigurationFileMeta;
[ index: string ]: unknown;
Expand All @@ -97,6 +99,7 @@ export interface InstanceData {
elasticsearch?: string | boolean;
mailpit: boolean;
photon: boolean;
cron: boolean;
pullAfter?: number;
autologinKey?: string;
version?: string;
Expand Down

0 comments on commit 91e29cf

Please sign in to comment.