1+ name : ' Go Setup Action'
2+ description : ' Sets up Go environment with private modules support and caching'
3+ inputs :
4+ go-version :
5+ description : ' The Go version to use'
6+ required : false
7+ default : ' 1.22.1'
8+ go-private :
9+ description : ' Private go modules'
10+ required : false
11+ default : ' github.com/klever-io/*'
12+ cache-enabled :
13+ description : ' Enable caching of Go modules'
14+ required : false
15+ default : ' true'
16+ git-user :
17+ description : ' Git username for private modules'
18+ required : false
19+ git-pass :
20+ description : ' Git password or token for private modules'
21+ required : false
22+
23+ runs :
24+ using : " composite"
25+ steps :
26+ - name : Set up Golang
27+ uses : actions/setup-go@v5
28+ with :
29+ go-version : ${{ inputs.go-version }}
30+ cache : false
31+
32+ - name : Configure git for private modules
33+ if : inputs.git-user != '' && inputs.git-pass != ''
34+ shell : bash
35+ run : |
36+ git config --global url."https://${{ inputs.git-user }}:${{ inputs.git-pass }}@github.com".insteadOf "https://github.com"
37+
38+ - name : Cache Go dependencies
39+ id : cache_vendor
40+ if : inputs.cache-enabled == 'true'
41+ uses : actions/cache@v4
42+ env :
43+ cache-name : go-cache-vendor
44+ with :
45+ path : |
46+ ~/go/pkg/mod
47+ ./vendor
48+ key : ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}
49+ restore-keys : |
50+ ${{ runner.os }}-${{ env.cache-name }}-
51+ enableCrossOsArchive : true
52+
53+ - name : Resolve package to module & Download dependencies
54+ if : ${{ steps.cache_vendor.outputs.cache-hit != 'true' }}
55+ shell : bash
56+ run : |
57+ go mod tidy
58+ go mod download
59+
60+ - name : Generate Vendor and Install modvendor
61+ if : ${{ steps.cache_vendor.outputs.cache-hit != 'true' }}
62+ shell : bash
63+ run : |
64+ go install github.com/goware/modvendor@latest
65+ go mod vendor
66+ modvendor -copy="**/*.c **/*.h **/*.proto **/*.a"
67+
68+ - name : Verify no changes from go mod tidy
69+ shell : bash
70+ run : |
71+ go mod tidy
72+ if [ -n "$(git status --porcelain)" ]; then
73+ echo "Changes found after go mod tidy:"
74+ git status --porcelain
75+ exit 1
76+ fi
0 commit comments