11# .github/workflows/ci.yml
2- name : CI (Auto-tag on main + Push Docker on SemVer tag )
2+ name : CI (Auto-tag + Push Docker)
33
44on :
55 push :
6- branches : [ "main" ] # main push -> create next tag (no Docker push)
7- tags : [ "v*.*.*", "*.*.*" ] # tag push -> build & push the SemVer image
6+ branches : [ "main" ]
87 workflow_dispatch : {}
98
109env :
@@ -17,43 +16,70 @@ permissions:
1716 contents : write
1817
1918jobs :
20- # 1) MAIN: always bump & create next patch tag. NO Docker build here.
21- auto-tag :
22- if : ${{ github.ref == 'refs/heads/main' }}
19+ build-and-push :
2320 runs-on : ubuntu-latest
21+ outputs :
22+ new_tag : ${{ steps.bump.outputs.new_tag }}
2423 steps :
2524 - name : Checkout (full history)
2625 uses : actions/checkout@v4
2726 with :
2827 fetch-depth : 0
2928
30- - name : Bump patch and create tag
29+ - name : Determine version bump from commit message
30+ id : bump
3131 shell : bash
3232 run : |
3333 set -e
34+
35+ # Get the last tag
3436 LAST=$(git tag -l 'v*.*.*' --sort=-v:refname | head -n1)
3537 [ -z "$LAST" ] && LAST="v0.0.0"
38+
39+ # Parse version
3640 VER=${LAST#v}
37- IFS='.' read -r MA MI PA <<<"$VER"
38- NEW_TAG="v$MA.$MI.$((PA+1))"
39- echo "Last: $LAST -> New: $NEW_TAG"
41+ IFS='.' read -r MAJOR MINOR PATCH <<<"$VER"
4042
41- git config user.name "github-actions[bot]"
42- git config user.email "github-actions[bot]@users.noreply.github.com"
43+ # Get commit message
44+ COMMIT_MSG="${{ github.event.head_commit.message }}"
45+ echo "Commit message: $COMMIT_MSG"
4346
44- # Create annotated tag on the pushed commit (HEAD of main)
45- git tag -a "$NEW_TAG" -m "release $NEW_TAG"
47+ # Determine bump type from conventional commit
48+ if echo "$COMMIT_MSG" | grep -qiE '^(feat|feature)(\(.*\))?!:|^BREAKING CHANGE:'; then
49+ # Breaking change -> major bump
50+ MAJOR=$((MAJOR+1))
51+ MINOR=0
52+ PATCH=0
53+ BUMP_TYPE="major"
54+ elif echo "$COMMIT_MSG" | grep -qiE '^(feat|feature)(\(.*\))?:'; then
55+ # Feature -> minor bump
56+ MINOR=$((MINOR+1))
57+ PATCH=0
58+ BUMP_TYPE="minor"
59+ else
60+ # Everything else (fix, chore, docs, etc.) -> patch bump
61+ PATCH=$((PATCH+1))
62+ BUMP_TYPE="patch"
63+ fi
4664
47- # Push tag using GITHUB_TOKEN (requires 'contents: write' + repo setting 'Read and write')
48- git push origin "$NEW_TAG"
65+ NEW_TAG="v$MAJOR.$MINOR.$PATCH"
66+ echo "Last tag: $LAST"
67+ echo "Bump type: $BUMP_TYPE"
68+ echo "New tag: $NEW_TAG"
4969
50- # 2) TAG: ONLY build & push the SemVer image to Docker Hub.
51- push-image :
52- if : startsWith(github.ref, 'refs/tags/')
53- runs-on : ubuntu-latest
54- steps :
55- - name : Checkout
56- uses : actions/checkout@v4
70+ # Export for next steps
71+ echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
72+ echo "version=$MAJOR.$MINOR.$PATCH" >> $GITHUB_OUTPUT
73+ echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
74+
75+ - name : Create and push tag
76+ shell : bash
77+ run : |
78+ git config user.name "github-actions[bot]"
79+ git config user.email "github-actions[bot]@users.noreply.github.com"
80+
81+ git tag -a "${{ steps.bump.outputs.new_tag }}" -m "release ${{ steps.bump.outputs.new_tag }} (${{ steps.bump.outputs.bump_type }} bump)"
82+ git push origin "${{ steps.bump.outputs.new_tag }}"
5783
5884 - name : Set up QEMU
5985 uses : docker/setup-qemu-action@v3
@@ -68,27 +94,30 @@ jobs:
6894 username : ${{ secrets.DOCKERHUB_USERNAME }}
6995 password : ${{ secrets.DOCKERHUB_TOKEN }}
7096
71- - name : Extract Docker metadata (SemVer only)
72- id : meta
73- uses : docker/metadata-action@v5
74- with :
75- images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
76- tags : |
77- type=semver,pattern={{version}}
78- labels : |
79- org.opencontainers.image.title=${{ github.event.repository.name }}
80- org.opencontainers.image.source=${{ github.repository }}
81- org.opencontainers.image.revision=${{ github.sha }}
82-
83- - name : Build & Push SemVer image
97+ - name : Build & Push Docker image
8498 uses : docker/build-push-action@v6
8599 with :
86100 context : .
87101 file : ${{ env.DOCKERFILE }}
88102 push : true
89103 platforms : linux/amd64,linux/arm64
90- tags : ${{ steps.meta.outputs.tags }}
91- labels : ${{ steps.meta.outputs.labels }}
104+ tags : |
105+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.bump.outputs.version }}
106+ ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
107+ labels : |
108+ org.opencontainers.image.title=${{ github.event.repository.name }}
109+ org.opencontainers.image.source=${{ github.repository }}
110+ org.opencontainers.image.revision=${{ github.sha }}
111+ org.opencontainers.image.version=${{ steps.bump.outputs.version }}
92112 cache-from : type=gha
93113 cache-to : type=gha,mode=max
94- provenance : false
114+ provenance : false
115+
116+ - name : Summary
117+ run : |
118+ echo "## 🚀 Release Summary" >> $GITHUB_STEP_SUMMARY
119+ echo "" >> $GITHUB_STEP_SUMMARY
120+ echo "- **Version**: ${{ steps.bump.outputs.new_tag }}" >> $GITHUB_STEP_SUMMARY
121+ echo "- **Bump Type**: ${{ steps.bump.outputs.bump_type }}" >> $GITHUB_STEP_SUMMARY
122+ echo "- **Docker Image**: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.bump.outputs.version }}" >> $GITHUB_STEP_SUMMARY
123+ echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
0 commit comments