11# .github/workflows/ci.yml
2- name : CI (Build & Push Docker)
2+ name : CI (Build & Push Docker + Auto Release )
33
44on :
55 push :
66 branches : [ "main" ]
7- tags : [ "v*.*.*" ] # allow v2.0.1 or 2.0.1 (keep only the one you use)
7+ tags : [ "v*.*.*", "*.*.*" ] # supports v2.0.1 or 2.0.1
88 workflow_dispatch : {}
99
1010env :
1313 DOCKERFILE : ./Dockerfile
1414
1515permissions :
16- contents : read
16+ contents : write # needed to push tags & create releases
1717
1818jobs :
1919 build-and-push :
4444 uses : docker/metadata-action@v5
4545 with :
4646 images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
47- # Only SemVer on tag events; only latest/branch/sha on branch events
47+ # Only SemVer on tag events; latest/branch/sha on main pushes
4848 tags : |
4949 type=semver,pattern={{version}},enable=${{ github.ref_type == 'tag' }}
5050 type=raw,value=latest,enable=${{ github.ref_type == 'branch' && github.ref_name == 'main' }}
7474 labels : ${{ steps.meta.outputs.labels }}
7575 cache-from : type=gha
7676 cache-to : type=gha,mode=max
77- provenance : false
77+ provenance : false
78+
79+ auto-release :
80+ needs : build-and-push
81+ if : contains(github.event.head_commit.message, '#release')
82+ runs-on : ubuntu-latest
83+ steps :
84+ - name : Checkout
85+ uses : actions/checkout@v4
86+ with :
87+ fetch-depth : 0 # need full history for tags
88+
89+ - name : Bump patch version and create tag
90+ id : bump
91+ run : |
92+ set -e
93+ LAST=$(git tag -l 'v*' --sort=-v:refname | head -n1)
94+ if [ -z "$LAST" ]; then LAST="v0.0.0"; fi
95+ VER=${LAST#v}
96+ IFS='.' read -r MA MI PA <<<"$VER"
97+ NEW_TAG="v$MA.$MI.$((PA+1))"
98+ echo "New tag: $NEW_TAG"
99+ git config user.name "github-actions[bot]"
100+ git config user.email "github-actions[bot]@users.noreply.github.com"
101+ git tag -a "$NEW_TAG" -m "release $NEW_TAG"
102+ git push origin "$NEW_TAG"
103+ echo "tag=$NEW_TAG" >> $GITHUB_OUTPUT
104+
105+ - name : Create GitHub Release
106+ uses : softprops/action-gh-release@v2
107+ with :
108+ tag_name : ${{ steps.bump.outputs.tag }}
109+ name : Release ${{ steps.bump.outputs.tag }}
110+ body : |
111+ 🚀 Automated release from CI.
112+ env :
113+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments