11# .github/workflows/ci.yml
2- name : CI (Auto-tag + Build & Push Docker on SemVer)
2+ name : CI (Auto-tag on main + Push Docker on SemVer tag )
33
44on :
55 push :
6- branches : [ "main" ] # main pushes can create a tag (no image push)
7- tags : [ "v*.*.*", "*.*.*" ] # tag pushes build & push the SemVer image
6+ branches : [ "main" ] # main push -> create next tag (no Docker push)
7+ tags : [ "v*.*.*", "*.*.*" ] # tag push -> build & push the SemVer image
88 workflow_dispatch : {}
99
1010env :
1111 REGISTRY : docker.io
1212 IMAGE_NAME : ${{ secrets.DOCKERHUB_USERNAME }}/gabs-redis-langcache
1313 DOCKERFILE : ./Dockerfile
1414
15- # We need write so the job can create a tag via GitHub API
15+ # Needed so GITHUB_TOKEN can create tags
1616permissions :
1717 contents : write
1818
1919jobs :
20- # 1) MAIN PUSH: if any commit message includes #release, create next SemVer tag (no Docker build here)
21- auto-release :
20+ # 1) MAIN: always bump & create next patch tag. NO Docker build here.
21+ auto-tag :
2222 if : ${{ github.ref == 'refs/heads/main' }}
2323 runs-on : ubuntu-latest
2424 steps :
25- - name : Checkout (full history for tags )
25+ - name : Checkout (full history)
2626 uses : actions/checkout@v4
2727 with :
2828 fetch-depth : 0
2929
30- - name : Decide if this push requests a release
31- id : decide
32- run : |
33- MSGS="${{ join(github.event.commits.*.message, ' | ') }}"
34- echo "Commit messages: $MSGS"
35- if echo "$MSGS" | grep -q '#release'; then
36- echo "release=yes" >> $GITHUB_OUTPUT
37- else
38- echo "release=no" >> $GITHUB_OUTPUT
39- fi
40-
41- - name : Compute next patch tag (vX.Y.Z -> vX.Y.(Z+1))
42- id : bump
43- if : steps.decide.outputs.release == 'yes'
30+ - name : Bump patch and create tag
4431 shell : bash
4532 run : |
4633 set -e
@@ -49,28 +36,19 @@ jobs:
4936 VER=${LAST#v}
5037 IFS='.' read -r MA MI PA <<<"$VER"
5138 NEW_TAG="v$MA.$MI.$((PA+1))"
52- echo "NEW_TAG=$NEW_TAG" >> $GITHUB_ENV
53- echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
54- echo "Last tag: $LAST -> Next tag: $NEW_TAG"
39+ echo "Last: $LAST -> New: $NEW_TAG"
5540
56- - name : Create git tag via GitHub API
57- if : steps.decide.outputs.release == 'yes'
58- uses : actions/github-script@v7
59- with :
60- script : |
61- const newTag = process.env.NEW_TAG; // from $GITHUB_ENV
62- core.info(`Creating tag ${newTag} at ${context.sha}`);
63- await github.rest.git.createRef({
64- owner: context.repo.owner,
65- repo: context.repo.repo,
66- ref: `refs/tags/${newTag}`,
67- sha: context.sha
68- });
69- env :
70- NEW_TAG : ${{ env.NEW_TAG }}
41+ git config user.name "github-actions[bot]"
42+ git config user.email "github-actions[bot]@users.noreply.github.com"
43+
44+ # Create annotated tag on the pushed commit (HEAD of main)
45+ git tag -a "$NEW_TAG" -m "release $NEW_TAG"
46+
47+ # Push tag using GITHUB_TOKEN (requires 'contents: write' + repo setting 'Read and write')
48+ git push origin "$NEW_TAG"
7149
72- # 2) TAG PUSH : ONLY build & push the SemVer image
73- build-and- push :
50+ # 2) TAG: ONLY build & push the SemVer image to Docker Hub.
51+ push-image :
7452 if : startsWith(github.ref, 'refs/tags/')
7553 runs-on : ubuntu-latest
7654 steps :
0 commit comments