From 399847d7ea22fc5d841ccacf5d65ce49564e02de Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Tue, 20 Jun 2023 12:42:33 +0530 Subject: [PATCH] WIP: Build from template --- app/workers/builds.php | 22 +++++++++++++++++++++- composer.lock | 4 ++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/workers/builds.php b/app/workers/builds.php index 7958da8894..bc65e58be0 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -129,12 +129,32 @@ class BuildsV1 extends Worker $owner = $github->getOwnerName($installationId); $repositoryName = $github->getRepositoryName($repositoryId); $branchName = $deployment->getAttribute('vcsBranch'); - $gitCloneCommand = $github->generateGitCloneCommand($owner, $repositoryId, $branchName, $tmpDirectory, $rootDirectory); + $gitCloneCommand = $github->generateGitCloneCommand($owner, $repositoryName, $branchName, $tmpDirectory, $rootDirectory); \var_dump($gitCloneCommand); $stdout = ''; $stderr = ''; Console::execute('mkdir -p /tmp/builds/' . $buildId, '', $stdout, $stderr); Console::execute($gitCloneCommand, '', $stdout, $stderr); + + // build from template + $templateRepositoryName = $template->getAttribute('templateRepositoryName'); + $templateOwnerName = $template->getAttribute('templateOwnerName'); + + if (!empty($templateRepositoryName) && !empty($templateOwnerName)) { + // clone template repo + $tmpTemplateDirectory = '/tmp/builds/' . $buildId . '/template'; + $templateRootDirectory = $template->getAttribute('templateDirectory', ''); + var_dump($templateOwnerName . " " . $templateRepositoryName); + $gitCloneCommandForTemplate = $github->generateGitCloneCommand($templateOwnerName, $templateRepositoryName, 'main', $tmpTemplateDirectory, $templateRootDirectory); + var_dump("clone cmd for template " . $gitCloneCommandForTemplate); + Console::execute($gitCloneCommandForTemplate, '', $stdout, $stderr); + + // TODO: move template to code directory + // Console::execute('mv FROM TO', '', $stdout, $stderr); + + // TODO: commit and push + } + Console::execute('tar --exclude code.tar.gz -czf /tmp/builds/' . $buildId . '/code.tar.gz -C /tmp/builds/' . $buildId . '/code' . (empty($rootDirectory) ? '' : '/' . $rootDirectory) . ' .', '', $stdout, $stderr); $deviceFunctions = $this->getFunctionsDevice($project->getId()); diff --git a/composer.lock b/composer.lock index c5f249afd5..1e130bb3ee 100644 --- a/composer.lock +++ b/composer.lock @@ -2705,7 +2705,7 @@ "source": { "type": "git", "url": "https://github.com/utopia-php/vcs.git", - "reference": "7fb5b733ab0676b257d8bc8fc4e0c4cafd4c756c" + "reference": "df56d0eecf308e0c8b1e86c6801bb44c7c363052" }, "require": { "adhocore/jwt": "^1.1", @@ -2750,7 +2750,7 @@ "utopia", "vcs" ], - "time": "2023-06-17T14:27:48+00:00" + "time": "2023-06-19T16:54:01+00:00" }, { "name": "utopia-php/websocket",