Skip to content

Commit a6cd2d6

Browse files
pan93412claude
andcommitted
ci: introduce prepare job with docker/metadata-action for tag generation
- Add prepare job that centralises version resolution and Docker tag computation using docker/metadata-action (semver patterns + latest=auto) - build-release-* and push-* jobs consume version/tags from job outputs instead of repeating the logic inline in each job - build and prepare run in parallel; build-release-* waits on both - metadata-action handles stable vs pre-release automatically: x.y.z → latest, x, x.y, x.y.z x.y.z-pre.N → only x.y.z-pre.N Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f2f8824 commit a6cd2d6

1 file changed

Lines changed: 67 additions & 69 deletions

File tree

.github/workflows/release.yml

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,57 @@ jobs:
3838
platforms: linux/amd64
3939
push: false
4040

41+
prepare:
42+
name: Prepare release metadata
43+
runs-on: blacksmith-2vcpu-ubuntu-2404
44+
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || github.event_name == 'workflow_dispatch'
45+
outputs:
46+
version: ${{ steps.version.outputs.value }}
47+
dockerhub-tags: ${{ steps.dockerhub.outputs.tags }}
48+
swr-tags: ${{ steps.swr.outputs.tags }}
49+
50+
steps:
51+
- name: Resolve tag
52+
id: tag
53+
run: |
54+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
55+
echo "value=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
56+
else
57+
echo "value=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
58+
fi
59+
60+
- name: Extract version
61+
id: version
62+
run: |
63+
TAG="${{ steps.tag.outputs.value }}"
64+
echo "value=${TAG#v}" >> "$GITHUB_OUTPUT"
65+
66+
- name: Docker Hub metadata
67+
id: dockerhub
68+
uses: docker/metadata-action@v5 # TODO: pin to commit hash
69+
with:
70+
images: docker.io/zeabur/stratus
71+
flavor: latest=auto
72+
tags: |
73+
type=semver,pattern={{version}},value=${{ steps.tag.outputs.value }}
74+
type=semver,pattern={{major}}.{{minor}},value=${{ steps.tag.outputs.value }}
75+
type=semver,pattern={{major}},value=${{ steps.tag.outputs.value }}
76+
77+
- name: SWR metadata
78+
id: swr
79+
uses: docker/metadata-action@v5 # TODO: pin to commit hash
80+
with:
81+
images: swr.cn-east-3.myhuaweicloud.com/zeabur/stratus
82+
flavor: latest=auto
83+
tags: |
84+
type=semver,pattern={{version}},value=${{ steps.tag.outputs.value }}
85+
type=semver,pattern={{major}}.{{minor}},value=${{ steps.tag.outputs.value }}
86+
type=semver,pattern={{major}},value=${{ steps.tag.outputs.value }}
87+
4188
build-release-dockerhub:
4289
name: Build (dockerhub, linux/${{ matrix.arch }})
4390
runs-on: ${{ matrix.runner }}
44-
needs: [build]
45-
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || github.event_name == 'workflow_dispatch'
91+
needs: [build, prepare]
4692
strategy:
4793
matrix:
4894
include:
@@ -66,29 +112,18 @@ jobs:
66112
username: ${{ secrets.DOCKERHUB_USERNAME }}
67113
password: ${{ secrets.DOCKERHUB_TOKEN }}
68114

69-
- name: Extract version
70-
id: meta
71-
run: |
72-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
73-
TAG="${{ github.event.inputs.tag }}"
74-
else
75-
TAG="${GITHUB_REF_NAME}"
76-
fi
77-
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
78-
79115
- name: Build and push
80116
uses: useblacksmith/build-push-action@fb9e3e6a9299c78462bfadd0d93352c316adc9b8 # v2.2.0
81117
with:
82118
platforms: ${{ matrix.platform }}
83119
provenance: "true"
84120
push: true
85-
tags: docker.io/zeabur/stratus:${{ steps.meta.outputs.version }}-linux-${{ matrix.arch }}
121+
tags: docker.io/zeabur/stratus:${{ needs.prepare.outputs.version }}-linux-${{ matrix.arch }}
86122

87123
build-release-swr:
88124
name: Build (swr, linux/${{ matrix.arch }})
89125
runs-on: ${{ matrix.runner }}
90-
needs: [build]
91-
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) || github.event_name == 'workflow_dispatch'
126+
needs: [build, prepare]
92127
strategy:
93128
matrix:
94129
include:
@@ -113,28 +148,18 @@ jobs:
113148
username: ${{ secrets.HUAWEI_SWR_USERNAME }}
114149
password: ${{ secrets.HUAWEI_SWR_TOKEN }}
115150

