Skip to content

Commit 54e48c3

Browse files
authored
Merge pull request #3 from zeabur/swr-ci-fix
ci: restructure release workflow with gated matrix builds
2 parents 596f4e4 + a6cd2d6 commit 54e48c3

1 file changed

Lines changed: 124 additions & 67 deletions

File tree

.github/workflows/release.yml

Lines changed: 124 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
- "v*"
77
pull_request:
88
workflow_dispatch:
9+
inputs:
10+
tag:
11+
description: "Version tag to release (e.g. v1.2.3 or v1.2.3-dev.1)"
12+
required: true
13+
type: string
914

1015
permissions:
1116
contents: read
@@ -16,7 +21,7 @@ concurrency:
1621
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
1722

1823
jobs:
19-
build-amd64:
24+
build:
2025
name: Build (linux/amd64)
2126
runs-on: blacksmith-2vcpu-ubuntu-2404
2227

@@ -25,78 +30,140 @@ jobs:
2530
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2631

2732
- name: Set up Docker Buildx
28-
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
33+
uses: useblacksmith/setup-docker-builder@722e97d12b1d06a961800dd6c05d79d951ad3c80 # v1.8.0
2934

30-
- name: Login to Docker Hub
31-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
32-
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
35+
- name: Build
36+
uses: useblacksmith/build-push-action@fb9e3e6a9299c78462bfadd0d93352c316adc9b8 # v2.2.0
3337
with:
34-
username: ${{ secrets.DOCKERHUB_USERNAME }}
35-
password: ${{ secrets.DOCKERHUB_TOKEN }}
38+
platforms: linux/amd64
39+
push: false
3640

37-
- name: Extract version
38-
id: meta
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
3953
run: |
40-
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref_type }}" == "tag" ]]; then
41-
echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
54+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
55+
echo "value=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
4256
else
43-
echo "version=0.0.0" >> "$GITHUB_OUTPUT"
57+
echo "value=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
4458
fi
4559
46-
- name: Build and push
47-
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
48-
with:
49-
platforms: linux/amd64
50-
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
51-
tags: docker.io/zeabur/stratus:${{ steps.meta.outputs.version }}-linux-amd64
52-
cache-from: type=gha,scope=buildkit-linux-amd64
53-
cache-to: type=gha,mode=max,scope=buildkit-linux-amd64
60+
- name: Extract version
61+
id: version
62+
run: |
63+
TAG="${{ steps.tag.outputs.value }}"
64+
echo "value=${TAG#v}" >> "$GITHUB_OUTPUT"
5465
55-
build-arm64:
56-
name: Build (linux/arm64)
57-
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
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+
88+
build-release-dockerhub:
89+
name: Build (dockerhub, linux/${{ matrix.arch }})
90+
runs-on: ${{ matrix.runner }}
91+
needs: [build, prepare]
92+
strategy:
93+
matrix:
94+
include:
95+
- arch: amd64
96+
platform: linux/amd64
97+
runner: blacksmith-2vcpu-ubuntu-2404
98+
- arch: arm64
99+
platform: linux/arm64
100+
runner: blacksmith-2vcpu-ubuntu-2404-arm
58101

59102
steps:
60103
- name: Checkout
61104
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
62105

63106
- name: Set up Docker Buildx
64-
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
107+
uses: useblacksmith/setup-docker-builder@722e97d12b1d06a961800dd6c05d79d951ad3c80 # v1.8.0
65108

66109
- name: Login to Docker Hub
67-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
68110
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
69111
with:
70112
username: ${{ secrets.DOCKERHUB_USERNAME }}
71113
password: ${{ secrets.DOCKERHUB_TOKEN }}
72114

