fix: address review findings in workflow_sync.php
Platform: mokocli CI / Gate 2: Unit Tests (8.1) (pull_request) Blocked by required conditions
Platform: mokocli CI / Gate 2: Unit Tests (8.2) (pull_request) Blocked by required conditions
Platform: mokocli CI / Gate 2: Unit Tests (8.3) (pull_request) Blocked by required conditions
Platform: mokocli CI / Gate 3: Self-Health Check (pull_request) Blocked by required conditions
Platform: mokocli CI / Gate 4: Governance (pull_request) Blocked by required conditions
Platform: mokocli CI / Gate 5: Template Integrity (pull_request) Blocked by required conditions
Platform: mokocli CI / CI Summary (pull_request) Blocked by required conditions
Universal: PR Check / Build RC Package (pull_request) Blocked by required conditions
Universal: PR Check / Report Issues (pull_request) Blocked by required conditions
Generic: Repo Health / Scripts governance (pull_request) Blocked by required conditions
Generic: Repo Health / Repository health (pull_request) Blocked by required conditions
Generic: Repo Health / Report Issues (pull_request) Blocked by required conditions
Universal: PR Check / Branch Policy (pull_request) Failing after 1s
Generic: Repo Health / Access control (pull_request) Successful in 2s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Universal: PR Check / Validate PR (pull_request) Failing after 13s
Universal: PR Check / Secret Scan (pull_request) Successful in 16s
Universal: Auto Version Bump / Version Bump (push) Successful in 26s
Platform: mokocli CI / Gate 1: Code Quality (pull_request) Failing after 1m0s

- Fix #1: protect PLATFORM_EXCLUDES workflows from orphan deletion
- Fix #2: remove dead CUSTOM_DIR constant and listWorkflowEntries()
- Fix #3: fix pre-existing undefined $label bug on EXCLUDED branch
This commit is contained in:
Jonathan Miller
2026-06-23 14:13:12 -05:00
parent bb24a58903
commit 2d856c8846
+14 -31
View File
@@ -45,9 +45,6 @@ class WorkflowSyncCli extends CliFramework
/** Prefix for custom workflows preserved during orphan cleanup. */
private const CUSTOM_PREFIX = 'custom-';
/** Subdirectory name for custom workflows preserved during orphan cleanup. */
private const CUSTOM_DIR = 'custom';
private int $updated = 0;
private int $created = 0;
private int $skipped = 0;
@@ -283,14 +280,15 @@ class WorkflowSyncCli extends CliFramework
foreach ($workflows as $workflow) {
$filename = $workflow['name'];
$destPath = '.mokogitea/workflows/' . $filename;
$label = "{$repoFullName}/{$filename}";
// Skip platform-excluded workflows
if (in_array($filename, self::PLATFORM_EXCLUDES[$platform] ?? [], true)) {
fprintf(STDERR, "%-45s | %s\n", $label, 'EXCLUDED (platform)');
$this->skipped++;
continue;
}
$destPath = '.mokogitea/workflows/' . $filename;
$label = "{$repoFullName}/{$filename}";
// Get source content from template
$sourceContent = $this->getFileContent(
@@ -316,7 +314,7 @@ class WorkflowSyncCli extends CliFramework
if ($this->getArgument('--delete-orphans', false)) {
$templateNames = array_map(fn($w) => $w['name'], $workflows);
$this->deleteOrphanWorkflows(
$giteaUrl, $token, $org, $repoName, $branch, $templateNames
$giteaUrl, $token, $org, $repoName, $branch, $templateNames, $platform
);
}
}
@@ -437,15 +435,15 @@ class WorkflowSyncCli extends CliFramework
string $org,
string $repoName,
string $branch,
array $templateNames
array $templateNames,
string $platform
): void {
$repoWorkflows = $this->listWorkflows($giteaUrl, $token, $org, $repoName, $branch);
if ($repoWorkflows === null) {
return;
}
// Also list directories so we can preserve custom/
$allEntries = $this->listWorkflowEntries($giteaUrl, $token, $org, $repoName, $branch);
$platformExcludes = self::PLATFORM_EXCLUDES[$platform] ?? [];
foreach ($repoWorkflows as $workflow) {
$name = $workflow['name'];
@@ -462,6 +460,13 @@ class WorkflowSyncCli extends CliFramework
continue;
}
// Keep if it's platform-excluded (legitimately skipped during sync)
if (in_array($name, $platformExcludes, true)) {
$label = "{$org}/{$repoName}/{$name}";
fprintf(STDERR, "%-45s | %s\n", $label, 'KEPT (platform-excluded)');
continue;
}
// Delete orphan
$filePath = '.mokogitea/workflows/' . $name;
$label = "{$org}/{$repoName}/{$name}";
@@ -525,28 +530,6 @@ class WorkflowSyncCli extends CliFramework
return $response['code'] === 200;
}
/**
* List all entries (files + dirs) in .mokogitea/workflows/.
*/
private function listWorkflowEntries(
string $giteaUrl,
string $token,
string $org,
string $repoName,
string $branch
): array {
$response = $this->apiRequest(
$giteaUrl, $token, 'GET',
"/api/v1/repos/{$org}/{$repoName}/contents/.mokogitea/workflows?ref={$branch}"
);
if ($response['code'] !== 200) {
return [];
}
return json_decode($response['body'], true) ?: [];
}
/**
* List workflow files in a repo's .mokogitea/workflows/ directory.
*/