Skip to content

Commit 7a8236e

Browse files
committed
Add correct tag for docker image
1 parent bc09c1a commit 7a8236e

2 files changed

Lines changed: 48 additions & 8 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Build Binaries
33
on:
44
push:
55
branches: ['main']
6+
tags: ['v*']
67
pull_request:
78
branches: ['main']
89
workflow_dispatch:

.github/workflows/docker-build.yml

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
workflow_run:
55
workflows: ["Build Binaries"]
66
types: [completed]
7-
branches: [main]
87
release:
98
types: [published]
109
workflow_dispatch:
@@ -29,15 +28,54 @@ jobs:
2928
- name: Checkout code
3029
uses: actions/checkout@v4
3130

32-
- name: Download artifacts from Build Binaries workflow
31+
- name: Download artifacts from Build Binaries workflow (triggered by Build Binaries)
32+
if: github.event_name == 'workflow_run'
3333
uses: dawidd6/action-download-artifact@v6
3434
with:
3535
github_token: ${{ secrets.GITHUB_TOKEN }}
3636
workflow: build.yml
37-
run_id: ${{ (github.event_name == 'workflow_dispatch' || github.event_name == 'release') && '' || github.event.workflow_run.id }}
37+
run_id: ${{ github.event.workflow_run.id }}
3838
name_is_regexp: true
3939
name: perfecto-mcp-.*
4040
path: artifacts/
41+
42+
- name: Download artifacts from Build Binaries workflow (triggered by release/manual)
43+
if: github.event_name != 'workflow_run'
44+
uses: dawidd6/action-download-artifact@v6
45+
with:
46+
github_token: ${{ secrets.GITHUB_TOKEN }}
47+
workflow: build.yml
48+
commit: ${{ github.sha }}
49+
workflow_conclusion: success
50+
name_is_regexp: true
51+
name: perfecto-mcp-.*
52+
path: artifacts/
53+
54+
- name: Get tag for version (when triggered by Build Binaries)
55+
if: github.event_name == 'workflow_run'
56+
id: get_tag
57+
run: |
58+
git fetch --tags --force 2>/dev/null || true
59+
TAG=$(git tag --points-at ${{ github.event.workflow_run.head_sha }} 2>/dev/null | grep -E '^v[0-9]+\.[0-9]+' | sort -V | tail -1)
60+
echo "tag_name=$TAG" >> $GITHUB_OUTPUT
61+
echo "Tag for ${{ github.event.workflow_run.head_sha }}: $TAG"
62+
63+
- name: Set ref tag without v (tag event processed)
64+
if: github.event_name == 'release' || (github.event_name == 'workflow_run' && steps.get_tag.outputs.tag_name != '')
65+
id: ref_tag
66+
run: |
67+
if [ "${{ github.event_name }}" = "release" ]; then
68+
RAW="${{ github.event.release.tag_name }}"
69+
else
70+
RAW="${{ steps.get_tag.outputs.tag_name }}"
71+
fi
72+
VERSION="${RAW#v}"
73+
echo "version=$VERSION" >> $GITHUB_OUTPUT
74+
MAJOR_MINOR=$(echo "$VERSION" | sed -n 's/^\([0-9]*\.[0-9]*\).*/\1/p')
75+
echo "major_minor=$MAJOR_MINOR" >> $GITHUB_OUTPUT
76+
MAJOR=$(echo "$VERSION" | sed -n 's/^\([0-9]*\).*/\1/p')
77+
echo "major=$MAJOR" >> $GITHUB_OUTPUT
78+
echo "Ref tag (no v): $VERSION ($MAJOR_MINOR, $MAJOR)"
4179
4280
- name: Organize binaries for Docker build
4381
run: |
@@ -83,11 +121,12 @@ jobs:
83121
${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE_NAME }}
84122
tags: |
85123
type=ref,event=branch
86-
type=ref,event=pr
87-
type=semver,pattern={{version}},enable=${{ github.event_name == 'release' }}
88-
type=semver,pattern={{major}}.{{minor}},enable=${{ github.event_name == 'release' }}
89-
type=semver,pattern={{major}},enable=${{ github.event_name == 'release' }}
90-
type=raw,value=latest,enable=${{ github.event_name == 'release' }}
124+
type=ref,event=pr
125+
type=match,pattern=v(.*),group=1
126+
type=raw,value=${{ steps.ref_tag.outputs.version }},enable=${{ steps.ref_tag.outputs.version != '' }}
127+
type=raw,value=${{ steps.ref_tag.outputs.major_minor }},enable=${{ steps.ref_tag.outputs.major_minor != '' }}
128+
type=raw,value=${{ steps.ref_tag.outputs.major }},enable=${{ steps.ref_tag.outputs.major != '' }}
129+
type=raw,value=latest,enable=${{ steps.ref_tag.outputs.version != '' }}
91130
92131
- name: Build and push Docker image
93132
uses: docker/build-push-action@v5

0 commit comments

Comments
 (0)