diff --git a/.mokogitea/workflows/pre-release.yml b/.mokogitea/workflows/pre-release.yml index 6208b20..0183c3c 100644 --- a/.mokogitea/workflows/pre-release.yml +++ b/.mokogitea/workflows/pre-release.yml @@ -79,29 +79,21 @@ jobs: STABILITY="${{ inputs.stability || 'development' }}" case "$STABILITY" in - development) SUFFIX="-dev"; TAG="development" ;; - alpha) SUFFIX="-alpha"; TAG="alpha" ;; - beta) SUFFIX="-beta"; TAG="beta" ;; - release-candidate) SUFFIX="-rc"; TAG="release-candidate" ;; + development) TAG="development" ;; + alpha) TAG="alpha" ;; + beta) TAG="beta" ;; + release-candidate) TAG="release-candidate" ;; esac - # Read current version (bump already handled by push workflow) - VERSION=$(php ${MOKO_CLI}/version_read.php --path . 2>/dev/null) - [ -z "$VERSION" ] && VERSION="00.00.01" - - # Strip any existing suffix from version before applying stability - VERSION=$(echo "$VERSION" | sed 's/-\(dev\|alpha\|beta\|rc\)$//') - + # Set stability suffix, bump preserves it, fix consistency php ${MOKO_CLI}/version_set_platform.php \ - --path . --version "$VERSION" --branch "${{ github.ref_name }}" --stability "$STABILITY" 2>/dev/null || true - - # Verify version consistency across all files + --path . --version "$(php ${MOKO_CLI}/version_read.php --path . 2>/dev/null || echo '00.00.01')" \ + --branch "${{ github.ref_name }}" --stability "$STABILITY" 2>/dev/null || true php ${MOKO_CLI}/version_check.php --path . --fix 2>/dev/null || true - # Update VERSION variable with suffix - if [ -n "$SUFFIX" ]; then - VERSION="${VERSION}${SUFFIX}" - fi + # Read final version (includes suffix, e.g. 01.02.15-dev) + VERSION=$(php ${MOKO_CLI}/version_read.php --path . 2>/dev/null) + [ -z "$VERSION" ] && VERSION="00.00.01" # Commit version bump git config --local user.email "gitea-actions[bot]@mokoconsulting.tech" @@ -126,12 +118,11 @@ jobs: echo "version=${VERSION}" >> "$GITHUB_OUTPUT" echo "stability=${STABILITY}" >> "$GITHUB_OUTPUT" - echo "suffix=${SUFFIX}" >> "$GITHUB_OUTPUT" echo "tag=${TAG}" >> "$GITHUB_OUTPUT" echo "zip_name=${ZIP_NAME}" >> "$GITHUB_OUTPUT" echo "ext_element=${EXT_ELEMENT}" >> "$GITHUB_OUTPUT" - echo "=== Pre-Release: ${EXT_ELEMENT} ${VERSION}${SUFFIX} ===" + echo "=== Pre-Release: ${EXT_ELEMENT} ${VERSION} ===" - name: Create release id: release diff --git a/.mokogitea/workflows/update-server.yml b/.mokogitea/workflows/update-server.yml index 4382731..d2aa4e7 100644 --- a/.mokogitea/workflows/update-server.yml +++ b/.mokogitea/workflows/update-server.yml @@ -109,14 +109,6 @@ jobs: git config --local user.name "gitea-actions[bot]" git remote set-url origin "https://x-access-token:${{ secrets.MOKOGITEA_TOKEN }}@git.mokoconsulting.tech/${{ github.repository }}.git" - # Auto-bump patch version - php ${MOKO_CLI}/version_bump.php --path . 2>/dev/null || true - - VERSION=$(php ${MOKO_CLI}/version_read.php --path . 2>/dev/null || echo "0.0.0") - - # Strip any existing suffix before applying stability - VERSION=$(echo "$VERSION" | sed 's/-\(dev\|alpha\|beta\|rc\)$//') - # Determine stability from branch or manual input if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then STABILITY="${{ inputs.stability }}" @@ -130,30 +122,28 @@ jobs: STABILITY="development" fi - # Version suffix per stability stream + # Gitea release tag per stability case "$STABILITY" in - development) SUFFIX="-dev"; TAG="development" ;; - alpha) SUFFIX="-alpha"; TAG="alpha" ;; - beta) SUFFIX="-beta"; TAG="beta" ;; - rc) SUFFIX="-rc"; TAG="release-candidate" ;; - *) SUFFIX=""; TAG="stable" ;; + development) TAG="development" ;; + alpha) TAG="alpha" ;; + beta) TAG="beta" ;; + rc) TAG="release-candidate" ;; + *) TAG="stable" ;; esac - # Propagate version with stability suffix to all manifest files + # Bump patch, set platform suffix, fix consistency — version_bump preserves suffix php ${MOKO_CLI}/version_set_platform.php \ - --path . --version "$VERSION" --branch "$BRANCH" --stability "$STABILITY" 2>/dev/null || true + --path . --version "$(php ${MOKO_CLI}/version_read.php --path . 2>/dev/null || echo '00.00.01')" \ + --branch "$BRANCH" --stability "$STABILITY" 2>/dev/null || true + php ${MOKO_CLI}/version_bump.php --path . 2>/dev/null || true php ${MOKO_CLI}/version_check.php --path . --fix 2>/dev/null || true - # Re-read version (now includes suffix from version_set_platform) - if [ -n "$SUFFIX" ]; then - VERSION="${VERSION}${SUFFIX}" - fi + # Read final version (includes suffix, e.g. 01.02.15-dev) + VERSION=$(php ${MOKO_CLI}/version_read.php --path . 2>/dev/null || echo "00.00.01") echo "version=${VERSION}" >> "$GITHUB_OUTPUT" echo "stability=${STABILITY}" >> "$GITHUB_OUTPUT" - echo "suffix=${SUFFIX}" >> "$GITHUB_OUTPUT" echo "tag=${TAG}" >> "$GITHUB_OUTPUT" - echo "display_version=${VERSION}" >> "$GITHUB_OUTPUT" # Commit version bump if changed git add -A @@ -303,7 +293,7 @@ jobs: run: | VERSION="${{ steps.meta.outputs.version }}" STABILITY="${{ steps.meta.outputs.stability }}" - DISPLAY="${{ steps.meta.outputs.display_version }}" + DISPLAY="${VERSION}" echo "## Update Server" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY diff --git a/cli/updates_xml_build.php b/cli/updates_xml_build.php index 46ff8bd..2d9bd18 100644 --- a/cli/updates_xml_build.php +++ b/cli/updates_xml_build.php @@ -52,7 +52,7 @@ class UpdatesXmlBuildCli extends CliFramework return 1; } - // Strip any existing stability suffix from version + // Strip suffix — stability is applied via --stability parameter $version = preg_replace('/-(dev|alpha|beta|rc)$/', '', $version); $root = realpath($path) ?: $path; diff --git a/cli/version_bump.php b/cli/version_bump.php index 6181c9a..574c8e3 100644 --- a/cli/version_bump.php +++ b/cli/version_bump.php @@ -41,12 +41,14 @@ class VersionBumpCli extends CliFramework } $root = realpath($path) ?: $path; $mokoVersion = null; + $existingSuffix = ''; $mokoManifest = "{$root}/.mokogitea/manifest.xml"; $mokoContent = ''; if (file_exists($mokoManifest)) { $mokoContent = file_get_contents($mokoManifest); - if (preg_match('#(\d{2}\.\d{2}\.\d{2})(?:-((?:(?:dev|alpha|beta|rc)-?)+))?#', $mokoContent, $m)) { + if (preg_match('#(\d{2}\.\d{2}\.\d{2})((?:-(?:dev|alpha|beta|rc))+)?#', $mokoContent, $m)) { $mokoVersion = $m[1]; + $existingSuffix = $m[2] ?? ''; } } $readmeVersion = null; @@ -117,7 +119,8 @@ class VersionBumpCli extends CliFramework } break; } - $newFull = sprintf('%02d.%02d.%02d', $major, $minor, $patch); + $newBase = sprintf('%02d.%02d.%02d', $major, $minor, $patch); + $newFull = $newBase . $existingSuffix; if (file_exists($mokoManifest) && !empty($mokoContent)) { $pattern = '#\d{2}\.\d{2}\.\d{2}' . '(?:(?:-(?:dev|alpha|beta|rc))+)?#'; @@ -132,7 +135,7 @@ class VersionBumpCli extends CliFramework } } if (file_exists($readme) && !empty($readmeContent)) { - $updated = preg_replace('/(VERSION:\s*)\d{2}\.\d{2}\.\d{2}(?:(?:-(?:dev|alpha|beta|rc))+)?/m', '${1}' . $newFull, $readmeContent, 1); + $updated = preg_replace('/(VERSION:\s*)\d{2}\.\d{2}\.\d{2}(?:(?:-(?:dev|alpha|beta|rc))+)?/m', '${1}' . $newBase, $readmeContent, 1); if ($updated !== null) { file_put_contents($readme, $updated); } @@ -193,7 +196,7 @@ class VersionBumpCli extends CliFramework $changelogFile = "{$root}/CHANGELOG.md"; if (file_exists($changelogFile)) { $clContent = file_get_contents($changelogFile); - $updatedCl = preg_replace('/(VERSION:\s*)\d{2}\.\d{2}\.\d{2}(?:(?:-(?:dev|alpha|beta|rc))+)?/m', '${1}' . $newFull, $clContent); + $updatedCl = preg_replace('/(VERSION:\s*)\d{2}\.\d{2}\.\d{2}(?:(?:-(?:dev|alpha|beta|rc))+)?/m', '${1}' . $newBase, $clContent); if ($updatedCl !== null && $updatedCl !== $clContent) { file_put_contents($changelogFile, $updatedCl); fwrite(STDERR, "Updated CHANGELOG.md\n"); @@ -201,7 +204,7 @@ class VersionBumpCli extends CliFramework } $scanExtensions = ['php', 'yml', 'yaml', 'md', 'txt', 'xml', 'sh', 'toml', 'ini', 'css', 'js']; $excludeDirs = ['.git', 'vendor', 'node_modules', 'build', 'dist', '.claude']; - $versionPattern = '/(VERSION:\s*)\d{2}\.\d{2}\.\d{2}(?:(?:-(?:dev|alpha|beta|rc))+)?/m'; + $versionPattern = '/(VERSION:\s*)\d{2}\.\d{2}\.\d{2}/m'; $directory = new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS); $filter = new RecursiveCallbackFilterIterator($directory, function ($current, $key, $iterator) use ($excludeDirs) { if ($current->isDir() && in_array($current->getFilename(), $excludeDirs, true)) { @@ -236,7 +239,7 @@ class VersionBumpCli extends CliFramework if (preg_match('/^#\s*REPO:\s*https?:\/\//m', $content)) { continue; } - $updated = preg_replace($versionPattern, '${1}' . $newFull, $content); + $updated = preg_replace($versionPattern, '${1}' . $newBase, $content); if ($updated !== null && $updated !== $content) { file_put_contents($filePath, $updated); $genericUpdated[] = $relPath; diff --git a/tests/Unit/VersionBumpTest.php b/tests/Unit/VersionBumpTest.php index 17698cc..c3184bb 100644 --- a/tests/Unit/VersionBumpTest.php +++ b/tests/Unit/VersionBumpTest.php @@ -68,7 +68,7 @@ class VersionBumpTest extends TestCase $this->execute(); $content = file_get_contents("{$this->tmpDir}/README.md"); - $this->assertStringContainsString('03.05.02', $content); + $this->assertStringContainsString('09.21.08', $content); $this->assertStringContainsString('Some content', $content); } @@ -86,6 +86,22 @@ class VersionBumpTest extends TestCase $this->assertStringContainsString('01.00.01', $output); } + public function testPreservesSuffixOnBump(): void + { + mkdir("{$this->tmpDir}/.mokogitea", 0755, true); + file_put_contents( + "{$this->tmpDir}/.mokogitea/manifest.xml", + '01.02.03-dev' + ); + $this->writeReadme('01.02.03'); + + $output = $this->execute(); + $this->assertStringContainsString('01.02.04-dev', $output); + + $manifest = file_get_contents("{$this->tmpDir}/.mokogitea/manifest.xml"); + $this->assertStringContainsString('01.02.04-dev', $manifest); + } + public function testFailsWithNoVersion(): void { file_put_contents(