From bd8462b2b338d562dc64559db92c6c05adc4bfa1 Mon Sep 17 00:00:00 2001 From: Steven Date: Sun, 3 Nov 2024 10:21:34 +0800 Subject: [PATCH] chore: update build action --- .../build-and-push-release-image.yml | 57 ++++++++++++++++--- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-and-push-release-image.yml b/.github/workflows/build-and-push-release-image.yml index 076ce1f61..ac6d83fbe 100644 --- a/.github/workflows/build-and-push-release-image.yml +++ b/.github/workflows/build-and-push-release-image.yml @@ -1,14 +1,18 @@ -name: build-and-push-release-image +name: build-and-push-stable-image on: push: - branches: - # Run on pushing branches like `release/1.0.0` - - "release/*.*.*" + tags: + # Match stable and rc versions, such as 'v1.0.0' or 'v0.23.0-rc.0' + - "v*.*.*" + - "v*.*.*-rc.*" jobs: - build-and-push-release-image: + build-and-push-stable-image: runs-on: ubuntu-latest + permissions: + contents: read + packages: write steps: - uses: actions/checkout@v4 @@ -16,10 +20,14 @@ jobs: uses: docker/setup-qemu-action@v3 - name: Extract build args - # Extract version from branch name - # Example: branch name `release/1.0.0` sets up env.VERSION=1.0.0 + # Extract version number and check if it's an rc version run: | - echo "VERSION=${GITHUB_REF_NAME#release/}" >> $GITHUB_ENV + if [[ "${GITHUB_REF_NAME}" =~ -rc ]]; then + echo "PRE_RELEASE=true" >> $GITHUB_ENV + else + echo "PRE_RELEASE=false" >> $GITHUB_ENV + fi + echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV - name: Login to Docker Hub uses: docker/login-action@v3 @@ -32,6 +40,36 @@ jobs: uses: docker/setup-buildx-action@v3 with: install: true + version: v0.9.1 + + # Metadata for stable versions + - name: Docker meta for stable + id: meta-stable + if: env.PRE_RELEASE == 'false' + uses: docker/metadata-action@v5 + with: + images: | + yourselfhosted/slash + tags: | + type=semver,pattern={{version}},value=${{ env.VERSION }} + type=raw,value=stable + flavor: | + latest=true + labels: | + org.opencontainers.image.version=${{ env.VERSION }} + + # Metadata for rc versions + - name: Docker meta for rc + id: meta-rc + if: env.PRE_RELEASE == 'true' + uses: docker/metadata-action@v5 + with: + images: | + yourselfhosted/slash + tags: | + type=raw,value=${{ env.VERSION }} + labels: | + org.opencontainers.image.version=${{ env.VERSION }} - name: Build and Push id: docker_build @@ -41,4 +79,5 @@ jobs: file: ./Dockerfile platforms: linux/amd64,linux/arm64 push: true - tags: yourselfhosted/slash:latest, yourselfhosted/slash:${{ env.VERSION }} + tags: ${{ steps.meta-stable.outputs.tags || steps.meta-rc.outputs.tags }} + labels: ${{ steps.meta-stable.outputs.labels || steps.meta-rc.outputs.labels }}