From 66da3fa30c2caff466937a753f256c745fd1ebd1 Mon Sep 17 00:00:00 2001 From: Jonathan Miller Date: Tue, 23 Jun 2026 17:13:02 -0500 Subject: [PATCH] feat: make version bumps and pre-releases source-aware MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reads .mokogitea/manifest.xml to detect platform and source directory. Skips bumps and pre-releases when only workflows, docs, or config files change — no more empty version increments. - auto-bump: skips if no source files changed in last commit - pre-release: skips build if push didn't touch source (dispatch always runs) - Falls back to always-bump for generic repos without a manifest Authored-by: Moko Consulting --- .mokogitea/workflows/auto-bump.yml | 47 +++++++++++++++++++++++- .mokogitea/workflows/pre-release.yml | 53 +++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 2 deletions(-) diff --git a/.mokogitea/workflows/auto-bump.yml b/.mokogitea/workflows/auto-bump.yml index cb078c6..812a0dc 100644 --- a/.mokogitea/workflows/auto-bump.yml +++ b/.mokogitea/workflows/auto-bump.yml @@ -41,9 +41,53 @@ jobs: uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 with: token: ${{ secrets.MOKOGITEA_TOKEN }} - fetch-depth: 1 + fetch-depth: 2 + + - name: Check for source changes + id: source-check + run: | + # Read platform and source directory from manifest + PLATFORM="" + SOURCE_DIR="" + if [ -f ".mokogitea/manifest.xml" ]; then + PLATFORM=$(grep -oP '\K[^<]+' .mokogitea/manifest.xml 2>/dev/null || true) + SOURCE_DIR=$(grep -oP '\K[^<]+' .mokogitea/manifest.xml 2>/dev/null || true) + ENTRY=$(grep -oP '\K[^<]+' .mokogitea/manifest.xml 2>/dev/null || true) + SOURCE_DIR="${SOURCE_DIR:-$ENTRY}" + fi + + # Default source dirs by platform + if [ -z "$SOURCE_DIR" ]; then + case "$PLATFORM" in + joomla) SOURCE_DIR="src/ source/ htdocs/" ;; + dolibarr) SOURCE_DIR="src/ htdocs/" ;; + *) SOURCE_DIR="" ;; + esac + fi + + # If no platform or source dir, always bump (generic repos) + if [ -z "$SOURCE_DIR" ]; then + echo "has_source_changes=true" >> "$GITHUB_OUTPUT" + echo "No platform manifest — defaulting to bump" + exit 0 + fi + + # Check if the last commit touched any source files + CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || true) + HAS_CHANGES=false + for DIR in $SOURCE_DIR; do + DIR="${DIR%/}" + if echo "$CHANGED" | grep -q "^${DIR}/"; then + HAS_CHANGES=true + break + fi + done + + echo "has_source_changes=$HAS_CHANGES" >> "$GITHUB_OUTPUT" + echo "Platform: ${PLATFORM:-generic}, Source: ${SOURCE_DIR}, Changes: ${HAS_CHANGES}" - name: Setup mokocli tools + if: steps.source-check.outputs.has_source_changes == 'true' run: | if ! command -v composer &> /dev/null; then sudo apt-get update -qq && sudo apt-get install -y -qq php-cli php-mbstring php-xml php-zip php-curl composer >/dev/null 2>&1 @@ -59,6 +103,7 @@ jobs: fi - name: Bump version + if: steps.source-check.outputs.has_source_changes == 'true' run: | php ${MOKO_CLI}/version_auto_bump.php \ --path . --branch "${GITHUB_REF_NAME}" \ diff --git a/.mokogitea/workflows/pre-release.yml b/.mokogitea/workflows/pre-release.yml index 2755d7c..17488cb 100644 --- a/.mokogitea/workflows/pre-release.yml +++ b/.mokogitea/workflows/pre-release.yml @@ -55,11 +55,56 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-depth: 2 token: ${{ secrets.MOKOGITEA_TOKEN }} ref: ${{ github.ref_name }} + - name: Check for source changes + id: source-check + if: github.event_name == 'push' + run: | + # Read platform and source directory from manifest + PLATFORM="" + SOURCE_DIR="" + if [ -f ".mokogitea/manifest.xml" ]; then + PLATFORM=$(grep -oP '\K[^<]+' .mokogitea/manifest.xml 2>/dev/null || true) + SOURCE_DIR=$(grep -oP '\K[^<]+' .mokogitea/manifest.xml 2>/dev/null || true) + ENTRY=$(grep -oP '\K[^<]+' .mokogitea/manifest.xml 2>/dev/null || true) + SOURCE_DIR="${SOURCE_DIR:-$ENTRY}" + fi + + # Default source dirs by platform + if [ -z "$SOURCE_DIR" ]; then + case "$PLATFORM" in + joomla) SOURCE_DIR="src/ source/ htdocs/" ;; + dolibarr) SOURCE_DIR="src/ htdocs/" ;; + *) SOURCE_DIR="" ;; + esac + fi + + # If no platform or source dir, always build (generic repos) + if [ -z "$SOURCE_DIR" ]; then + echo "has_source_changes=true" >> "$GITHUB_OUTPUT" + echo "No platform manifest — defaulting to build" + exit 0 + fi + + # Check if the last commit touched any source files + CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || true) + HAS_CHANGES=false + for DIR in $SOURCE_DIR; do + DIR="${DIR%/}" + if echo "$CHANGED" | grep -q "^${DIR}/"; then + HAS_CHANGES=true + break + fi + done + + echo "has_source_changes=$HAS_CHANGES" >> "$GITHUB_OUTPUT" + echo "Platform: ${PLATFORM:-generic}, Source: ${SOURCE_DIR}, Changes: ${HAS_CHANGES}" + - name: Setup mokocli tools + if: github.event_name == 'workflow_dispatch' || steps.source-check.outputs.has_source_changes == 'true' env: MOKO_CLONE_TOKEN: ${{ secrets.MOKOGITEA_TOKEN }} MOKO_CLONE_HOST: git.mokoconsulting.tech/MokoConsulting @@ -81,6 +126,7 @@ jobs: fi - name: Detect platform + if: github.event_name == 'workflow_dispatch' || steps.source-check.outputs.has_source_changes == 'true' id: platform run: | # Auto-detect and update platform if not set in manifest @@ -88,6 +134,7 @@ jobs: php ${MOKO_CLI}/manifest_read.php --path . --github-output - name: Resolve metadata and bump version + if: github.event_name == 'workflow_dispatch' || steps.source-check.outputs.has_source_changes == 'true' id: meta run: | # Auto-detect stability from branch name on push, or use input on dispatch @@ -164,6 +211,7 @@ jobs: echo "=== Pre-Release: ${EXT_ELEMENT} ${VERSION}${SUFFIX} ===" - name: Create release + if: github.event_name == 'workflow_dispatch' || steps.source-check.outputs.has_source_changes == 'true' id: release run: | TAG="${{ steps.meta.outputs.tag }}" @@ -175,6 +223,7 @@ jobs: --repo "${GITEA_REPO}" --branch "${{ github.ref_name }}" --prerelease - name: Update release notes from CHANGELOG.md + if: github.event_name == 'workflow_dispatch' || steps.source-check.outputs.has_source_changes == 'true' run: | TAG="${{ steps.meta.outputs.tag }}" VERSION="${{ steps.meta.outputs.version }}" @@ -210,6 +259,7 @@ jobs: fi - name: Build package and upload + if: github.event_name == 'workflow_dispatch' || steps.source-check.outputs.has_source_changes == 'true' id: package run: | VERSION="${{ steps.meta.outputs.version }}" @@ -224,6 +274,7 @@ jobs: # No need to build, commit, or sync updates.xml from workflows - name: "Delete lesser pre-release channels (cascade)" + if: github.event_name == 'workflow_dispatch' || steps.source-check.outputs.has_source_changes == 'true' continue-on-error: true run: | API_BASE="${GITEA_URL}/api/v1/repos/${GITEA_ORG}/${GITEA_REPO}"