ci(drone): 添加 Go 模块和构建缓存

- 在 restore cache 和 rebuild cache 步骤中添加了 go-mod-cache 和 go
This commit is contained in:
hxt
2025-07-08 21:46:00 +08:00
parent d9384ded4c
commit ba41978174

View File

@@ -7,52 +7,45 @@ steps:
image: drillster/drone-volume-cache
volumes:
- name: go-mod-cache
path: /go/pkg/mod
path: /opt/drone/cache/go-mod
- name: go-build-cache
path: /root/.cache/go-build
path: /opt/drone/cache/go-build
settings:
restore: true
mount:
- /go/pkg/mod
- /root/.cache/go-build
- /opt/drone/cache/go-mod
- /opt/drone/cache/go-build
backend: local
cache_key: go-mod-cache-${DRONE_BRANCH}
- name: build
image: golang:1.22
commands:
- mkdir -p /go/pkg/mod
- mkdir -p /root/.cache/go-build
- echo "test" > /go/pkg/mod/testfile
- echo "==== Before build, go/pkg/mod ===="
- ls -lR /go/pkg/mod || echo "/go/pkg/mod not found"
- echo "==== Before build, /root/.cache/go-build ===="
- ls -lR /root/.cache/go-build || echo "/root/.cache/go-build not found"
- echo "==== Before build, /go/.cache/go-build ===="
- ls -lR /go/.cache/go-build || echo "/go/.cache/go-build not found"
- mkdir -p /opt/drone/cache/go-mod
- mkdir -p /opt/drone/cache/go-build
- go env -w GOMODCACHE=/opt/drone/cache/go-mod
- go env -w GOCACHE=/opt/drone/cache/go-build
- go env -w GO111MODULE=on
- go env -w GOPROXY=https://goproxy.cn,direct
- go mod tidy
- go build -o main.exe .
- echo "==== After build, go/pkg/mod ===="
- ls -lR /go/pkg/mod || echo "/go/pkg/mod not found"
- echo "==== After build, /root/.cache/go-build ===="
- ls -lR /root/.cache/go-build || echo "/root/.cache/go-build not found"
- echo "==== After build, /go/.cache/go-build ===="
- ls -lR /go/.cache/go-build || echo "/go/.cache/go-build not found"
- echo "==== After build, /opt/drone/cache/go-mod ===="
- ls -lR /opt/drone/cache/go-mod || echo "/opt/drone/cache/go-mod not found"
- echo "==== After build, /opt/drone/cache/go-build ===="
- ls -lR /opt/drone/cache/go-build || echo "/opt/drone/cache/go-build not found"
- name: rebuild cache
image: drillster/drone-volume-cache
volumes:
- name: go-mod-cache
path: /go/pkg/mod
path: /opt/drone/cache/go-mod
- name: go-build-cache
path: /root/.cache/go-build
path: /opt/drone/cache/go-build
settings:
rebuild: true
mount:
- /go/pkg/mod
- /root/.cache/go-build
- /opt/drone/cache/go-mod
- /opt/drone/cache/go-build
backend: local
cache_key: go-mod-cache-${DRONE_BRANCH}