Skip to content

Commit 1f30bb3

Browse files
authored
Merge pull request #20 from dash14/ci/docker-publish-concurrency
Prevent alias tag overwrite on concurrent Docker publishes
2 parents 4824cb3 + 515f7e4 commit 1f30bb3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

.github/workflows/docker-publish.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88

99
workflow_dispatch:
1010

11+
concurrency:
12+
group: docker-publish
13+
cancel-in-progress: false
14+
1115
jobs:
1216
build-and-push:
1317
runs-on: ubuntu-latest
@@ -41,6 +45,21 @@ jobs:
4145
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
4246
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
4347
48+
# Check if this version is the latest within the same major/major.minor
49+
VERSION="${TAG#v}"
50+
MAJOR=$(echo "$VERSION" | cut -d. -f1)
51+
MINOR=$(echo "$VERSION" | cut -d. -f1-2)
52+
53+
LATEST_IN_MAJOR=$(git tag --list "v${MAJOR}.*.*" --sort=-version:refname | head -1)
54+
if [ "$TAG" != "$LATEST_IN_MAJOR" ]; then
55+
echo "skip_major=true" >> "$GITHUB_OUTPUT"
56+
fi
57+
58+
LATEST_IN_MINOR=$(git tag --list "v${MINOR}.*" --sort=-version:refname | head -1)
59+
if [ "$TAG" != "$LATEST_IN_MINOR" ]; then
60+
echo "skip_minor=true" >> "$GITHUB_OUTPUT"
61+
fi
62+
4463
- name: Set up QEMU
4564
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
4665

@@ -54,8 +73,8 @@ jobs:
5473
images: ghcr.io/${{ github.repository }}
5574
tags: |
5675
type=semver,pattern={{version}},value=${{ steps.version.outputs.tag }}
57-
type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.tag }}
58-
type=semver,pattern={{major}},value=${{ steps.version.outputs.tag }}
76+
${{ steps.version.outputs.skip_minor != 'true' && format('type=semver,pattern={{{{major}}}}.{{{{minor}}}},value={0}', steps.version.outputs.tag) || '' }}
77+
${{ steps.version.outputs.skip_major != 'true' && format('type=semver,pattern={{{{major}}}},value={0}', steps.version.outputs.tag) || '' }}
5978
type=raw,value=sha-${{ steps.version.outputs.sha }},priority=100
6079
6180
- name: Login to GHCR

0 commit comments

Comments
 (0)