ci: improve GitHub Actions Docker build workflow

This commit is contained in:
Nick007
2025-10-21 17:40:10 +08:00
parent 8f8af073f2
commit f83fc4fc22

View File

@@ -3,16 +3,8 @@ name: Build and Publish Docker Image
on:
workflow_dispatch:
push:
branches:
- main
- master
- dev
tags:
- 'v*'
pull_request:
branches:
- main
- master
env:
REGISTRY: ghcr.io
@@ -48,13 +40,10 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') || github.ref == format('refs/heads/{0}', 'master') }}
type=sha,prefix={{branch}}-
type=raw,value=latest
- name: Build and push Docker image
id: build-image
@@ -62,14 +51,14 @@ jobs:
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate artifact attestation
if: github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch'
if: github.event_name != 'workflow_dispatch'
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
@@ -77,7 +66,6 @@ jobs:
push-to-registry: true
- name: Output Docker image information
if: github.event_name != 'pull_request'
run: |
echo "## 🐳 Docker Image Published" >> $GITHUB_STEP_SUMMARY
echo "**Registry:** ${{ env.REGISTRY }}" >> $GITHUB_STEP_SUMMARY