From 6f68f62a826bc559fb003e2999fc61364f3f2eb5 Mon Sep 17 00:00:00 2001 From: Jimboo Date: Fri, 13 Mar 2026 07:16:56 +0000 Subject: [PATCH] =?UTF-8?q?ci:=20=E4=BC=98=E5=8C=96=20Docker=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=B7=A5=E4=BD=9C=E6=B5=81=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=89=8B=E5=8A=A8=E8=A7=A6=E5=8F=91=E9=80=89=E6=8B=A9=E5=88=86?= =?UTF-8?q?=E6=94=AF=E5=92=8C=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-image.yml | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 528f658..7b7bdf1 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,8 +2,22 @@ name: Build and Push Docker Image on: release: - types: [ published ] # 发布 release 时触发 - workflow_dispatch: # 手动触发 + types: [published] + workflow_dispatch: + inputs: + branch: + description: '要构建的分支' + required: true + default: 'dev' + type: choice + options: + - dev + - main + tag: + description: '镜像标签' + required: true + default: 'dev' + type: string env: REGISTRY: docker.io @@ -19,12 +33,13 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.branch || 'main' }} - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to Docker Hub - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKER_USERNAME }} @@ -36,14 +51,15 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=semver,pattern={{version}} # v0.0.1 - type=raw,value=latest,enable={{is_default_branch}} # latest + type=semver,pattern={{version}} + type=raw,value=latest,enable=${{ github.event_name == 'release' }} + type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }} - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . - push: ${{ github.event_name != 'pull_request' }} + push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} platforms: linux/amd64,linux/arm64 @@ -51,7 +67,7 @@ jobs: cache-to: type=gha,mode=max - name: Update Docker Hub README - if: github.event_name != 'pull_request' + if: github.event_name == 'release' uses: peter-evans/dockerhub-description@v3 with: username: ${{ secrets.DOCKER_USERNAME }}