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') }}
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