diff --git a/.mokogitea/workflows/sync-feature-versions.yml b/.mokogitea/workflows/sync-feature-versions.yml new file mode 100644 index 0000000..7682008 --- /dev/null +++ b/.mokogitea/workflows/sync-feature-versions.yml @@ -0,0 +1,103 @@ +# Copyright (C) 2026 Moko Consulting +# +# SPDX-License-Identifier: GPL-3.0-or-later +# +# FILE INFORMATION +# DEFGROUP: Gitea.Workflow +# INGROUP: mokocli.Automation +# REPO: https://git.mokoconsulting.tech/MokoConsulting/mokocli +# PATH: /.mokogitea/workflows/sync-feature-versions.yml +# VERSION: 01.00.00 +# BRIEF: Merge dev into open feature branches after version bumps + +name: "Universal: Sync Feature Branch Versions" + +on: + push: + branches: + - dev + workflow_dispatch: + +permissions: + contents: write + +env: + GITEA_URL: ${{ vars.GITEA_URL || 'https://git.mokoconsulting.tech' }} + +jobs: + sync: + name: Sync feature branches with dev + runs-on: ubuntu-latest + if: >- + github.event_name == 'workflow_dispatch' || + contains(github.event.head_commit.message, 'chore(version)') + + steps: + - name: Checkout dev + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: dev + token: ${{ secrets.MOKOGITEA_TOKEN }} + + - name: Configure git + run: | + git config --local user.email "gitea-actions[bot]@mokoconsulting.tech" + 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" + + - name: Merge dev into feature branches + run: | + echo "=== Syncing feature branches with dev ===" + + # Fetch all remote branches + git fetch origin + + # Find feature branches (feature/*, fix/*, patch/*, hotfix/*, bugfix/*, chore/*) + BRANCHES=$(git branch -r --list 'origin/feature/*' 'origin/fix/*' 'origin/patch/*' 'origin/hotfix/*' 'origin/bugfix/*' 'origin/chore/*' | sed 's|origin/||; s/^[[:space:]]*//') + + if [ -z "$BRANCHES" ]; then + echo "No feature branches found — nothing to sync" + exit 0 + fi + + SYNCED=0 + SKIPPED=0 + FAILED=0 + + for BRANCH in $BRANCHES; do + echo "" + echo "--- ${BRANCH} ---" + + # Skip branches that are already up to date with dev + if git merge-base --is-ancestor dev "origin/${BRANCH}" 2>/dev/null; then + echo "Already up to date" + SKIPPED=$((SKIPPED + 1)) + continue + fi + + # Try to merge dev into the branch + git checkout "origin/${BRANCH}" -B "$BRANCH" 2>/dev/null + if git merge dev --no-edit -m "chore: merge dev into ${BRANCH} (version sync) [skip ci]" 2>/dev/null; then + git push origin "$BRANCH" 2>/dev/null + echo "Synced successfully" + SYNCED=$((SYNCED + 1)) + else + git merge --abort 2>/dev/null || true + echo "Merge conflict — skipping (manual rebase needed)" + FAILED=$((FAILED + 1)) + fi + done + + # Return to dev + git checkout dev 2>/dev/null || true + + echo "" + echo "=== Summary ===" + echo "Synced: ${SYNCED}" + echo "Already current: ${SKIPPED}" + echo "Conflicts (skipped): ${FAILED}" + + if [ "$FAILED" -gt 0 ]; then + echo "::warning::${FAILED} branch(es) had merge conflicts and need manual rebase" + fi