import { executeCommand, createGithubPR, cleanSandbox, } from './deploy-utils.mjs'; const publicThemesFolder = process.env.PUBLIC_THEMES_FOLDER; const coreThemes = [ 'twentyten', 'twentyeleven', 'twentytwelve', 'twentythirteen', 'twentyfourteen', 'twentyfifteen', 'twentysixteen', 'twentyseventeen', 'twentynineteen', 'twentytwenty', 'twentytwentyone', 'twentytwentytwo', 'twentytwentythree', 'twentytwentyfour', 'twentytwentyfive', ]; export async function pullCoreThemes() { console.log( 'Pulling CORE themes from sandbox.' ); for ( let theme of coreThemes ) { await executeCommand( ` rsync -avr --no-p --no-times --delete -m --exclude-from='.theme-utils/.sandbox-ignore' wpcom-sandbox:${ publicThemesFolder }/${ theme }/ ./${ theme }/ `, true ); } } export async function pushCoreThemes() { console.log( 'Pushing CORE themes to sandbox.' ); for ( let theme of coreThemes ) { await executeCommand( ` rsync -avr --no-p --no-times --delete -m --exclude-from='.theme-utils/.sandbox-ignore' ./${ theme }/ wpcom-sandbox:${ publicThemesFolder }/${ theme }/ `, true ); } } export async function syncCoreTheme( theme, sinceRevision ) { if ( ! theme ) { console.log( 'Must supply theme to sync and revision to start from' ); return; } if ( ! sinceRevision ) { sinceRevision = await executeCommand( `cat ./${ theme }/.pub-svn-revision` ); } let latestRevision = await executeCommand( `svn info -r HEAD https://develop.svn.wordpress.org/trunk | grep Revision | egrep -o "[0-9]+"` ); console.log( `syncing core theme ${ theme } from ${ sinceRevision } to ${ latestRevision }` ); try { await executeCommand( ` svn merge --accept postpone http://develop.svn.wordpress.org/trunk/src/wp-content/themes/${ theme } ./${ theme } -r${ sinceRevision }:HEAD echo '${ latestRevision }' > ./${ theme }/.pub-svn-revision `, true ); } catch ( err ) { console.log( 'Error merging:', err ); } return latestRevision; } export async function checkoutCoreTheme( theme ) { if ( ! theme ) { console.log( 'Must supply theme to sync and revision to start from' ); return; } return executeCommand( ` rm -rf ./${ theme } svn checkout https://wpcom-themes.svn.automattic.com/${ theme } ./${ theme } ` ); } export async function deploySyncCoreTheme( theme, sinceRevision ) { if ( ! theme ) { console.log( 'Must supply theme to sync and revision to start from' ); return; } await cleanSandbox(); await checkoutCoreTheme( theme ); await syncCoreTheme( theme, sinceRevision ); let prompt = await inquirer.prompt( [ { type: 'confirm', message: `Changes have been synced locally. Please resolve any conflicts now. Are you ready to continue?`, name: 'continue', default: false, }, ] ); if ( ! prompt.continue ) { console.log( `Aborted Core Sync Deploy.` ); return; } await pushThemeToSandbox( theme ); let prId = await createCoreGithubPR( theme, sinceRevision ); prompt = await inquirer.prompt( [ { type: 'confirm', message: 'Are you ready to land these changes?', name: 'continue', default: false, }, ] ); if ( ! prompt.continue ) { console.log( `Aborted Automated Deploy Sync Process Landing Phase\n\nYou will have to land these changes manually. The ID of the PR to land: ${ prId }` ); return; } await deployThemes( [ theme ] ); return; } async function buildCoreGithubCommitMessageSince( theme, sinceRevision ) { let latestRevision = await executeCommand( `svn info -r HEAD https://develop.svn.wordpress.org/trunk | grep Revision | egrep -o "[0-9]+"` ); let logs = await executeCommand( `svn log https://core.svn.wordpress.org/trunk/wp-content/themes/${ theme } -r${ sinceRevision }:HEAD` ); // Remove any double or back quotes from commit messages logs = logs.replace( /"/g, '' ); logs = logs.replace( /`/g, "'" ); logs = logs.replace( /\$/g, '%24' ); return `${ theme }: Merge latest core changes up to [wp${ latestRevision }] Summary: ${ logs } Test Plan: Activate ${ theme } and ensure nothing is broken Reviewers: #themes_team Subscribers: `; } /** * Deploys the localy copy of a core theme to wpcom. */ export async function createCoreGithubPR( theme, sinceRevision ) { let commitMessage = await buildCoreGithubCommitMessageSince( theme, sinceRevision ); let prUrl = await createGithubPR( commitMessage ); let prId = prUrl.split( 'pull/' )[ 1 ]; return prId; }