Skip to content

Commit 87a8840

Browse files
committed
update build workflow with cache and repository variables
1 parent e98c135 commit 87a8840

File tree

2 files changed

+85
-17
lines changed

2 files changed

+85
-17
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

.github/workflows/build.yml

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,20 @@ on:
88

99
jobs:
1010
build:
11-
strategy:
12-
matrix:
13-
runs-on: [ ubuntu-latest ]
14-
runs-on: ${{ matrix.runs-on }}
11+
runs-on: ubuntu-latest
1512
name: Build
1613
steps:
17-
- name: Set up Go 1.x
18-
uses: actions/setup-go@v3
19-
with:
20-
go-version: 1.20.7
21-
id: go
22-
2314
- name: Check out code into the Go module directory
2415
uses: actions/checkout@v3
2516

26-
- name: Get dependencies
27-
run: |
28-
go get -v -t -d ./...
29-
if [ -f Gopkg.toml ]; then
30-
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
31-
dep ensure
32-
fi
17+
- name: Go Setup
18+
uses: ./.github/actions/go-setup-action
19+
with:
20+
go-version: ${{vars.GO_VERSION }}
21+
go-private: ${{vars.GO_PRIVATE_REPO }}
22+
git-user: ${{ secrets.GIT_USER }}
23+
git-pass: ${{ secrets.GIT_PASS }}
24+
3325
- name: Build
3426
run: |
3527
cd ${GITHUB_WORKSPACE}/cmd/bridge && go build .

0 commit comments

Comments
 (0)