Skip to content

Commit ca18c1f

Browse files
committed
ci(workflow): 修改Docker构建流程以忽略登录失败
将Docker Hub登录和镜像推送步骤改为忽略错误继续执行,不再严格依赖secrets配置
1 parent 1a5b384 commit ca18c1f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ jobs:
122122
- name: Set up Docker Buildx
123123
uses: docker/setup-buildx-action@v3
124124

125-
# 如果配置了 Docker Hub secrets,则登录
125+
# 尝试登录 Docker Hub(如果没有配置 secrets 会失败但不影响构建)
126126
- name: Login to Docker Hub
127-
if: ${{ secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != '' }}
127+
continue-on-error: true
128128
uses: docker/login-action@v3
129129
with:
130130
username: ${{ secrets.DOCKER_USERNAME }}
@@ -142,13 +142,14 @@ jobs:
142142
type=semver,pattern={{major}}.{{minor}}
143143
type=raw,value=latest,enable={{is_default_branch}}
144144
145-
- name: Build and conditionally push Docker image
145+
- name: Build and push Docker image
146+
continue-on-error: true
146147
uses: docker/build-push-action@v5
147148
with:
148149
context: .
149150
platforms: linux/amd64,linux/arm64
150-
# 只有在配置了 secrets 且是 main 分支时才推送
151-
push: ${{ secrets.DOCKER_USERNAME != '' && secrets.DOCKER_PASSWORD != '' && github.ref == 'refs/heads/main' }}
151+
# 只在 main 分支推送,如果没有登录会失败但不影响构建
152+
push: ${{ github.ref == 'refs/heads/main' }}
152153
tags: ${{ steps.meta.outputs.tags }}
153154
labels: ${{ steps.meta.outputs.labels }}
154155
cache-from: type=gha

0 commit comments

Comments
 (0)