Skip to content

Commit 86e162c

Browse files
committed
Auto. tag releases
1 parent 5dbc7e9 commit 86e162c

1 file changed

Lines changed: 34 additions & 17 deletions

File tree

.github/workflows/docker-publish.yml

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,34 @@ jobs:
1515
build-and-push:
1616
runs-on: ubuntu-latest
1717
permissions:
18-
contents: read
18+
contents: write
1919
packages: write
2020

2121
steps:
2222
- name: Checkout
2323
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0 # needed to inspect all tags for version bumping
26+
27+
- name: Compute next version
28+
id: version
29+
run: |
30+
if [[ "$GITHUB_REF" == refs/tags/* ]]; then
31+
# Triggered by a manual tag push — use it as-is
32+
echo "tag=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
33+
else
34+
# Triggered by a branch push — bump the minor version
35+
LATEST=$(git tag --list 'v*' --sort=-version:refname | head -n1)
36+
if [ -z "$LATEST" ]; then
37+
NEW="v0.1.0"
38+
else
39+
V="${LATEST#v}"
40+
MAJOR=$(echo "$V" | cut -d. -f1)
41+
MINOR=$(echo "$V" | cut -d. -f2)
42+
NEW="v${MAJOR}.$((MINOR + 1)).0"
43+
fi
44+
echo "tag=$NEW" >> "$GITHUB_OUTPUT"
45+
fi
2446
2547
- name: Set up Docker Buildx
2648
uses: docker/setup-buildx-action@v3
@@ -38,10 +60,8 @@ jobs:
3860
with:
3961
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4062
tags: |
41-
type=ref,event=branch
42-
type=semver,pattern={{version}}
43-
type=semver,pattern={{major}}.{{minor}}
44-
type=raw,value=latest,enable={{is_default_branch}}
63+
type=raw,value=${{ steps.version.outputs.tag }}
64+
type=raw,value=latest,enable=${{ github.ref_type == 'branch' }}
4565
4666
- name: Build and push
4767
uses: docker/build-push-action@v5
@@ -54,21 +74,18 @@ jobs:
5474
cache-from: type=gha
5575
cache-to: type=gha,mode=max
5676

57-
release:
58-
needs: build-and-push
59-
runs-on: ubuntu-latest
60-
if: startsWith(github.ref, 'refs/tags/v')
61-
permissions:
62-
contents: write
63-
64-
steps:
65-
- name: Checkout
66-
uses: actions/checkout@v4
77+
- name: Tag commit and push
78+
if: github.ref_type == 'branch'
79+
run: |
80+
git config user.name "github-actions[bot]"
81+
git config user.email "github-actions[bot]@users.noreply.github.com"
82+
git tag "${{ steps.version.outputs.tag }}"
83+
git push origin "${{ steps.version.outputs.tag }}"
6784
6885
- name: Create GitHub Release
6986
env:
7087
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7188
run: |
72-
gh release create ${{ github.ref_name }} \
73-
--title "TubeChecker ${{ github.ref_name }}" \
89+
gh release create "${{ steps.version.outputs.tag }}" \
90+
--title "TubeChecker ${{ steps.version.outputs.tag }}" \
7491
--generate-notes

0 commit comments

Comments
 (0)