mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-04 10:42:23 +00:00
fix: remove duplicate syncFilesToGitHubRepo method from merge
The merge brought in both HEAD's and origin/next's versions of the method. Kept origin/next's version which accepts an explicit $files array parameter. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
d4491590de
commit
29cb8a7cd3
1 file changed
-173
@@ -670,179 +670,6 @@ class SyncBunny extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync static files (install.sh, upgrade.sh, docker-compose files, .env.production) to GitHub repository via PR
|
||||
*/
|
||||
private function syncFilesToGitHubRepo(bool $nightly = false): bool
|
||||
{
|
||||
$envLabel = $nightly ? 'NIGHTLY' : 'PRODUCTION';
|
||||
$this->info("Syncing $envLabel static files to GitHub repository...");
|
||||
|
||||
try {
|
||||
$parentDir = realpath(dirname(__FILE__).'/../../..');
|
||||
|
||||
if ($nightly) {
|
||||
$files = [
|
||||
"$parentDir/other/nightly/install.sh" => 'scripts/nightly/install.sh',
|
||||
"$parentDir/other/nightly/upgrade.sh" => 'scripts/nightly/upgrade.sh',
|
||||
"$parentDir/other/nightly/docker-compose.yml" => 'docker/nightly/docker-compose.yml',
|
||||
"$parentDir/other/nightly/docker-compose.prod.yml" => 'docker/nightly/docker-compose.prod.yml',
|
||||
"$parentDir/other/nightly/.env.production" => 'environment/nightly/.env.production',
|
||||
];
|
||||
} else {
|
||||
$files = [
|
||||
"$parentDir/scripts/install.sh" => 'scripts/install.sh',
|
||||
"$parentDir/scripts/upgrade.sh" => 'scripts/upgrade.sh',
|
||||
"$parentDir/docker-compose.yml" => 'docker/docker-compose.yml',
|
||||
"$parentDir/docker-compose.prod.yml" => 'docker/docker-compose.prod.yml',
|
||||
"$parentDir/.env.production" => 'environment/.env.production',
|
||||
];
|
||||
}
|
||||
|
||||
// Verify all source files exist
|
||||
foreach ($files as $source => $target) {
|
||||
if (! file_exists($source)) {
|
||||
$this->error("Source file not found: $source");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$timestamp = time();
|
||||
$tmpDir = sys_get_temp_dir().'/coolify-cdn-files-'.$timestamp;
|
||||
$branchName = 'update-files-'.$timestamp;
|
||||
|
||||
// Clone the repository
|
||||
$this->info('Cloning coolify-cdn repository...');
|
||||
$output = [];
|
||||
exec('gh repo clone coollabsio/coolify-cdn '.escapeshellarg($tmpDir).' 2>&1', $output, $returnCode);
|
||||
if ($returnCode !== 0) {
|
||||
$this->error('Failed to clone repository: '.implode("\n", $output));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create feature branch
|
||||
$this->info('Creating feature branch...');
|
||||
$output = [];
|
||||
exec('cd '.escapeshellarg($tmpDir).' && git checkout -b '.escapeshellarg($branchName).' 2>&1', $output, $returnCode);
|
||||
if ($returnCode !== 0) {
|
||||
$this->error('Failed to create branch: '.implode("\n", $output));
|
||||
exec('rm -rf '.escapeshellarg($tmpDir));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy files to their CDN repo paths
|
||||
$stagedFiles = [];
|
||||
foreach ($files as $source => $target) {
|
||||
$targetPath = "$tmpDir/$target";
|
||||
$targetDir = dirname($targetPath);
|
||||
|
||||
if (! is_dir($targetDir)) {
|
||||
if (! mkdir($targetDir, 0755, true)) {
|
||||
$this->error("Failed to create directory: $targetDir");
|
||||
exec('rm -rf '.escapeshellarg($tmpDir));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (! copy($source, $targetPath)) {
|
||||
$this->error("Failed to copy $source to $targetPath");
|
||||
exec('rm -rf '.escapeshellarg($tmpDir));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$stagedFiles[] = $target;
|
||||
$this->info("Copied: $target");
|
||||
}
|
||||
|
||||
// Stage all files
|
||||
$this->info('Staging changes...');
|
||||
$output = [];
|
||||
$addCommand = 'cd '.escapeshellarg($tmpDir).' && git add '.implode(' ', array_map('escapeshellarg', $stagedFiles)).' 2>&1';
|
||||
exec($addCommand, $output, $returnCode);
|
||||
if ($returnCode !== 0) {
|
||||
$this->error('Failed to stage changes: '.implode("\n", $output));
|
||||
exec('rm -rf '.escapeshellarg($tmpDir));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for changes
|
||||
$this->info('Checking for changes...');
|
||||
$statusOutput = [];
|
||||
exec('cd '.escapeshellarg($tmpDir).' && git status --porcelain 2>&1', $statusOutput, $returnCode);
|
||||
if ($returnCode !== 0) {
|
||||
$this->error('Failed to check repository status: '.implode("\n", $statusOutput));
|
||||
exec('rm -rf '.escapeshellarg($tmpDir));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty(array_filter($statusOutput))) {
|
||||
$this->info('All files are already up to date. No changes to commit.');
|
||||
exec('rm -rf '.escapeshellarg($tmpDir));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Commit changes
|
||||
$commitMessage = "Update $envLabel static files - ".date('Y-m-d H:i:s');
|
||||
$output = [];
|
||||
exec('cd '.escapeshellarg($tmpDir).' && git commit -m '.escapeshellarg($commitMessage).' 2>&1', $output, $returnCode);
|
||||
if ($returnCode !== 0) {
|
||||
$this->error('Failed to commit changes: '.implode("\n", $output));
|
||||
exec('rm -rf '.escapeshellarg($tmpDir));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Push to remote
|
||||
$this->info('Pushing branch to remote...');
|
||||
$output = [];
|
||||
exec('cd '.escapeshellarg($tmpDir).' && git push origin '.escapeshellarg($branchName).' 2>&1', $output, $returnCode);
|
||||
if ($returnCode !== 0) {
|
||||
$this->error('Failed to push branch: '.implode("\n", $output));
|
||||
exec('rm -rf '.escapeshellarg($tmpDir));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create pull request
|
||||
$this->info('Creating pull request...');
|
||||
$prTitle = "Update $envLabel static files - ".date('Y-m-d H:i:s');
|
||||
$fileList = implode("\n- ", $stagedFiles);
|
||||
$prBody = "Automated update of $envLabel static files:\n- $fileList";
|
||||
$prCommand = 'gh pr create --repo coollabsio/coolify-cdn --title '.escapeshellarg($prTitle).' --body '.escapeshellarg($prBody).' --base main --head '.escapeshellarg($branchName).' 2>&1';
|
||||
$output = [];
|
||||
exec($prCommand, $output, $returnCode);
|
||||
|
||||
// Clean up
|
||||
exec('rm -rf '.escapeshellarg($tmpDir));
|
||||
|
||||
if ($returnCode !== 0) {
|
||||
$this->error('Failed to create PR: '.implode("\n", $output));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->info('Pull request created successfully!');
|
||||
if (! empty($output)) {
|
||||
$this->info('PR URL: '.implode("\n", $output));
|
||||
}
|
||||
$this->info('Files synced: '.count($stagedFiles));
|
||||
|
||||
return true;
|
||||
} catch (\Throwable $e) {
|
||||
$this->error('Error syncing files to GitHub: '.$e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user