name: Version on: push: branches: [development, main] permissions: contents: write jobs: bump: if: github.actor != 'github-actions[bot]' runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GITHUB_TOKEN }} - name: Configure git run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - name: Bump version run: | set -euo pipefail current=$(cat VERSION) IFS=. read -r major minor patch <<< "$current" if [ "${{ github.ref_name }}" = "development" ]; then patch=$((patch + 1)) else # main: PATCH+1 for a direct hotfix push, MINOR+1/PATCH=0 when every # commit in this push came from development (an approved PR merge). merge_base=$(git merge-base origin/development HEAD 2>/dev/null || echo "") before="${{ github.event.before }}" if [ -n "$merge_base" ] && [ -n "$before" ] && [ "$before" != "0000000000000000000000000000000000000000" ] \ && git merge-base --is-ancestor "$before" origin/development 2>/dev/null; then minor=$((minor + 1)) patch=0 else patch=$((patch + 1)) fi fi new_version="$major.$minor.$patch" echo "$new_version" > VERSION git add VERSION git commit -m "chore(release): v$new_version [skip ci]" git tag "v$new_version" - name: Push changes run: git push origin HEAD:${{ github.ref_name }} --follow-tags - name: Merge main back into development if: github.ref_name == 'main' run: | set -euo pipefail git fetch origin development git checkout development git merge --no-edit origin/main git push origin development