Skip to content

Commit bd8462b

Browse files
committed
chore: update build action
1 parent 0857e4e commit bd8462b

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed
Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
name: build-and-push-release-image
1+
name: build-and-push-stable-image
22

33
on:
44
push:
5-
branches:
6-
# Run on pushing branches like `release/1.0.0`
7-
- "release/*.*.*"
5+
tags:
6+
# Match stable and rc versions, such as 'v1.0.0' or 'v0.23.0-rc.0'
7+
- "v*.*.*"
8+
- "v*.*.*-rc.*"
89

910
jobs:
10-
build-and-push-release-image:
11+
build-and-push-stable-image:
1112
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
packages: write
1216
steps:
1317
- uses: actions/checkout@v4
1418

1519
- name: Set up QEMU
1620
uses: docker/setup-qemu-action@v3
1721

1822
- name: Extract build args
19-
# Extract version from branch name
20-
# Example: branch name `release/1.0.0` sets up env.VERSION=1.0.0
23+
# Extract version number and check if it's an rc version
2124
run: |
22-
echo "VERSION=${GITHUB_REF_NAME#release/}" >> $GITHUB_ENV
25+
if [[ "${GITHUB_REF_NAME}" =~ -rc ]]; then
26+
echo "PRE_RELEASE=true" >> $GITHUB_ENV
27+
else
28+
echo "PRE_RELEASE=false" >> $GITHUB_ENV
29+
fi
30+
echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
2331
2432
- name: Login to Docker Hub
2533
uses: docker/login-action@v3
@@ -32,6 +40,36 @@ jobs:
3240
uses: docker/setup-buildx-action@v3
3341
with:
3442
install: true
43+
version: v0.9.1
44+
45+
# Metadata for stable versions
46+
- name: Docker meta for stable
47+
id: meta-stable
48+
if: env.PRE_RELEASE == 'false'
49+
uses: docker/metadata-action@v5
50+
with:
51+
images: |
52+
yourselfhosted/slash
53+
tags: |
54+
type=semver,pattern={{version}},value=${{ env.VERSION }}
55+
type=raw,value=stable
56+
flavor: |
57+
latest=true
58+
labels: |
59+
org.opencontainers.image.version=${{ env.VERSION }}
60+
61+
# Metadata for rc versions
62+
- name: Docker meta for rc
63+
id: meta-rc
64+
if: env.PRE_RELEASE == 'true'
65+
uses: docker/metadata-action@v5
66+
with:
67+
images: |
68+
yourselfhosted/slash
69+
tags: |
70+
type=raw,value=${{ env.VERSION }}
71+
labels: |
72+
org.opencontainers.image.version=${{ env.VERSION }}
3573
3674
- name: Build and Push
3775
id: docker_build
@@ -41,4 +79,5 @@ jobs:
4179
file: ./Dockerfile
4280
platforms: linux/amd64,linux/arm64
4381
push: true
44-
tags: yourselfhosted/slash:latest, yourselfhosted/slash:${{ env.VERSION }}
82+
tags: ${{ steps.meta-stable.outputs.tags || steps.meta-rc.outputs.tags }}
83+
labels: ${{ steps.meta-stable.outputs.labels || steps.meta-rc.outputs.labels }}

0 commit comments

Comments
 (0)