Skip to content

Commit 0f9fff5

Browse files
committed
fix: actually ?fix? the ghcr tag matching release tag
1 parent 9100316 commit 0f9fff5

File tree

1 file changed

+47
-15
lines changed

1 file changed

+47
-15
lines changed

.github/workflows/docker-publish.yml

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: Build and Publish Docker Image
22

33
on:
44
push:
5-
branches:
6-
- main
75
tags:
86
- 'v*'
97
pull_request:
@@ -15,7 +13,9 @@ env:
1513
IMAGE_NAME: ${{ github.repository }}
1614

1715
jobs:
18-
build-and-push:
16+
# Job for release builds triggered by version tags
17+
build-release:
18+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
1919
runs-on: ubuntu-latest
2020
permissions:
2121
contents: read
@@ -25,48 +25,44 @@ jobs:
2525
- name: Checkout repository
2626
uses: actions/checkout@v4
2727
with:
28-
fetch-depth: 0 # Fetch all history for version calculation
28+
fetch-depth: 0
2929

3030
- name: Set up Docker Buildx
3131
uses: docker/setup-buildx-action@v3
3232

3333
- name: Log in to Container Registry
34-
if: github.event_name != 'pull_request'
3534
uses: docker/login-action@v3
3635
with:
3736
registry: ${{ env.REGISTRY }}
3837
username: ${{ github.actor }}
3938
password: ${{ secrets.GITHUB_TOKEN }}
4039

41-
- name: Extract metadata
40+
- name: Extract metadata for release
4241
id: docker_meta
4342
uses: docker/metadata-action@v5
4443
with:
4544
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
4645
tags: |
47-
type=ref,event=branch
48-
type=ref,event=pr
4946
type=semver,pattern={{version}}
5047
type=semver,pattern={{major}}.{{minor}}
5148
type=semver,pattern={{major}}
52-
type=raw,value=latest,enable={{is_default_branch}}
49+
type=raw,value=latest
5350
5451
- name: Build and push Docker image
5552
uses: docker/build-push-action@v5
5653
with:
5754
context: .
5855
file: ./Dockerfile
5956
platforms: linux/amd64,linux/arm64
60-
push: ${{ github.event_name != 'pull_request' }}
57+
push: true
6158
tags: ${{ steps.docker_meta.outputs.tags }}
6259
labels: ${{ steps.docker_meta.outputs.labels }}
6360
cache-from: type=gha
6461
cache-to: type=gha,mode=max
6562

66-
- name: Generate summary
67-
if: github.event_name != 'pull_request'
63+
- name: Generate release summary
6864
run: |
69-
echo "## 🐳 Docker Image Published" >> $GITHUB_STEP_SUMMARY
65+
echo "## 🐳 Docker Release Image Published" >> $GITHUB_STEP_SUMMARY
7066
echo "" >> $GITHUB_STEP_SUMMARY
7167
echo "**Registry:** ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY
7268
echo "" >> $GITHUB_STEP_SUMMARY
@@ -75,7 +71,43 @@ jobs:
7571
echo "${{ steps.docker_meta.outputs.tags }}" | tr ',' '\n' >> $GITHUB_STEP_SUMMARY
7672
echo '```' >> $GITHUB_STEP_SUMMARY
7773
echo "" >> $GITHUB_STEP_SUMMARY
78-
echo "**Pull command (latest):**" >> $GITHUB_STEP_SUMMARY
74+
echo "**Pull command:**" >> $GITHUB_STEP_SUMMARY
7975
echo '```bash' >> $GITHUB_STEP_SUMMARY
8076
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
81-
echo '```' >> $GITHUB_STEP_SUMMARY
77+
echo '```' >> $GITHUB_STEP_SUMMARY
78+
79+
80+
# Job for PR builds
81+
build-pr:
82+
if: github.event_name == 'pull_request'
83+
runs-on: ubuntu-latest
84+
permissions:
85+
contents: read
86+
packages: write
87+
88+
steps:
89+
- name: Checkout repository
90+
uses: actions/checkout@v4
91+
92+
- name: Set up Docker Buildx
93+
uses: docker/setup-buildx-action@v3
94+
95+
- name: Extract metadata for PR
96+
id: docker_meta
97+
uses: docker/metadata-action@v5
98+
with:
99+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
100+
tags: |
101+
type=ref,event=pr
102+
103+
- name: Build Docker image (no push)
104+
uses: docker/build-push-action@v5
105+
with:
106+
context: .
107+
file: ./Dockerfile
108+
platforms: linux/amd64,linux/arm64
109+
push: false
110+
tags: ${{ steps.docker_meta.outputs.tags }}
111+
labels: ${{ steps.docker_meta.outputs.labels }}
112+
cache-from: type=gha
113+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)