Files
Jonathan Miller 66e728b078
Generic: Repo Health / Access control (push) Successful in 18s
Generic: Repo Health / Site Health (push) Has been skipped
Universal: PR Check / Branch Policy (pull_request) Successful in 3s
Universal: Auto Version Bump / Version Bump (push) Failing after 27s
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Successful in 28s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Generic: Repo Health / Access control (pull_request) Successful in 3s
Platform: moko-platform CI / Gate 1: Code Quality (pull_request) Failing after 1m7s
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 1m7s
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (pull_request) Has been cancelled
Platform: moko-platform CI / CI Summary (pull_request) Has been cancelled
Universal: PR Check / Build RC Package (pull_request) Has been cancelled
Generic: Repo Health / Release configuration (pull_request) Has been cancelled
Generic: Repo Health / Scripts governance (pull_request) Has been cancelled
Generic: Repo Health / Repository health (pull_request) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Has been cancelled
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Has been cancelled
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Has been cancelled
Platform: moko-platform CI / Gate 4: Governance (push) Has been cancelled
Platform: moko-platform CI / Gate 5: Template Integrity (push) Has been cancelled
Platform: moko-platform CI / CI Summary (push) Has been cancelled
Generic: Repo Health / Release configuration (push) Has been cancelled
Generic: Repo Health / Scripts governance (push) Has been cancelled
Generic: Repo Health / Repository health (push) Has been cancelled
style: fix PHPCS violations across migrated CLI scripts
Auto-fixed 5006 tab-indent and line-ending errors via phpcbf, then
manually broke 100 lines exceeding 150-char limit. All 74 files in
cli/, automation/, maintenance/, deploy/ now pass PHPCS PSR-12 clean.

Authored-by: Moko Consulting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-31 13:36:05 -05:00

168 lines
5.0 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
/**
* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
*
* This file is part of a Moko Consulting project.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*
* FILE INFORMATION
* DEFGROUP: MokoPlatform.Scripts.Maintenance
* INGROUP: MokoPlatform
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
* PATH: /maintenance/update_sha_hashes.php
* BRIEF: Update SHA-256 hashes in script registry
*/
declare(strict_types=1);
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
use MokoEnterprise\CliFramework;
class UpdateShaHashesCli extends CliFramework
{
private const REGISTRY_PATH = '.script-registry.json';
private array $changes = [];
protected function configure(): void
{
$this->setDescription('Update SHA-256 hashes for all scripts in the registry');
}
protected function run(): int
{
$this->logForced("SHA-256 Hash Update Tool");
$this->logForced(str_repeat("=", 50));
if ($this->dryRun) {
$this->logForced("Mode: DRY RUN (no changes will be made)");
}
// Load registry
$registry = $this->loadRegistry();
// Update hashes
$updatedRegistry = $this->updateHashes($registry);
// Save if not dry run and there are changes
if (!$this->dryRun && !empty($this->changes)) {
$this->saveRegistry($updatedRegistry);
$this->logForced("\nRegistry updated successfully");
} elseif (empty($this->changes)) {
$this->logForced("\nNo changes needed - all hashes are current");
} else {
$this->logForced("\nDry run complete - changes detected but not applied");
}
return 0;
}
private function loadRegistry(): array
{
if (!file_exists(self::REGISTRY_PATH)) {
throw new \Exception("Registry file not found: " . self::REGISTRY_PATH);
}
$content = file_get_contents(self::REGISTRY_PATH);
$registry = json_decode($content, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \Exception("Failed to parse registry JSON: " . json_last_error_msg());
}
$this->logVerbose("Registry loaded: " . count($registry['scripts']) . " scripts tracked");
return $registry;
}
private function updateHashes(array $registry): array
{
$this->logVerbose("\nChecking scripts for changes...\n");
foreach ($registry['scripts'] as $index => &$script) {
$path = $script['path'];
if (!file_exists($path)) {
$this->logForced("Skipping missing file: {$path}");
continue;
}
// Calculate current hash
$currentHash = hash_file('sha256', $path);
$currentSize = filesize($path);
// Check if changed
if ($currentHash !== $script['sha256']) {
$this->changes[] = [
'path' => $path,
'old_hash' => $script['sha256'],
'new_hash' => $currentHash,
];
$this->logForced("Hash updated: {$path}");
if ($this->verbose) {
$this->logVerbose(" Old: {$script['sha256']}");
$this->logVerbose(" New: {$currentHash}");
}
// Update in registry
$script['sha256'] = $currentHash;
$script['size_bytes'] = $currentSize;
} else {
$this->logVerbose("No change: {$path}");
}
}
// Update metadata timestamp if there are changes
if (!empty($this->changes)) {
$microtime = microtime(true);
$dt = \DateTime::createFromFormat('U.u', sprintf('%.6f', $microtime), new \DateTimeZone('UTC'));
if ($dt === false) {
throw new \Exception("Failed to create DateTime from microtime");
}
$registry['metadata']['generated_at'] = $dt->format('Y-m-d\TH:i:s.u\Z');
}
$this->logForced("\nSummary:");
$this->logForced(" Total scripts: " . count($registry['scripts']));
$this->logForced(" Changed: " . count($this->changes));
return $registry;
}
private function saveRegistry(array $registry): void
{
$json = json_encode($registry, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
if ($json === false) {
throw new \Exception("Failed to encode registry JSON: " . json_last_error_msg());
}
if (file_put_contents(self::REGISTRY_PATH, $json) === false) {
throw new \Exception("Failed to write registry file");
}
$this->logVerbose("Registry saved: " . self::REGISTRY_PATH);
}
private function logForced(string $message): void
{
echo $message . "\n";
}
private function logVerbose(string $message): void
{
if ($this->verbose) {
echo $message . "\n";
}
}
}
$app = new UpdateShaHashesCli();
exit($app->execute());