Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit 3f5ba6e

Browse files
committed
feat: allow manual
1 parent 0ddeea7 commit 3f5ba6e

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

.github/workflows/docker-build.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ on:
66
tags: [ 'v*' ]
77
pull_request:
88
branches: [ main ]
9+
workflow_dispatch:
10+
inputs:
11+
tag:
12+
description: '自定义标签 (可选)'
13+
required: false
14+
default: 'manual'
15+
push_to_registry:
16+
description: '推送到注册表'
17+
required: true
18+
default: true
19+
type: boolean
920

1021
env:
1122
REGISTRY: ghcr.io
@@ -44,23 +55,30 @@ jobs:
4455
type=semver,pattern={{major}}.{{minor}}
4556
type=semver,pattern={{major}}
4657
type=raw,value=latest,enable={{is_default_branch}}
58+
type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
4759
4860
- name: 构建并推送 Docker 镜像
4961
uses: docker/build-push-action@v5
5062
with:
5163
context: .
5264
platforms: linux/amd64,linux/arm64
53-
push: true
65+
push: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.push_to_registry == 'true' }}
5466
tags: ${{ steps.meta.outputs.tags }}
5567
labels: ${{ steps.meta.outputs.labels }}
5668
cache-from: type=gha
5769
cache-to: type=gha,mode=max
5870

5971
- name: 生成摘要
60-
if: github.event_name == 'push'
72+
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
6173
run: |
6274
echo "## 🐳 Docker 镜像构建完成" >> $GITHUB_STEP_SUMMARY
6375
echo "" >> $GITHUB_STEP_SUMMARY
76+
echo "**触发方式:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
77+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
78+
echo "**自定义标签:** ${{ github.event.inputs.tag }}" >> $GITHUB_STEP_SUMMARY
79+
echo "**推送到注册表:** ${{ github.event.inputs.push_to_registry }}" >> $GITHUB_STEP_SUMMARY
80+
fi
81+
echo "" >> $GITHUB_STEP_SUMMARY
6482
echo "**镜像标签:**" >> $GITHUB_STEP_SUMMARY
6583
echo '```' >> $GITHUB_STEP_SUMMARY
6684
echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY
@@ -69,4 +87,7 @@ jobs:
6987
echo "**拉取命令:**" >> $GITHUB_STEP_SUMMARY
7088
echo '```bash' >> $GITHUB_STEP_SUMMARY
7189
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY
90+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ github.event.inputs.tag }}" != "" ]; then
91+
echo "docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.event.inputs.tag }}" >> $GITHUB_STEP_SUMMARY
92+
fi
7293
echo '```' >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)