From e90750d11bdea5e3e3493d1a841705d8818935ee Mon Sep 17 00:00:00 2001 From: Raphael Titsworth-Morin Date: Wed, 29 May 2024 15:41:49 -0700 Subject: [PATCH] split --- samples/flask/README.md | 2 +- scripts/template-manager.js | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/samples/flask/README.md b/samples/flask/README.md index 8bc2db8f..9cca61ba 100644 --- a/samples/flask/README.md +++ b/samples/flask/README.md @@ -5,7 +5,7 @@ This is a sample of a basic Flask TODO app. The items are stored in memory and a ### NOTE: This sample is a simple Flask app that demonstrates how to create a TODO app using Flask. The items are stored in memory and are lost when the server is restarted. This sample is intended to provide a basic understanding of how to get started with Flask on Defang. **it is not intended for production use**. If you need something production ready, you should use a managed database like Postgres or MySQL. -TODO: Add docs? +TODO: Push sample... ## Essential Setup Files 1. A [Dockerfile](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/). diff --git a/scripts/template-manager.js b/scripts/template-manager.js index 5a0f3d3a..036c5d85 100644 --- a/scripts/template-manager.js +++ b/scripts/template-manager.js @@ -83,22 +83,39 @@ module.exports = async ({ github, context, core }) => { const currentBranch = process.env.GITHUB_HEAD_REF.split('/').pop(); const isMain = currentBranch === 'main'; - const branch = isMain ? 'main' : `test-${currentBranch}`; + const remoteBranch = isMain ? 'main' : `test-${currentBranch}`; console.log('@@ push token exists? ', process.env.PUSH_TOKEN); - const cmd = `git subtree push --prefix samples/${sample} https://x-access-token:${process.env.PUSH_TOKEN}@github.com/DefangLabs/${templateRepo}.git ${branch}`; + const authedRemote = `https://x-access-token:${process.env.PUSH_TOKEN}@github.com/DefangLabs/${templateRepo}.git` - // add space between each char - console.log('@@ cmd: ', cmd.split('').join(' ')); + const splitBranch = sample; - exec(cmd, (err, stdout, stderr) => { + exec(`git subtree split --prefix samples/${sample} -b ${splitBranch}`, (err, stdout, stderr) => { console.log(`stdout: ${stdout}`); console.log(`stderr: ${stderr}`); if (err) { throw new Error(`exec error: ${err}`); } }); + + exec(`git checkout ${splitBranch}`, (err, stdout, stderr) => { + console.log(`stdout: ${stdout}`); + console.log(`stderr: ${stderr}`); + if (err) { + throw new Error(`exec error: ${err}`); + } + }); + + + exec(`git push ${authedRemote} ${splitBranch}:${remoteBranch} --force`, (err, stdout, stderr) => { + console.log(`stdout: ${stdout}`); + console.log(`stderr: ${stderr}`); + if (err) { + throw new Error(`exec error: ${err}`); + } + }); + } return {