|
| 1 | +variables: |
| 2 | + # Define GOPATH within the project directory to allow GitLab CI to cache it. |
| 3 | + # By default, Go places modules in GOMODCACHE, often outside the project. |
| 4 | + # Explicitly setting GOMODCACHE ensures it's within the cached path. |
| 5 | + GOPATH: "$CI_PROJECT_DIR/.go" |
| 6 | + GOMODCACHE: "$GOPATH/pkg/mod" |
| 7 | + GO_BIN_DIR: "$GOPATH/bin" |
| 8 | + |
| 9 | +cache: |
| 10 | + # Cache Go modules and the binaries. |
| 11 | + # The 'key' ensures a unique cache per branch, or you can use a fixed key |
| 12 | + # for a shared cache across all branches if that fits your workflow. |
| 13 | + key: "$CI_COMMIT_REF_SLUG" |
| 14 | + paths: |
| 15 | + - ${GOPATH}/pkg/mod/ # For Go modules |
| 16 | + - ${GO_BIN_DIR}/ |
| 17 | + |
1 | 18 | stages: [build, release] |
2 | 19 |
|
3 | 20 | default: |
@@ -37,6 +54,23 @@ default: |
37 | 54 | when: always |
38 | 55 | - when: never |
39 | 56 |
|
| 57 | + |
| 58 | +# Template for Go setup, including caching and installation |
| 59 | +.go_setup: |
| 60 | + image: docker-registry.cfdata.org/stash/devtools/ci-builders/golang-1.24/master:3090-3e32590@sha256:fc81df4f8322f022d93712ee40bb1e5752fdbe9868d1e5a23fd851ad6fbecb91 |
| 61 | + before_script: |
| 62 | + - mkdir -p ${GOPATH} ${GOMODCACHE} ${GO_BIN_DIR} |
| 63 | + - export PATH=$PATH:${GO_BIN_DIR} |
| 64 | + - go env -w GOMODCACHE=${GOMODCACHE} # Ensure go uses the cached module path |
| 65 | + |
| 66 | + # Check if govulncheck is already installed and install it if not |
| 67 | + - if [ ! -f ${GO_BIN_DIR}/govulncheck ]; then |
| 68 | + echo "govulncheck not found in cache, installing..."; |
| 69 | + go install golang.org/x/vuln/cmd/govulncheck@latest; |
| 70 | + else |
| 71 | + echo "govulncheck found in cache, skipping installation."; |
| 72 | + fi |
| 73 | + |
40 | 74 | # ----------------------------------------------- |
41 | 75 | # Stage 1: Build on every PR |
42 | 76 | # ----------------------------------------------- |
@@ -64,6 +98,14 @@ build_cloudflared_macos: &build |
64 | 98 | - echo "Executing ${BUILD_SCRIPT}" |
65 | 99 | - exec ${BUILD_SCRIPT} |
66 | 100 |
|
| 101 | +vulncheck: |
| 102 | + stage: build |
| 103 | + extends: .go_setup |
| 104 | + rules: |
| 105 | + - !reference [.default_rules, run_on_branch] |
| 106 | + script: |
| 107 | + - make vulncheck |
| 108 | + |
67 | 109 | # ----------------------------------------------- |
68 | 110 | # Stage 1: Build and sign only on releases |
69 | 111 | # ----------------------------------------------- |
|
0 commit comments