Skip to content

Commit 3cccae3

Browse files
committed
Auto-release patch versions on push to main
- release.yml: auto-increment patch version, create tag + GitHub release - build.yml: trigger on version tags only (not push to main) - Flow: push to main → auto-bump v0.1.x → tag triggers Docker build
1 parent 0fb434f commit 3cccae3

2 files changed

Lines changed: 43 additions & 15 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,7 @@ name: Build and Push Docker Images
22

33
on:
44
push:
5-
branches: [main]
65
tags: ["v*"]
7-
paths:
8-
- 'Dockerfile'
9-
- 'Dockerfile.worker'
10-
- 'requirements.txt'
11-
- 'requirements-worker.txt'
12-
- 'app/**'
13-
- 'services/**'
14-
- '.github/workflows/build.yml'
156
workflow_dispatch:
167

178
concurrency:
@@ -72,7 +63,7 @@ jobs:
7263
with:
7364
images: ${{ matrix.image }}
7465
tags: |
75-
type=raw,value=latest,enable={{is_default_branch}}
66+
type=raw,value=latest
7667
type=semver,pattern={{version}}
7768
type=semver,pattern={{major}}.{{minor}}
7869

.github/workflows/release.yml

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,63 @@
1-
name: GitHub Release
1+
name: Auto Release
22

33
on:
44
push:
5-
tags:
6-
- "v*.*.*"
5+
branches: [main]
6+
paths:
7+
- 'Dockerfile'
8+
- 'Dockerfile.worker'
9+
- 'requirements.txt'
10+
- 'requirements-worker.txt'
11+
- 'app/**'
12+
- 'services/**'
13+
workflow_dispatch:
714

815
permissions:
916
contents: write
1017

1118
jobs:
1219
release:
13-
name: Create GitHub Release
20+
name: Bump version and release
1421
runs-on: ubuntu-latest
22+
# Skip releases triggered by the release workflow itself
23+
if: "!contains(github.event.head_commit.message, '[skip ci]')"
1524
steps:
1625
- name: Checkout code
1726
uses: actions/checkout@v4
1827
with:
1928
fetch-depth: 0
2029

21-
- name: Create Release
30+
- name: Get latest version tag
31+
id: version
32+
run: |
33+
# Get the latest semver tag, default to v0.0.0 if none
34+
LATEST=$(git tag -l 'v*.*.*' --sort=-v:refname | head -1)
35+
if [ -z "$LATEST" ]; then
36+
LATEST="v0.0.0"
37+
fi
38+
echo "latest=$LATEST" >> "$GITHUB_OUTPUT"
39+
40+
# Increment patch version
41+
VERSION="${LATEST#v}"
42+
MAJOR=$(echo "$VERSION" | cut -d. -f1)
43+
MINOR=$(echo "$VERSION" | cut -d. -f2)
44+
PATCH=$(echo "$VERSION" | cut -d. -f3)
45+
NEW_PATCH=$((PATCH + 1))
46+
NEW_TAG="v${MAJOR}.${MINOR}.${NEW_PATCH}"
47+
echo "new_tag=$NEW_TAG" >> "$GITHUB_OUTPUT"
48+
echo "Bumping $LATEST -> $NEW_TAG"
49+
50+
- name: Create and push tag
51+
run: |
52+
git config user.name "github-actions[bot]"
53+
git config user.email "github-actions[bot]@users.noreply.github.com"
54+
git tag -a "${{ steps.version.outputs.new_tag }}" -m "Release ${{ steps.version.outputs.new_tag }}"
55+
git push origin "${{ steps.version.outputs.new_tag }}"
56+
57+
- name: Create GitHub Release
2258
uses: softprops/action-gh-release@v2
2359
with:
60+
tag_name: ${{ steps.version.outputs.new_tag }}
2461
generate_release_notes: true
2562
draft: false
2663
prerelease: false

0 commit comments

Comments
 (0)