Skip to content

Commit 78a2d65

Browse files
committed
ci(workflow): 更新 GitHub Actions 依赖至最新版本并优化 Docker 推送逻辑
更新 actions/cache、codecov-action 和 upload-artifact 至 v4 版本 优化 Docker 镜像构建推送逻辑,仅在配置 secrets 且为 main 分支时推送
1 parent 15a4dd7 commit 78a2d65

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
go-version: '1.23'
3838

3939
- name: Cache Go modules
40-
uses: actions/cache@v3
40+
uses: actions/cache@v4
4141
with:
4242
path: ~/go/pkg/mod
4343
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
@@ -84,7 +84,7 @@ jobs:
8484
REDIS_PORT: 6379
8585

8686
- name: Upload coverage to Codecov
87-
uses: codecov/codecov-action@v3
87+
uses: codecov/codecov-action@v4
8888
with:
8989
file: ./coverage.out
9090
flags: unittests
@@ -107,7 +107,7 @@ jobs:
107107
go build -v -ldflags "-X gotribe-admin/internal/pkg/common.GitVersion=$(git describe --tags --always --dirty) -X gotribe-admin/internal/pkg/common.GitCommit=$(git rev-parse HEAD) -X gotribe-admin/internal/pkg/common.GitTreeState=$(if [ -z "$(git status --porcelain)" ]; then echo "clean"; else echo "dirty"; fi) -X gotribe-admin/internal/pkg/common.BuildDate=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" -o gotribe-admin .
108108
109109
- name: Upload build artifacts
110-
uses: actions/upload-artifact@v3
110+
uses: actions/upload-artifact@v4
111111
with:
112112
name: gotribe-admin-linux-amd64
113113
path: gotribe-admin
@@ -122,7 +122,9 @@ jobs:
122122
- name: Set up Docker Buildx
123123
uses: docker/setup-buildx-action@v3
124124

125+
# 如果配置了 Docker Hub secrets,则登录
125126
- name: Login to Docker Hub
127+
if: ${{ secrets.DOCKER_USERNAME && secrets.DOCKER_PASSWORD }}
126128
uses: docker/login-action@v3
127129
with:
128130
username: ${{ secrets.DOCKER_USERNAME }}
@@ -140,12 +142,13 @@ jobs:
140142
type=semver,pattern={{major}}.{{minor}}
141143
type=raw,value=latest,enable={{is_default_branch}}
142144
143-
- name: Build and push Docker image
145+
- name: Build and conditionally push Docker image
144146
uses: docker/build-push-action@v5
145147
with:
146148
context: .
147149
platforms: linux/amd64,linux/arm64
148-
push: true
150+
# 只有在配置了 secrets 且是 main 分支时才推送
151+
push: ${{ secrets.DOCKER_USERNAME && secrets.DOCKER_PASSWORD && github.ref == 'refs/heads/main' }}
149152
tags: ${{ steps.meta.outputs.tags }}
150153
labels: ${{ steps.meta.outputs.labels }}
151154
cache-from: type=gha

0 commit comments

Comments
 (0)