From 96420f0daf783278d58124b05660fe8ef61e65d0 Mon Sep 17 00:00:00 2001 From: Monica Kozbial <6621618+moniika@users.noreply.github.com> Date: Wed, 21 Jul 2021 11:53:52 -0700 Subject: [PATCH] Add command to deploy beta version of demos (#4958) --- gulpfile.js | 1 + package.json | 1 + scripts/gulpfiles/appengine_tasks.js | 60 ++++++++++++++++++++++++---- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 53a756874..40e9bec44 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -22,6 +22,7 @@ var cleanupTasks = require('./scripts/gulpfiles/cleanup_tasks'); module.exports = { deployDemos: appengineTasks.deployDemos, + deployDemosBeta: appengineTasks.deployDemosBeta, default: buildTasks.build, generateLangfiles: buildTasks.generateLangfiles, build: buildTasks.build, diff --git a/package.json b/package.json index 6314e8b44..1cfca9bc0 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "checkin:built": "gulp checkinBuilt", "checkin:typings": "gulp checkinTypings", "deployDemos": "gulp deployDemos", + "deployDemos:beta": "gulp deployDemosBeta", "format": "git-clang-format", "format:sortrequires": "gulp sortRequires", "generate:langfiles": "gulp generateLangfiles", diff --git a/scripts/gulpfiles/appengine_tasks.js b/scripts/gulpfiles/appengine_tasks.js index 3ae3cc1ba..253d64111 100644 --- a/scripts/gulpfiles/appengine_tasks.js +++ b/scripts/gulpfiles/appengine_tasks.js @@ -67,15 +67,9 @@ function copyPlaygroundDeps() { /** * Deploys files from tmp directory to appengine to version based on the version - * specified in package.json and then cleans the tmp directory. + * passed in and then cleans the tmp directory. */ -function deployAndClean(done) { - const minorVersion = packageJson.version.split('.')[1]; - const patchVersion = packageJson.version.split('.')[2]; - let demoVersion = minorVersion; - if (patchVersion != 0) { - demoVersion += '-' + patchVersion - } +function deployToAndClean(demoVersion) { try { execSync(`gcloud app deploy --project blockly-demo --version ${demoVersion} --no-promote`, { stdio: 'inherit', cwd: demoTmpDir }); } finally { @@ -84,6 +78,50 @@ function deployAndClean(done) { rimraf.sync(demoTmpDir); } } +} + +/** + * Constructs a demo version name based on the version specified in + * package.json. + */ +function getDemosVersion() { + const minorVersion = packageJson.version.split('.')[1]; + const patchVersion = packageJson.version.split('.')[2]; + let demoVersion = minorVersion; + if (patchVersion != 0) { + demoVersion += '-' + patchVersion + } + return demoVersion; +} + +/** + * Deploys files from tmp directory to appengine to version based on the version + * specified in package.json and then cleans the tmp directory. + */ +function deployAndClean(done) { + const demoVersion = getDemosVersion(); + deployToAndClean(demoVersion); + done(); +} + +/** + * Constructs a beta demo version name based on the current date. + */ +function getDemosBetaVersion() { + var date = new Date(); + var mm = date.getMonth() + 1; // Month, 0-11 + var dd = date.getDate(); // Day of the month, 1-31 + var yyyy = date.getFullYear(); + return `${yyyy}${mm < 10 ? '0' + mm : mm}${dd}-beta`; +} + +/** + * Deploys files from tmp directory to appengine to a beta version based on the + * current date and then cleans the tmp directory. + */ +function deployBetaAndClean(done) { + const demoVersion = getDemosBetaVersion(); + deployToAndClean(demoVersion); done(); } @@ -99,7 +137,13 @@ const prepareDemos = gulp.series( */ const deployDemos = gulp.series(prepareDemos, deployAndClean); +/** + * Deploys beta version of demos (version appended with -beta). + */ +const deployDemosBeta = gulp.series(prepareDemos, deployBetaAndClean); + module.exports = { deployDemos: deployDemos, + deployDemosBeta: deployDemosBeta, prepareDemos: prepareDemos }