|
6 | 6 | tags: [ 'v*' ] |
7 | 7 | pull_request: |
8 | 8 | 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 |
9 | 20 |
|
10 | 21 | env: |
11 | 22 | REGISTRY: ghcr.io |
@@ -44,23 +55,30 @@ jobs: |
44 | 55 | type=semver,pattern={{major}}.{{minor}} |
45 | 56 | type=semver,pattern={{major}} |
46 | 57 | type=raw,value=latest,enable={{is_default_branch}} |
| 58 | + type=raw,value=${{ github.event.inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }} |
47 | 59 |
|
48 | 60 | - name: 构建并推送 Docker 镜像 |
49 | 61 | uses: docker/build-push-action@v5 |
50 | 62 | with: |
51 | 63 | context: . |
52 | 64 | platforms: linux/amd64,linux/arm64 |
53 | | - push: true |
| 65 | + push: ${{ github.event_name != 'workflow_dispatch' || github.event.inputs.push_to_registry == 'true' }} |
54 | 66 | tags: ${{ steps.meta.outputs.tags }} |
55 | 67 | labels: ${{ steps.meta.outputs.labels }} |
56 | 68 | cache-from: type=gha |
57 | 69 | cache-to: type=gha,mode=max |
58 | 70 |
|
59 | 71 | - name: 生成摘要 |
60 | | - if: github.event_name == 'push' |
| 72 | + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' |
61 | 73 | run: | |
62 | 74 | echo "## 🐳 Docker 镜像构建完成" >> $GITHUB_STEP_SUMMARY |
63 | 75 | 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 |
64 | 82 | echo "**镜像标签:**" >> $GITHUB_STEP_SUMMARY |
65 | 83 | echo '```' >> $GITHUB_STEP_SUMMARY |
66 | 84 | echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY |
|
69 | 87 | echo "**拉取命令:**" >> $GITHUB_STEP_SUMMARY |
70 | 88 | echo '```bash' >> $GITHUB_STEP_SUMMARY |
71 | 89 | 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 |
72 | 93 | echo '```' >> $GITHUB_STEP_SUMMARY |
0 commit comments