Skip to content

Commit 98ef7dd

Browse files
committed
Enhance GitHub Actions workflow for Docker image release
1 parent 34679f7 commit 98ef7dd

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: release docker image
22

33
on:
4+
# Trigger when a GitHub Release is published (stable or pre-release).
45
release:
56
types: [published]
7+
# Trigger when tags like v1.2.3 or 1.2.3 are pushed.
68
push:
79
tags:
810
- 'v*.*.*'
@@ -12,41 +14,68 @@ jobs:
1214
publish:
1315
runs-on: ubuntu-latest
1416

17+
# Unify tag name across events and keep repo name handy.
18+
env:
19+
REF_NAME: ${{ github.ref_name || github.event.release.tag_name }}
20+
DOCKERHUB_REPO: ${{ vars.DOCKERHUB_REPO }}
21+
1522
steps:
1623
- name: Checkout
1724
uses: actions/checkout@v4
25+
with:
26+
# Fetch full history so metadata-action can parse semver/tag properly.
27+
fetch-depth: 0
1828

1929
- name: Login to Docker Hub
2030
uses: docker/login-action@v3
2131
with:
2232
username: ${{ secrets.DOCKERHUB_USERNAME }}
2333
password: ${{ secrets.DOCKERHUB_TOKEN }}
2434

25-
- name: Set up QEMU (multi-arch)
35+
- name: Set up QEMU (for multi-arch builds)
2636
uses: docker/setup-qemu-action@v3
2737

28-
- name: Set up Buildx
38+
- name: Set up Docker Buildx
2939
uses: docker/setup-buildx-action@v3
3040

31-
- name: Docker meta (генерує теги/лейбли з семвер-тега)
41+
- name: Docker meta (derive tags/labels from the git tag)
3242
id: meta
3343
uses: docker/metadata-action@v5
3444
with:
35-
images: ${{ secrets.DOCKERHUB_REPO }} # напр. volodymyr/myapp
45+
images: ${{ env.DOCKERHUB_REPO }}
46+
# Tag strategy:
47+
# - Always publish the full semver from the git tag (includes -beta/-rc).
48+
# - Publish short tags (major.minor, major) only for stable tags (no hyphen).
49+
# - Move the "latest" channel only for stable tags.
50+
# - Move the "beta" channel when the tag contains "-beta".
3651
tags: |
52+
# Full version (e.g., 1.4.0 or 1.4.0-beta.2)
3753
type=semver,pattern={{version}},priority=100
38-
type=semver,pattern={{major}}.{{minor}},priority=90
39-
type=semver,pattern={{major}},priority=80
54+
55+
# Short tags only for stable (no hyphen in tag)
56+
type=semver,pattern={{major}}.{{minor}},priority=90,enable=${{ !contains(env.REF_NAME, '-') }}
57+
type=semver,pattern={{major}},priority=80,enable=${{ !contains(env.REF_NAME, '-') }}
58+
59+
# Stable channel
60+
type=raw,value=latest,priority=70,enable=${{ !contains(env.REF_NAME, '-') }}
61+
62+
# Beta channel (rolling tag pointing to the newest beta)
63+
type=raw,value=beta,priority=60,enable=${{ contains(env.REF_NAME, '-beta') }}
64+
65+
# (Optional) RC channel:
66+
# type=raw,value=rc,priority=60,enable=${{ contains(env.REF_NAME, '-rc') }}
67+
# Add common OCI labels (source, version, etc.)
4068
flavor: |
41-
latest=auto
69+
latest=false
4270
4371
- name: Build and push
4472
uses: docker/build-push-action@v6
4573
with:
4674
context: .
47-
push: true
75+
push: true # Always push on these events
4876
platforms: linux/amd64,linux/arm64
4977
tags: ${{ steps.meta.outputs.tags }}
5078
labels: ${{ steps.meta.outputs.labels }}
79+
# GitHub Actions cache for faster subsequent builds
5180
cache-from: type=gha
5281
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)