DotCom Automation: create GlotPress project when a theme is deployed (#6956)

* automate glotpress project creation

automate theme launch

* add version check for glotpress project
This commit is contained in:
Madhu Dollu 2023-04-27 13:33:00 +05:30 committed by GitHub
parent 7b2573a583
commit f33796852a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 165 additions and 332 deletions

469
package-lock.json generated
View file

@ -28,6 +28,7 @@
"octokit": "^2.0.3",
"open": "^8.4.0",
"parse5-html-rewriting-stream": "^7.0.0",
"semver": "^7.5.0",
"string-progressbar": "^1.0.4",
"table": "^6.8.0"
},
@ -339,6 +340,15 @@
"url": "https://opencollective.com/babel"
}
},
"node_modules/@babel/core/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/@babel/eslint-parser": {
"version": "7.18.2",
"dev": true,
@ -356,6 +366,15 @@
"eslint": "^7.5.0 || ^8.0.0"
}
},
"node_modules/@babel/eslint-parser/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/@babel/generator": {
"version": "7.18.7",
"dev": true,
@ -422,6 +441,15 @@
"@babel/core": "^7.0.0"
}
},
"node_modules/@babel/helper-compilation-targets/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/@babel/helper-create-class-features-plugin": {
"version": "7.18.6",
"dev": true,
@ -475,6 +503,15 @@
"@babel/core": "^7.4.0-0"
}
},
"node_modules/@babel/helper-define-polyfill-provider/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/@babel/helper-environment-visitor": {
"version": "7.18.6",
"dev": true,
@ -1733,6 +1770,15 @@
"@babel/core": "^7.0.0-0"
}
},
"node_modules/@babel/plugin-transform-runtime/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/@babel/plugin-transform-shorthand-properties": {
"version": "7.18.6",
"dev": true,
@ -1937,6 +1983,15 @@
"@babel/core": "^7.0.0-0"
}
},
"node_modules/@babel/preset-env/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/@babel/preset-modules": {
"version": "0.1.5",
"dev": true,
@ -2649,36 +2704,6 @@
"semver": "^7.3.5"
}
},
"node_modules/@npmcli/fs/node_modules/lru-cache": {
"version": "6.0.0",
"dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@npmcli/fs/node_modules/semver": {
"version": "7.3.7",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@npmcli/fs/node_modules/yallist": {
"version": "4.0.0",
"dev": true,
"license": "ISC"
},
"node_modules/@npmcli/move-file": {
"version": "1.1.2",
"dev": true,
@ -3932,36 +3957,6 @@
}
}
},
"node_modules/@typescript-eslint/eslint-plugin/node_modules/lru-cache": {
"version": "6.0.0",
"dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@typescript-eslint/eslint-plugin/node_modules/semver": {
"version": "7.3.7",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@typescript-eslint/eslint-plugin/node_modules/yallist": {
"version": "4.0.0",
"dev": true,
"license": "ISC"
},
"node_modules/@typescript-eslint/experimental-utils": {
"version": "5.30.6",
"dev": true,
@ -4085,36 +4080,6 @@
}
}
},
"node_modules/@typescript-eslint/typescript-estree/node_modules/lru-cache": {
"version": "6.0.0",
"dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@typescript-eslint/typescript-estree/node_modules/semver": {
"version": "7.3.7",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@typescript-eslint/typescript-estree/node_modules/yallist": {
"version": "4.0.0",
"dev": true,
"license": "ISC"
},
"node_modules/@typescript-eslint/utils": {
"version": "5.30.6",
"dev": true,
@ -5440,6 +5405,15 @@
"@babel/core": "^7.0.0-0"
}
},
"node_modules/babel-plugin-polyfill-corejs2/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/babel-plugin-polyfill-corejs3": {
"version": "0.5.2",
"dev": true,
@ -6030,6 +6004,15 @@
"node": ">=8"
}
},
"node_modules/check-node-version/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/cheerio": {
"version": "1.0.0-rc.12",
"dev": true,
@ -6908,36 +6891,6 @@
"webpack": "^5.0.0"
}
},
"node_modules/css-loader/node_modules/lru-cache": {
"version": "6.0.0",
"dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/css-loader/node_modules/semver": {
"version": "7.3.7",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/css-loader/node_modules/yallist": {
"version": "4.0.0",
"dev": true,
"license": "ISC"
},
"node_modules/css-select": {
"version": "5.1.0",
"dev": true,
@ -8186,36 +8139,6 @@
"eslint": "^7.0.0 || ^8.0.0"
}
},
"node_modules/eslint-plugin-jsdoc/node_modules/lru-cache": {
"version": "6.0.0",
"dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/eslint-plugin-jsdoc/node_modules/semver": {
"version": "7.3.7",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/eslint-plugin-jsdoc/node_modules/yallist": {
"version": "4.0.0",
"dev": true,
"license": "ISC"
},
"node_modules/eslint-plugin-jsx-a11y": {
"version": "6.6.0",
"dev": true,
@ -8242,6 +8165,15 @@
"eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8"
}
},
"node_modules/eslint-plugin-jsx-a11y/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/eslint-plugin-markdown": {
"version": "2.2.1",
"dev": true,
@ -8341,6 +8273,15 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/eslint-plugin-react/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/eslint-scope": {
"version": "5.1.1",
"dev": true,
@ -10688,6 +10629,15 @@
"node": ">=8"
}
},
"node_modules/istanbul-lib-instrument/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/istanbul-lib-report": {
"version": "3.0.0",
"dev": true,
@ -11286,36 +11236,6 @@
"node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"
}
},
"node_modules/jest-snapshot/node_modules/lru-cache": {
"version": "6.0.0",
"dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/jest-snapshot/node_modules/semver": {
"version": "7.3.7",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/jest-snapshot/node_modules/yallist": {
"version": "4.0.0",
"dev": true,
"license": "ISC"
},
"node_modules/jest-util": {
"version": "27.5.1",
"dev": true,
@ -11594,36 +11514,6 @@
"npm": ">=6"
}
},
"node_modules/jsonwebtoken/node_modules/lru-cache": {
"version": "6.0.0",
"dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/jsonwebtoken/node_modules/semver": {
"version": "7.3.8",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/jsonwebtoken/node_modules/yallist": {
"version": "4.0.0",
"dev": true,
"license": "ISC"
},
"node_modules/jsprim": {
"version": "1.4.2",
"dev": true,
@ -12132,6 +12022,15 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/make-dir/node_modules/semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true,
"bin": {
"semver": "bin/semver.js"
}
},
"node_modules/make-fetch-happen": {
"version": "9.1.0",
"dev": true,
@ -13017,17 +12916,6 @@
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
}
},
"node_modules/node-gyp/node_modules/lru-cache": {
"version": "6.0.0",
"dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/node-gyp/node_modules/npmlog": {
"version": "6.0.2",
"dev": true,
@ -13056,20 +12944,6 @@
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/node-gyp/node_modules/semver": {
"version": "7.3.7",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/node-gyp/node_modules/which": {
"version": "2.0.2",
"dev": true,
@ -13084,11 +12958,6 @@
"node": ">= 8"
}
},
"node_modules/node-gyp/node_modules/yallist": {
"version": "4.0.0",
"dev": true,
"license": "ISC"
},
"node_modules/node-int64": {
"version": "0.4.0",
"dev": true,
@ -13210,20 +13079,6 @@
"node": ">=10"
}
},
"node_modules/node-sass/node_modules/semver": {
"version": "7.3.7",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/node-sass/node_modules/shebang-command": {
"version": "2.0.0",
"dev": true,
@ -13383,36 +13238,6 @@
"npm": ">=6.0.0"
}
},
"node_modules/npm-package-json-lint/node_modules/lru-cache": {
"version": "6.0.0",
"dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/npm-package-json-lint/node_modules/semver": {
"version": "7.3.7",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/npm-package-json-lint/node_modules/yallist": {
"version": "4.0.0",
"dev": true,
"license": "ISC"
},
"node_modules/npm-packlist": {
"version": "3.0.0",
"dev": true,
@ -14597,36 +14422,6 @@
"webpack": "^5.0.0"
}
},
"node_modules/postcss-loader/node_modules/lru-cache": {
"version": "6.0.0",
"dev": true,
"license": "ISC",
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/postcss-loader/node_modules/semver": {
"version": "7.3.7",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/postcss-loader/node_modules/yallist": {
"version": "4.0.0",
"dev": true,
"license": "ISC"
},
"node_modules/postcss-media-query-parser": {
"version": "0.2.3",
"dev": true,
@ -15274,8 +15069,9 @@
},
"node_modules/prompts": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz",
"integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==",
"dev": true,
"license": "MIT",
"dependencies": {
"kleur": "^3.0.3",
"sisteransi": "^1.0.5"
@ -16378,13 +16174,38 @@
}
},
"node_modules/semver": {
"version": "6.3.0",
"version": "7.5.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.5.0.tgz",
"integrity": "sha512-+XC0AD/R7Q2mPSRuy2Id0+CGTZ98+8f+KvwirxOKIEyid+XSx6HbC63p+O4IndTHuX5Z+JxQ0TghCkO5Cg/2HA==",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/semver/node_modules/lru-cache": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
"dev": true,
"dependencies": {
"yallist": "^4.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/semver/node_modules/yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
"dev": true
},
"node_modules/send": {
"version": "0.18.0",
"dev": true,
@ -17394,20 +17215,6 @@
"node": ">=10"
}
},
"node_modules/stylelint/node_modules/semver": {
"version": "7.3.7",
"dev": true,
"license": "ISC",
"dependencies": {
"lru-cache": "^6.0.0"
},
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/stylelint/node_modules/type-fest": {
"version": "0.18.1",
"dev": true,

View file

@ -45,6 +45,7 @@
"octokit": "^2.0.3",
"open": "^8.4.0",
"parse5-html-rewriting-stream": "^7.0.0",
"semver": "^7.5.0",
"string-progressbar": "^1.0.4",
"table": "^6.8.0"
},