73-
- name: Extract version
74-
id: meta
75-
run: |
76-
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref_type }}" == "tag" ]]; then
77-
echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
78-
else
79-
echo "version=0.0.0" >> "$GITHUB_OUTPUT"
80-
fi
115+
- name: Build and push
116+
uses: useblacksmith/build-push-action@fb9e3e6a9299c78462bfadd0d93352c316adc9b8 # v2.2.0
117+
with:
118+
platforms: ${{ matrix.platform }}
119+
provenance: "true"
120+
push: true
121+
tags: docker.io/zeabur/stratus:${{ needs.prepare.outputs.version }}-linux-${{ matrix.arch }}
122+
123+
build-release-swr:
124+
name: Build (swr, linux/${{ matrix.arch }})
125+
runs-on: ${{ matrix.runner }}
126+
needs: [build, prepare]
127+
strategy:
128+
matrix:
129+
include:
130+
- arch: amd64
131+
platform: linux/amd64
132+
runner: blacksmith-2vcpu-ubuntu-2404
133+
- arch: arm64
134+
platform: linux/arm64
135+
runner: blacksmith-2vcpu-ubuntu-2404-arm
136+
137+
steps:
138+
- name: Checkout
139+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
140+
141+
- name: Set up Docker Buildx
142+
uses: useblacksmith/setup-docker-builder@722e97d12b1d06a961800dd6c05d79d951ad3c80 # v1.8.0
143+
144+
- name: Login to Huawei SWR
145+
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
146+
with:
147+
registry: swr.cn-east-3.myhuaweicloud.com
148+
username: ${{ secrets.HUAWEI_SWR_USERNAME }}
149+
password: ${{ secrets.HUAWEI_SWR_TOKEN }}
81150

82151
- name: Build and push
83-
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0
152+
uses: useblacksmith/build-push-action@fb9e3e6a9299c78462bfadd0d93352c316adc9b8 # v2.2.0
84153
with:
85-
platforms: linux/arm64
86-
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
87-
tags: docker.io/zeabur/stratus:${{ steps.meta.outputs.version }}-linux-arm64
88-
cache-from: type=gha,scope=buildkit-linux-arm64
89-
cache-to: type=gha,mode=max,scope=buildkit-linux-arm64
154+
platforms: ${{ matrix.platform }}
155+
provenance: "false"
156+
push: true
157+
tags: swr.cn-east-3.myhuaweicloud.com/zeabur/stratus:${{ needs.prepare.outputs.version }}-linux-${{ matrix.arch }}
90158

91159
push-dockerhub:
92160
name: Push to Docker Hub
93161
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
94-
needs: [build-amd64, build-arm64]
95-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
162+
needs: [prepare, build-release-dockerhub]
96163

97164
steps:
98165
- name: Set up Docker Buildx
99-
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
166+
uses: useblacksmith/setup-docker-builder@722e97d12b1d06a961800dd6c05d79d951ad3c80 # v1.8.0
100167

101168
- name: Login to Docker Hub
102169
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
@@ -106,30 +173,22 @@ jobs:
106173

107174
- name: Create multi-arch manifest
108175
run: |
109-
VERSION=${GITHUB_REF_NAME#v}
110-
docker buildx imagetools create \
111-
-t docker.io/zeabur/stratus:${VERSION} \
112-
-t docker.io/zeabur/stratus:${VERSION%.*} \
113-
-t docker.io/zeabur/stratus:${VERSION%%.*} \
114-
-t docker.io/zeabur/stratus:latest \
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[@]}" \
115181
docker.io/zeabur/stratus:${VERSION}-linux-amd64 \
116182
docker.io/zeabur/stratus:${VERSION}-linux-arm64
117183
118184
push-swr:
119185
name: Push to Huawei SWR
120186
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
121-
needs: [build-amd64, build-arm64]
122-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
187+
needs: [prepare, build-release-swr]
123188

124189
steps:
125190
- name: Set up Docker Buildx
126-
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
127-
128-
- name: Login to Docker Hub
129-
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
130-
with:
131-
username: ${{ secrets.DOCKERHUB_USERNAME }}
132-
password: ${{ secrets.DOCKERHUB_TOKEN }}
191+
uses: useblacksmith/setup-docker-builder@722e97d12b1d06a961800dd6c05d79d951ad3c80 # v1.8.0
133192

134193
- name: Login to Huawei SWR
135194
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
@@ -138,14 +197,12 @@ jobs:
138197
username: ${{ secrets.HUAWEI_SWR_USERNAME }}
139198
password: ${{ secrets.HUAWEI_SWR_TOKEN }}
140199

141-
- name: Retag to SWR
200+
- name: Create multi-arch manifest
142201
run: |
143-
VERSION=${GITHUB_REF_NAME#v}
144-
REGISTRY=swr.cn-east-3.myhuaweicloud.com
145-
docker buildx imagetools create \
146-
-t ${REGISTRY}/zeabur/stratus:${VERSION} \
147-
-t ${REGISTRY}/zeabur/stratus:${VERSION%.*} \
148-
-t ${REGISTRY}/zeabur/stratus:${VERSION%%.*} \
149-
-t ${REGISTRY}/zeabur/stratus:latest \
150-
docker.io/zeabur/stratus:${VERSION}-linux-amd64 \
151-
docker.io/zeabur/stratus:${VERSION}-linux-arm64
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)