refactor: simplify version extraction — derive filename from manifest version (#191)

Version string (e.g. 01.02.14-dev) is now read once from the manifest
and flows through unchanged. Removes DISPLAY_VERSION/SUFFIX re-derivation
from branch names in workflows.

Authored-by: Moko Consulting
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonathan Miller
2026-05-26 18:40:58 -05:00
parent e9dcd48e44
commit 2723fbf0e7
4 changed files with 23 additions and 27 deletions
+8 -8
View File
@@ -76,14 +76,15 @@ jobs:
run: |
STABILITY="${{ inputs.stability || 'development' }}"
# Map stability to Gitea release tag
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)
# Read current version (includes suffix from manifest, e.g. 01.02.14-dev)
VERSION=$(php ${MOKO_CLI}/version_read.php --path . 2>/dev/null)
[ -z "$VERSION" ] && VERSION="00.00.01"
@@ -112,16 +113,15 @@ jobs:
EXT_ELEMENT=$(grep '^ext_element=' "$GITHUB_OUTPUT" | tail -1 | cut -d= -f2)
ZIP_NAME=$(grep '^zip_name=' "$GITHUB_OUTPUT" | tail -1 | cut -d= -f2)
[ -z "$EXT_ELEMENT" ] && EXT_ELEMENT=$(echo "${GITEA_REPO}" | tr '[:upper:]' '[:lower:]' | tr -d ' -')
[ -z "$ZIP_NAME" ] && ZIP_NAME="${EXT_ELEMENT}-${VERSION}${SUFFIX}.zip"
[ -z "$ZIP_NAME" ] && ZIP_NAME="${EXT_ELEMENT}-${VERSION}.zip"
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
+7 -13
View File
@@ -182,14 +182,8 @@ jobs:
PHP_TAG=""
[ -n "$PHP_MINIMUM" ] && PHP_TAG="<php_minimum>${PHP_MINIMUM}</php_minimum>"
# Version suffix for non-stable
DISPLAY_VERSION="$VERSION"
case "$STABILITY" in
development) DISPLAY_VERSION="${VERSION}-dev" ;;
alpha) DISPLAY_VERSION="${VERSION}-alpha" ;;
beta) DISPLAY_VERSION="${VERSION}-beta" ;;
rc) DISPLAY_VERSION="${VERSION}-rc" ;;
esac
# VERSION already includes suffix from manifest (e.g. 01.02.14-dev)
# No separate DISPLAY_VERSION needed
MAJOR=$(echo "$VERSION" | awk -F. '{print $1}')
@@ -202,7 +196,7 @@ jobs:
*) RELEASE_TAG="v${MAJOR}" ;;
esac
PACKAGE_NAME="${EXT_ELEMENT}-${DISPLAY_VERSION}.zip"
PACKAGE_NAME="${EXT_ELEMENT}-${VERSION}.zip"
DOWNLOAD_URL="${GITEA_URL}/${GITEA_ORG}/${GITEA_REPO}/releases/download/${RELEASE_TAG}/${PACKAGE_NAME}"
INFO_URL="${GITEA_URL}/${GITEA_ORG}/${GITEA_REPO}"
@@ -211,7 +205,7 @@ jobs:
[ ! -d "$SOURCE_DIR" ] && SOURCE_DIR="htdocs"
if [ -d "$SOURCE_DIR" ]; then
EXCLUDES=".ftpignore sftp-config* *.ppk *.pem *.key .env*"
TAR_NAME="${EXT_ELEMENT}-${DISPLAY_VERSION}.tar.gz"
TAR_NAME="${EXT_ELEMENT}-${VERSION}.tar.gz"
cd "$SOURCE_DIR"
zip -r "/tmp/${PACKAGE_NAME}" . -x $EXCLUDES
@@ -234,7 +228,7 @@ jobs:
"${API_BASE}/releases" \
-d "$(python3 -c "import json; print(json.dumps({
'tag_name': '${RELEASE_TAG}',
'name': '${RELEASE_TAG} (${DISPLAY_VERSION})',
'name': '${RELEASE_TAG} (${VERSION})',
'body': '${STABILITY} release',
'prerelease': True,
'target_commitish': 'main'
@@ -371,7 +365,7 @@ jobs:
git config --local user.name "gitea-actions[bot]"
git add updates.xml
git diff --cached --quiet || {
git commit -m "chore: update updates.xml (${STABILITY}: ${DISPLAY_VERSION}) [skip ci]" \
git commit -m "chore: update updates.xml (${STABILITY}: ${VERSION}) [skip ci]" \
--author="gitea-actions[bot] <gitea-actions[bot]@mokoconsulting.tech>"
git push
}
@@ -600,6 +594,6 @@ jobs:
echo "| Field | Value |" >> $GITHUB_STEP_SUMMARY
echo "|-------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Stability | \`${STABILITY}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Version | \`${DISPLAY_VERSION}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Version | \`${VERSION}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Element | \`${EXT_ELEMENT}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Download | [ZIP](${DOWNLOAD_URL}) |" >> $GITHUB_STEP_SUMMARY
+6 -4
View File
@@ -26,12 +26,14 @@ $root = realpath($path) ?: $path;
// -- 1. Read version from .mokogitea/manifest.xml (canonical) --
$mokoVersion = null;
$mokoSuffix = '';
$mokoManifest = "{$root}/.mokogitea/manifest.xml";
$mokoContent = '';
if (file_exists($mokoManifest)) {
$mokoContent = file_get_contents($mokoManifest);
if (preg_match('|<version>(\d{2}\.\d{2}\.\d{2})(?:-([a-z]+))?</version>|', $mokoContent, $m)) {
$mokoVersion = $m[1];
$mokoSuffix = isset($m[2]) ? $m[2] : '';
}
}
@@ -108,15 +110,15 @@ switch ($type) {
$new = sprintf('%02d.%02d.%02d', $major, $minor, $patch);
// -- Determine suffix to preserve (from whichever source had the version) --
$suffix = !empty($manifestSuffix) ? $manifestSuffix : '';
// -- Determine suffix to preserve (moko manifest takes priority, then Joomla) --
$suffix = !empty($mokoSuffix) ? $mokoSuffix : (!empty($manifestSuffix) ? $manifestSuffix : '');
$newFull = $suffix !== '' ? "{$new}-{$suffix}" : $new;
// -- Update .mokogitea/manifest.xml (canonical target, no suffix) --
// -- Update .mokogitea/manifest.xml (canonical — preserves suffix) --
if (file_exists($mokoManifest) && !empty($mokoContent)) {
$updated = preg_replace(
'|<version>\d{2}\.\d{2}\.\d{2}(?:-[a-z]+)?</version>|',
"<version>{$new}</version>",
"<version>{$newFull}</version>",
$mokoContent,
1
);
+2 -2
View File
@@ -30,7 +30,7 @@ if (file_exists($mokoManifest)) {
$xml = @simplexml_load_file($mokoManifest);
if ($xml !== false) {
$v = (string)($xml->identity->version ?? '');
if (preg_match('/^\d{2}\.\d{2}\.\d{2}$/', $v)) {
if (preg_match('/^\d{2}\.\d{2}\.\d{2}(-[a-z]+)?$/', $v)) {
$mokoVersion = $v;
}
}
@@ -127,7 +127,7 @@ if ($versionSource === 'manifest' && !empty($manifestVersionSuffix)) {
// -- Backfill: if manifest.xml exists but lacks <version>, insert it --
if (file_exists($mokoManifest)) {
$content = file_get_contents($mokoManifest);
if (!preg_match('|<version>\d{2}\.\d{2}\.\d{2}</version>|', $content)) {
if (!preg_match('|<version>\d{2}\.\d{2}\.\d{2}(-[a-z]+)?</version>|', $content)) {
if (strpos($content, '<license') !== false) {
$content = preg_replace(
'|(\s*<license)|',