116-
- name: Extract version
117-
id: meta
118-
run: |
119-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
120-
TAG="${{ github.event.inputs.tag }}"
121-
else
122-
TAG="${GITHUB_REF_NAME}"
123-
fi
124-
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
125-
126151
- name: Build and push
127152
uses: useblacksmith/build-push-action@fb9e3e6a9299c78462bfadd0d93352c316adc9b8 # v2.2.0
128153
with:
129154
platforms: ${{ matrix.platform }}
130155
provenance: "false"
131156
push: true
132-
tags: swr.cn-east-3.myhuaweicloud.com/zeabur/stratus:${{ steps.meta.outputs.version }}-linux-${{ matrix.arch }}
157+
tags: swr.cn-east-3.myhuaweicloud.com/zeabur/stratus:${{ needs.prepare.outputs.version }}-linux-${{ matrix.arch }}
133158

134159
push-dockerhub:
135160
name: Push to Docker Hub
136161
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
137-
needs: [build-release-dockerhub]
162+
needs: [prepare, build-release-dockerhub]
138163

139164
steps:
140165
- name: Set up Docker Buildx
@@ -148,31 +173,18 @@ jobs:
148173

149174
- name: Create multi-arch manifest
150175
run: |
151-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
152-
TAG="${{ github.event.inputs.tag }}"
153-
else
154-
TAG="${GITHUB_REF_NAME}"
155-
fi
156-
VERSION="${TAG#v}"
157-
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
158-
docker buildx imagetools create \
159-
-t docker.io/zeabur/stratus:${VERSION} \
160-
-t docker.io/zeabur/stratus:${VERSION%.*} \
161-
-t docker.io/zeabur/stratus:${VERSION%%.*} \
162-
-t docker.io/zeabur/stratus:latest \
163-
docker.io/zeabur/stratus:${VERSION}-linux-amd64 \
164-
docker.io/zeabur/stratus:${VERSION}-linux-arm64
165-
else
166-
docker buildx imagetools create \
167-
-t docker.io/zeabur/stratus:${VERSION} \
168-
docker.io/zeabur/stratus:${VERSION}-linux-amd64 \
169-
docker.io/zeabur/stratus:${VERSION}-linux-arm64
170-
fi
176+
VERSION="${{ needs.prepare.outputs.version }}"
177+
readarray -t TAGS < <(echo "${{ needs.prepare.outputs.dockerhub-tags }}")
178+
TAG_ARGS=()
179+
for t in "${TAGS[@]}"; do TAG_ARGS+=(-t "$t"); done
180+
docker buildx imagetools create "${TAG_ARGS[@]}" \
181+
docker.io/zeabur/stratus:${VERSION}-linux-amd64 \
182+
docker.io/zeabur/stratus:${VERSION}-linux-arm64
171183
172184
push-swr:
173185
name: Push to Huawei SWR
174186
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
175-
needs: [build-release-swr]
187+
needs: [prepare, build-release-swr]
176188

177189
steps:
178190
- name: Set up Docker Buildx
@@ -187,24 +199,10 @@ jobs:
187199

188200
- name: Create multi-arch manifest
189201
run: |
190-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
191-
TAG="${{ github.event.inputs.tag }}"
192-
else
193-
TAG="${GITHUB_REF_NAME}"
194-
fi
195-
VERSION="${TAG#v}"
196-
REGISTRY=swr.cn-east-3.myhuaweicloud.com
197-
if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
198-
docker buildx imagetools create \
199-
-t ${REGISTRY}/zeabur/stratus:${VERSION} \
200-
-t ${REGISTRY}/zeabur/stratus:${VERSION%.*} \
201-
-t ${REGISTRY}/zeabur/stratus:${VERSION%%.*} \
202-
-t ${REGISTRY}/zeabur/stratus:latest \
203-
${REGISTRY}/zeabur/stratus:${VERSION}-linux-amd64 \
204-
${REGISTRY}/zeabur/stratus:${VERSION}-linux-arm64
205-
else
206-
docker buildx imagetools create \
207-
-t ${REGISTRY}/zeabur/stratus:${VERSION} \
208-
${REGISTRY}/zeabur/stratus:${VERSION}-linux-amd64 \
209-
${REGISTRY}/zeabur/stratus:${VERSION}-linux-arm64
210-
fi
202+
VERSION="${{ needs.prepare.outputs.version }}"
203+
readarray -t TAGS < <(echo "${{ needs.prepare.outputs.swr-tags }}")
204+
TAG_ARGS=()
205+
for t in "${TAGS[@]}"; do TAG_ARGS+=(-t "$t"); done
206+
docker buildx imagetools create "${TAG_ARGS[@]}" \
207+
swr.cn-east-3.myhuaweicloud.com/zeabur/stratus:${VERSION}-linux-amd64 \
208+
swr.cn-east-3.myhuaweicloud.com/zeabur/stratus:${VERSION}-linux-arm64

0 commit comments

Comments
 (0)