refactor: sync engine clones template repos at runtime for workflows
No longer references local templates/workflows/ — instead clones the canonical template repo (Joomla/Dolibarr/Generic/Client) at sync time to get the latest workflow files directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1042,42 +1042,51 @@ HCL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Template repo mapping — canonical source for each platform's workflows.
|
||||
* The sync engine clones these at runtime to get the latest workflow files.
|
||||
*/
|
||||
private const TEMPLATE_REPOS = [
|
||||
'joomla' => 'MokoConsulting/MokoStandards-Template-Joomla',
|
||||
'dolibarr' => 'MokoConsulting/MokoStandards-Template-Dolibarr',
|
||||
'generic' => 'MokoConsulting/MokoStandards-Template-Generic',
|
||||
'client' => 'MokoConsulting/MokoStandards-Template-Client',
|
||||
];
|
||||
|
||||
private function getSharedWorkflows(string $platform, string $repoRoot): array
|
||||
{
|
||||
$root = rtrim($repoRoot, '/');
|
||||
$wfDir = $this->adapter->getWorkflowDir();
|
||||
|
||||
// Common workflows for ALL platforms
|
||||
$shared = [
|
||||
['templates/workflows/shared/cleanup.yml', "{$wfDir}/cleanup.yml"],
|
||||
['templates/workflows/shared/notify.yml', "{$wfDir}/notify.yml"],
|
||||
['templates/workflows/shared/pr-check.yml', "{$wfDir}/pr-check.yml"],
|
||||
['templates/workflows/shared/pre-release.yml', "{$wfDir}/pre-release.yml"],
|
||||
['templates/workflows/shared/security-audit.yml', "{$wfDir}/security-audit.yml"],
|
||||
];
|
||||
// Determine which template repo to source from
|
||||
$templateType = match (true) {
|
||||
in_array($platform, ['crm-module', 'crm-platform']) => 'dolibarr',
|
||||
in_array($platform, ['waas-component', 'joomla-template']) => 'joomla',
|
||||
str_starts_with($platform, 'client') => 'client',
|
||||
default => 'generic',
|
||||
};
|
||||
|
||||
// Platform-specific workflows
|
||||
if ($platform === 'crm-module' || $platform === 'crm-platform') {
|
||||
// Dolibarr: 11 workflows
|
||||
$shared[] = ['templates/workflows/dolibarr/auto-release.yml', "{$wfDir}/auto-release.yml"];
|
||||
$shared[] = ['templates/workflows/dolibarr/ci-dolibarr.yml', "{$wfDir}/ci-dolibarr.yml"];
|
||||
$shared[] = ['templates/workflows/dolibarr/deploy-manual.yml', "{$wfDir}/deploy-manual.yml"];
|
||||
$shared[] = ['templates/workflows/dolibarr/repo-health.yml', "{$wfDir}/repo-health.yml"];
|
||||
$shared[] = ['templates/workflows/dolibarr/update-server.yml', "{$wfDir}/update-server.yml"];
|
||||
$shared[] = ['templates/workflows/dolibarr/publish-to-mokodolimods.yml', "{$wfDir}/publish-to-mokodolimods.yml"];
|
||||
} elseif ($platform === 'waas-component' || $platform === 'joomla-template') {
|
||||
// Joomla: 10 workflows
|
||||
$shared[] = ['templates/workflows/joomla/auto-release.yml', "{$wfDir}/auto-release.yml"];
|
||||
$shared[] = ['templates/workflows/joomla/ci-joomla.yml', "{$wfDir}/ci-joomla.yml"];
|
||||
$shared[] = ['templates/workflows/joomla/deploy-manual.yml', "{$wfDir}/deploy-manual.yml"];
|
||||
$shared[] = ['templates/workflows/joomla/repo-health.yml', "{$wfDir}/repo-health.yml"];
|
||||
$shared[] = ['templates/workflows/joomla/update-server.yml', "{$wfDir}/update-server.yml"];
|
||||
} else {
|
||||
// Generic: 9 workflows (shared only, no platform CI)
|
||||
$shared[] = ['templates/workflows/joomla/auto-release.yml', "{$wfDir}/auto-release.yml"];
|
||||
$shared[] = ['templates/workflows/joomla/deploy-manual.yml', "{$wfDir}/deploy-manual.yml"];
|
||||
$shared[] = ['templates/workflows/joomla/repo-health.yml', "{$wfDir}/repo-health.yml"];
|
||||
$shared[] = ['templates/workflows/joomla/update-server.yml', "{$wfDir}/update-server.yml"];
|
||||
// Clone template repo to tmp if not already cached
|
||||
$templateRepo = self::TEMPLATE_REPOS[$templateType];
|
||||
$cacheDir = sys_get_temp_dir() . '/mokostandards-sync/' . basename($templateRepo);
|
||||
|
||||
if (!is_dir($cacheDir)) {
|
||||
$gitUrl = $this->adapter->getCloneUrl($templateRepo);
|
||||
$this->logger->logInfo("Cloning template: {$templateRepo} → {$cacheDir}");
|
||||
$cloneResult = $this->adapter->cloneRepo($templateRepo, $cacheDir, ['depth' => 1]);
|
||||
if (!$cloneResult) {
|
||||
throw new \RuntimeException("Failed to clone template repo: {$templateRepo}");
|
||||
}
|
||||
}
|
||||
|
||||
// Read all .yml files from the template's .gitea/workflows/
|
||||
$sourceDir = "{$cacheDir}/.gitea/workflows";
|
||||
$shared = [];
|
||||
|
||||
if (is_dir($sourceDir)) {
|
||||
foreach (glob("{$sourceDir}/*.yml") as $file) {
|
||||
$basename = basename($file);
|
||||
$shared[] = [$file, "{$wfDir}/{$basename}"];
|
||||
}
|
||||
}
|
||||
|
||||
// CODEOWNERS — GitHub only; Gitea doesn't enforce it
|
||||
|
||||
Reference in New Issue
Block a user