From 2b5e394eec091c9e47c4e669d7b7067a8db79b35 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Sat, 30 May 2026 09:12:34 -0500 Subject: [PATCH] feat(cli): skip version bump when only non-code files change version_auto_bump now checks if files in the code directory (src/) changed in the last commit. If only docs/workflows/config changed, the bump is skipped entirely. Watch path auto-detected from manifest.xml tag, or can be passed explicitly via --watch-path. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) --- cli/version_auto_bump.php | 56 +++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/cli/version_auto_bump.php b/cli/version_auto_bump.php index f7de29e..350ba9a 100644 --- a/cli/version_auto_bump.php +++ b/cli/version_auto_bump.php @@ -26,11 +26,14 @@ $token = ''; $repoUrl = ''; $dryRun = false; +$watchPath = ''; + 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 === '--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 === '--watch-path' && isset($argv[$i + 1])) $watchPath = $argv[$i + 1]; if ($arg === '--dry-run') $dryRun = true; } @@ -62,17 +65,42 @@ if (array_key_exists($branch, $stabilityMap)) { $cli = __DIR__; $php = PHP_BINARY; -// Step 1: Patch bump — all branches get patch bumps -$shouldBump = true; - -if ($shouldBump) { - $bumpOutput = []; - exec("{$php} {$cli}/version_bump.php --path " . escapeshellarg($path) . " 2>&1", $bumpOutput, $bumpRc); - foreach ($bumpOutput as $line) { - echo "{$line}\n"; +// Auto-detect watch path from manifest.xml if not provided +if (empty($watchPath)) { + $manifestFile = realpath($path) . '/.mokogitea/manifest.xml'; + if (file_exists($manifestFile)) { + $xml = @simplexml_load_file($manifestFile); + if ($xml && isset($xml->build->{'entry-point'})) { + $watchPath = (string) $xml->build->{'entry-point'}; + } } -} else { - echo "Skipping patch bump on {$branch} branch (suffix change only)\n"; +} + +// Check if code files actually changed (skip bump for docs/config-only changes) +$shouldBump = true; +if (!empty($watchPath)) { + $root = realpath($path) ?: $path; + $diffOutput = trim((string) @shell_exec( + "cd " . escapeshellarg($root) . " && git diff --name-only HEAD~1 HEAD -- " . escapeshellarg($watchPath) . " 2>/dev/null" + )); + if (empty($diffOutput)) { + echo "No changes in {$watchPath} — skipping version bump\n"; + $shouldBump = false; + } else { + echo "Changes detected in {$watchPath}:\n{$diffOutput}\n"; + } +} + +if (!$shouldBump) { + echo "No code changes — nothing to do\n"; + exit(0); +} + +// 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