Skip to content

Commit 79b9ebd

Browse files
committed
feat: add smarter caching #release
1 parent 80d51f3 commit 79b9ebd

File tree

2 files changed

+55
-19
lines changed

2 files changed

+55
-19
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,87 @@
1+
# .github/workflows/ci.yml
12
name: CI (Auto-tag + Build & Push Docker on SemVer)
23

34
on:
45
push:
5-
branches: [ "main" ]
6-
tags: [ "v*.*.*", "*.*.*" ]
6+
branches: [ "main" ] # main pushes can create a tag (no image push)
7+
tags: [ "v*.*.*", "*.*.*" ] # tag pushes build & push the SemVer image
78
workflow_dispatch: {}
89

910
env:
1011
REGISTRY: docker.io
1112
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/gabs-redis-langcache
1213
DOCKERFILE: ./Dockerfile
1314

15+
# We need write so the job can create a tag via GitHub API
1416
permissions:
15-
contents: write # <-- gives GITHUB_TOKEN push access to create tags
17+
contents: write
1618

1719
jobs:
18-
# 1️⃣ main branch: bump + tag if '#release' present
20+
# 1) MAIN PUSH: if any commit message includes #release, create next SemVer tag (no Docker build here)
1921
auto-release:
20-
if: ${{ github.ref == 'refs/heads/main' && contains(join(github.event.commits.*.message, ' '), '#release') }}
22+
if: ${{ github.ref == 'refs/heads/main' }}
2123
runs-on: ubuntu-latest
2224
steps:
23-
- uses: actions/checkout@v4
25+
- name: Checkout (full history for tags)
26+
uses: actions/checkout@v4
2427
with:
2528
fetch-depth: 0
2629

27-
- name: Bump patch version and create tag
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'
44+
shell: bash
2845
run: |
2946
set -e
30-
LAST=$(git tag -l 'v*' --sort=-v:refname | head -n1)
47+
LAST=$(git tag -l 'v*.*.*' --sort=-v:refname | head -n1)
3148
[ -z "$LAST" ] && LAST="v0.0.0"
3249
VER=${LAST#v}
3350
IFS='.' read -r MA MI PA <<<"$VER"
3451
NEW_TAG="v$MA.$MI.$((PA+1))"
35-
echo "Creating $NEW_TAG"
36-
git config user.name "github-actions[bot]"
37-
git config user.email "github-actions[bot]@users.noreply.github.com"
38-
git tag -a "$NEW_TAG" -m "release $NEW_TAG"
39-
git push origin "$NEW_TAG"
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"
55+
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 }}
4071

41-
# 2️⃣ tag events: build + push ONLY semver tags
72+
# 2) TAG PUSH: ONLY build & push the SemVer image
4273
build-and-push:
4374
if: startsWith(github.ref, 'refs/tags/')
4475
runs-on: ubuntu-latest
4576
steps:
46-
- uses: actions/checkout@v4
47-
- uses: docker/setup-qemu-action@v3
48-
- uses: docker/setup-buildx-action@v3
77+
- name: Checkout
78+
uses: actions/checkout@v4
79+
80+
- name: Set up QEMU
81+
uses: docker/setup-qemu-action@v3
82+
83+
- name: Set up Buildx
84+
uses: docker/setup-buildx-action@v3
4985

5086
- name: Log in to Docker Hub
5187
uses: docker/login-action@v3
@@ -54,7 +90,7 @@ jobs:
5490
username: ${{ secrets.DOCKERHUB_USERNAME }}
5591
password: ${{ secrets.DOCKERHUB_TOKEN }}
5692

57-
- name: Extract Docker metadata
93+
- name: Extract Docker metadata (SemVer only)
5894
id: meta
5995
uses: docker/metadata-action@v5
6096
with:

main_demo_released.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def calc_savings(tokens_est: int, price_in: float, price_out: float, frac_in: fl
595595
<div class="app-header">
596596
<div class="brand">
597597
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/Redis_logo.svg/2560px-Redis_logo.svg.png" alt="Redis">
598-
<div class="title">Redis LangCache — Demo PT-BR - SemVer: v2.0.8-harness - PR GitHub: gacerioni</div>
598+
<div class="title">Redis LangCache — Demo PT-BR - SemVer: v2.0.9-harness - PR GitHub: gacerioni</div>
599599
</div>
600600
<div class="links">
601601
<a href="https://www.linkedin.com/in/gabrielcerioni/" target="_blank" rel="noopener">💼 LinkedIn do Gabs</a>

0 commit comments

Comments
 (0)