14de7dbe19
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 1s
Generic: Repo Health / Release configuration (push) Successful in 4s
Generic: Repo Health / Scripts governance (push) Successful in 4s
Generic: Repo Health / Repository health (push) Failing after 5s
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 3: Self-Health Check (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 4: Governance (pull_request) Blocked by required conditions
Universal: PR Check / Branch Policy (pull_request) Failing after 1s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Generic: Repo Health / Access control (pull_request) Successful in 1s
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Successful in 5s
Universal: PR Check / Validate PR (pull_request) Successful in 4s
Platform: moko-platform CI / Gate 1: Code Quality (pull_request) Failing after 10s
Generic: Repo Health / Release configuration (pull_request) Successful in 4s
Generic: Repo Health / Repository health (pull_request) Failing after 4s
Generic: Repo Health / Scripts governance (pull_request) Successful in 5s
Platform: moko-platform CI / Gate 5: Template Integrity (pull_request) Has been skipped
Platform: moko-platform CI / CI Summary (pull_request) Has been cancelled
- release_verify.php: Post-release artifact verification (ZIP integrity, manifest version, SHA256 vs updates.xml, disallowed files check) - release_validate.php: Pre-release sanity checks (version consistency across README, CHANGELOG, manifest, updates.xml, composer.json) - release_body_update.php: Update Gitea release body with changelog extract and checksums table via API - dev_branch_reset.php: Delete and recreate dev branch from main via Gitea API Resolves: #56, #60, #62, #64 Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
98 lines
3.0 KiB
PHP
98 lines
3.0 KiB
PHP
#!/usr/bin/env php
|
|
<?php
|
|
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* FILE INFORMATION
|
|
* DEFGROUP: moko-platform.CLI
|
|
* INGROUP: moko-platform
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
|
|
* PATH: /cli/dev_branch_reset.php
|
|
* BRIEF: Delete and recreate dev branch from main via Gitea API
|
|
*
|
|
* Usage:
|
|
* php dev_branch_reset.php --token TOKEN --api-base URL
|
|
* php dev_branch_reset.php --token TOKEN --api-base URL --branch dev --from main
|
|
*
|
|
* Options:
|
|
* --token Gitea API token (required)
|
|
* --api-base Gitea API base URL (required)
|
|
* --branch Branch to reset (default: dev)
|
|
* --from Source branch (default: main)
|
|
* --output-summary Write to $GITHUB_STEP_SUMMARY
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
$token = null;
|
|
$apiBase = null;
|
|
$branch = 'dev';
|
|
$from = 'main';
|
|
$outputSummary = false;
|
|
|
|
foreach ($argv as $i => $arg) {
|
|
if ($arg === '--token' && isset($argv[$i + 1])) $token = $argv[$i + 1];
|
|
if ($arg === '--api-base' && isset($argv[$i + 1])) $apiBase = $argv[$i + 1];
|
|
if ($arg === '--branch' && isset($argv[$i + 1])) $branch = $argv[$i + 1];
|
|
if ($arg === '--from' && isset($argv[$i + 1])) $from = $argv[$i + 1];
|
|
if ($arg === '--output-summary') $outputSummary = true;
|
|
}
|
|
|
|
if ($token === null) $token = getenv('GA_TOKEN') ?: getenv('GITEA_TOKEN') ?: null;
|
|
|
|
if ($token === null || $apiBase === null) {
|
|
fwrite(STDERR, "Usage: dev_branch_reset.php --token TOKEN --api-base URL [--branch dev] [--from main]\n");
|
|
exit(1);
|
|
}
|
|
|
|
// Delete branch (tolerate 404)
|
|
$ch = curl_init("{$apiBase}/branches/{$branch}");
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_CUSTOMREQUEST => 'DELETE',
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_HTTPHEADER => ["Authorization: token {$token}"],
|
|
CURLOPT_TIMEOUT => 30,
|
|
]);
|
|
curl_exec($ch);
|
|
$delCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
if ($delCode === 204 || $delCode === 200) {
|
|
echo "Deleted branch '{$branch}'\n";
|
|
} elseif ($delCode === 404) {
|
|
echo "Branch '{$branch}' did not exist (skipped delete)\n";
|
|
} else {
|
|
fwrite(STDERR, "WARNING: Delete branch returned HTTP {$delCode}\n");
|
|
}
|
|
|
|
// Create branch from source
|
|
$payload = json_encode(['new_branch_name' => $branch, 'old_branch_name' => $from]);
|
|
$ch = curl_init("{$apiBase}/branches");
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_HTTPHEADER => ["Authorization: token {$token}", "Content-Type: application/json"],
|
|
CURLOPT_POSTFIELDS => $payload,
|
|
CURLOPT_TIMEOUT => 30,
|
|
]);
|
|
$response = curl_exec($ch);
|
|
$createCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
|
|
if ($createCode === 201) {
|
|
echo "Recreated '{$branch}' from '{$from}'\n";
|
|
} else {
|
|
fwrite(STDERR, "Failed to create branch '{$branch}' from '{$from}' (HTTP {$createCode})\n");
|
|
exit(1);
|
|
}
|
|
|
|
if ($outputSummary) {
|
|
$summaryFile = getenv('GITHUB_STEP_SUMMARY');
|
|
if ($summaryFile) {
|
|
file_put_contents($summaryFile, "Dev branch reset: '{$branch}' recreated from '{$from}'\n", FILE_APPEND);
|
|
}
|
|
}
|
|
|
|
exit(0);
|