View file

@ -5,11 +5,13 @@ import inquirer from 'inquirer';
import { RewritingStream } from 'parse5-html-rewriting-stream';
import { table } from 'table';
import progressbar from 'string-progressbar';
import semver from 'semver';
const remoteSSH = 'wpcom-sandbox';
const sandboxPublicThemesFolder = '/home/wpdev/public_html/wp-content/themes/pub';
const sandboxPremiumThemesFolder = '/home/wpdev/public_html/wp-content/themes/premium';
const sandboxRootFolder = '/home/wpdev/public_html/';
const glotPressScript = '~/public_html/bin/i18n/create-glotpress-project-for-theme.php';
const isWin = process.platform === 'win32';
const premiumThemes = ['videomaker', 'videomaker-white'];
const coreThemes = ['twentyten', 'twentyeleven', 'twentytwelve', 'twentythirteen', 'twentyfourteen', 'twentyfifteen', 'twentysixteen', 'twentyseventeen', 'twentynineteen', 'twentytwenty', 'twentytwentyone', 'twentytwentytwo', 'twentytwentythree'];
@ -267,8 +269,13 @@ async function pushButtonDeploy() {
let changedThemes = await getChangedThemes(hash);
await pushChangesToSandbox();
if (!changedThemes.length) {
console.log(`\n\nEverything is upto date. Nothing new to deploy.\n\n`);
return;
}
await pushChangesToSandbox();
await createGlotPressProject(changedThemes);
//push changes (from version bump)
if (thingsWentBump) {
@ -1132,6 +1139,24 @@ async function tagDeployment(options = {}) {
`, true);
}
async function createGlotPressProject(changedThemes) {
for (const themeSlug of changedThemes) {
let styleCss = fs.readFileSync(`${themeSlug}/style.css`, 'utf8');
let themeVersion = getThemeMetadata(styleCss, 'Version');
if (semver.gte(themeVersion, '1.0.0')) {
console.log(`\nCreating GlotPress project for ${themeSlug}\n`);
await executeOnSandbox(`
cd ${sandboxPublicThemesFolder};
php ${glotPressScript} ${sandboxPublicThemesFolder}/${themeSlug};
`, true);
} else {
console.log(`\nSkipped GlotPress project creation for ${themeSlug}.\nVersion bump to a major release to create GlotPress project.\n`);
}
}
}
/*
Execute a command on the sandbox.
Expects the following to be configured in your ~/.ssh/config file: