db06dc31cc
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Blocked by required conditions
Platform: moko-platform CI / Gate 4: Governance (push) Blocked by required conditions
Platform: moko-platform CI / Gate 5: Template Integrity (push) Blocked by required conditions
Platform: moko-platform CI / CI Summary (push) Blocked by required conditions
Generic: Repo Health / Release configuration (push) Blocked by required conditions
Generic: Repo Health / Scripts governance (push) Blocked by required conditions
Generic: Repo Health / Repository health (push) Blocked by required conditions
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 1s
Universal: Auto Version Bump / Version Bump (push) Failing after 3s
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
Platform: moko-platform CI / Gate 5: Template Integrity (pull_request) Blocked by required conditions
Platform: moko-platform CI / CI Summary (pull_request) Blocked by required conditions
Universal: PR Check / Build RC Package (pull_request) Blocked by required conditions
Generic: Repo Health / Release configuration (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 / Site Health (pull_request) Has been skipped
Universal: PR Check / Branch Policy (pull_request) Successful in 1s
Generic: Repo Health / Access control (pull_request) Successful in 2s
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 45s
Universal: PR Check / Validate PR (pull_request) Successful in 5s
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Successful in 6s
Universal: Build & Release / Promote Pre-Release to RC (pull_request) Has been skipped
Branch Cleanup / Delete merged branch (pull_request) Has been skipped
Platform: moko-platform CI / Gate 1: Code Quality (pull_request) Failing after 47s
Universal: Build & Release / Build & Release Pipeline (pull_request) Failing after 11s
Phase 1: version_bump.php — scan CHANGELOG.md and all text files for VERSION: patterns Phase 2: version_check.php — check manifest.xml, package.json, pyproject.toml, CHANGELOG Phase 3: version_auto_bump.php — new CLI tool replacing inline workflow bash Phase 4: auto-release.yml — replace python3 calls with PHP Phase 5: auto-bump.yml — slim to single CLI call, support all branch types Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
138 lines
4.5 KiB
PHP
138 lines
4.5 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/version_auto_bump.php
|
|
* VERSION: 01.00.00
|
|
* BRIEF: Auto patch-bump, set stability suffix, and commit — single CLI replacing inline workflow bash
|
|
*
|
|
* Usage:
|
|
* php version_auto_bump.php --path . --branch dev
|
|
* php version_auto_bump.php --path . --branch feature/my-feature --token TOKEN --repo-url URL
|
|
* php version_auto_bump.php --path . --branch alpha --dry-run
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
$path = '.';
|
|
$branch = null;
|
|
$token = '';
|
|
$repoUrl = '';
|
|
$dryRun = false;
|
|
|
|
foreach ($argv as $i => $arg) {
|
|
if ($arg === '--path' && isset($argv[$i + 1])) $path = $argv[$i + 1];
|
|
if ($arg === '--branch' && isset($argv[$i + 1])) $branch = $argv[$i + 1];
|
|
if ($arg === '--token' && isset($argv[$i + 1])) $token = $argv[$i + 1];
|
|
if ($arg === '--repo-url' && isset($argv[$i + 1])) $repoUrl = $argv[$i + 1];
|
|
if ($arg === '--dry-run') $dryRun = true;
|
|
}
|
|
|
|
// Auto-detect branch from git or CI env
|
|
if ($branch === null) {
|
|
$branch = getenv('GITHUB_REF_NAME') ?: trim((string) @shell_exec('git rev-parse --abbrev-ref HEAD 2>/dev/null'));
|
|
if (empty($branch) || $branch === 'HEAD') {
|
|
fwrite(STDERR, "Cannot detect branch — pass --branch\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
// Map branch to stability suffix
|
|
$stabilityMap = [
|
|
'dev' => 'dev',
|
|
'alpha' => 'alpha',
|
|
'beta' => 'beta',
|
|
'rc' => 'rc',
|
|
];
|
|
|
|
if (array_key_exists($branch, $stabilityMap)) {
|
|
$stability = $stabilityMap[$branch];
|
|
} elseif (str_starts_with($branch, 'feature/')) {
|
|
$stability = 'dev';
|
|
} else {
|
|
$stability = 'dev';
|
|
}
|
|
|
|
$cli = __DIR__;
|
|
$php = PHP_BINARY;
|
|
|
|
// Step 1: Patch bump
|
|
$bumpOutput = [];
|
|
exec("{$php} {$cli}/version_bump.php --path " . escapeshellarg($path) . " 2>&1", $bumpOutput, $bumpRc);
|
|
foreach ($bumpOutput as $line) {
|
|
echo "{$line}\n";
|
|
}
|
|
|
|
// Step 2: Read version
|
|
$versionOutput = [];
|
|
exec("{$php} {$cli}/version_read.php --path " . escapeshellarg($path) . " 2>&1", $versionOutput, $versionRc);
|
|
$version = trim($versionOutput[0] ?? '');
|
|
|
|
if (empty($version)) {
|
|
echo "No version found — skipping\n";
|
|
exit(0);
|
|
}
|
|
|
|
echo "Version: {$version} | Branch: {$branch} | Stability: {$stability}\n";
|
|
|
|
// Step 3: Set platform version with stability suffix
|
|
exec("{$php} {$cli}/version_set_platform.php --path " . escapeshellarg($path)
|
|
. " --version " . escapeshellarg($version)
|
|
. " --branch " . escapeshellarg($branch)
|
|
. " --stability " . escapeshellarg($stability) . " 2>&1", $setPlatOutput);
|
|
foreach ($setPlatOutput as $line) {
|
|
echo "{$line}\n";
|
|
}
|
|
|
|
// Step 4: Version consistency check and fix
|
|
exec("{$php} {$cli}/version_check.php --path " . escapeshellarg($path) . " --fix 2>&1", $checkOutput);
|
|
|
|
// Re-read version (now includes suffix from version_set_platform)
|
|
$suffixMap = [
|
|
'dev' => '-dev',
|
|
'alpha' => '-alpha',
|
|
'beta' => '-beta',
|
|
'rc' => '-rc',
|
|
];
|
|
$displayVersion = preg_replace('/(-(dev|alpha|beta|rc))+$/', '', $version) . ($suffixMap[$stability] ?? '');
|
|
|
|
if ($dryRun) {
|
|
echo "[DRY-RUN] Would commit and push {$displayVersion} to {$branch}\n";
|
|
exit(0);
|
|
}
|
|
|
|
// Step 5: Git commit and push
|
|
$root = realpath($path) ?: $path;
|
|
|
|
// Check if anything changed
|
|
$diffStatus = trim((string) @shell_exec("cd " . escapeshellarg($root) . " && git diff --quiet && git diff --cached --quiet 2>&1 && echo clean || echo dirty"));
|
|
if ($diffStatus === 'clean') {
|
|
echo "No version changes to commit\n";
|
|
exit(0);
|
|
}
|
|
|
|
// Configure git
|
|
@shell_exec("cd " . escapeshellarg($root) . " && git config --local user.email \"gitea-actions[bot]@mokoconsulting.tech\"");
|
|
@shell_exec("cd " . escapeshellarg($root) . " && git config --local user.name \"gitea-actions[bot]\"");
|
|
|
|
if (!empty($repoUrl)) {
|
|
@shell_exec("cd " . escapeshellarg($root) . " && git remote set-url origin " . escapeshellarg($repoUrl));
|
|
}
|
|
|
|
@shell_exec("cd " . escapeshellarg($root) . " && git add -A");
|
|
$commitMsg = "chore(version): auto-bump patch {$displayVersion} [skip ci]";
|
|
@shell_exec("cd " . escapeshellarg($root) . " && git commit -m " . escapeshellarg($commitMsg)
|
|
. " --author=\"gitea-actions[bot] <gitea-actions[bot]@mokoconsulting.tech>\"");
|
|
|
|
$pushResult = @shell_exec("cd " . escapeshellarg($root) . " && git push origin " . escapeshellarg($branch) . " 2>&1");
|
|
echo $pushResult ?? '';
|
|
|
|
echo "Bumped to {$displayVersion}\n";
|
|
exit(0);
|