Skip to content

Commit 0528047

Browse files
committed
Use vendoring instead of Go module caching
Replace Go module cache with vendored dependencies shared via artifact. This is faster and more reliable than caching. Vendor directory is created once in prepare-dependencies job and shared across all test jobs using GOFLAGS=-mod=vendor.
1 parent 0881fc5 commit 0528047

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

.github/workflows/main.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,45 @@ jobs:
2121
- name: Running ${{ matrix.command }}
2222
run: ${{ matrix.command }}
2323

24-
prepare-terraform:
25-
name: Prepare Terraform Binary
24+
prepare-dependencies:
25+
name: Prepare Dependencies
2626
runs-on: ubuntu-22.04
2727
steps:
2828
- name: Checkout Git repo
2929
uses: actions/checkout@v4
3030

31+
- name: Set up Go
32+
uses: actions/setup-go@v4
33+
with:
34+
go-version-file: go.mod
35+
3136
- name: Download Terraform
3237
run: |
3338
mkdir -p bin
3439
curl -sfL https://releases.hashicorp.com/terraform/1.5.6/terraform_1.5.6_linux_amd64.zip > bin/terraform.zip
3540
cd bin && unzip terraform.zip && rm terraform.zip && chmod +x terraform
3641
42+
- name: Vendor Go dependencies
43+
run: go mod vendor
44+
3745
- name: Upload Terraform binary
3846
uses: actions/upload-artifact@v4
3947
with:
4048
name: terraform-binary
4149
path: bin/terraform
4250
retention-days: 1
51+
52+
- name: Upload vendor directory
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: vendor-dir
56+
path: vendor/
57+
retention-days: 1
58+
compression-level: 6
4359

4460
tests:
4561
runs-on: ubuntu-22.04
46-
needs: [prepare-terraform]
62+
needs: [prepare-dependencies]
4763
strategy:
4864
fail-fast: false
4965
matrix:
@@ -72,22 +88,18 @@ jobs:
7288
with:
7389
go-version-file: go.mod
7490

75-
- name: Cache Go modules
76-
uses: actions/cache@v4
77-
with:
78-
path: |
79-
~/.cache/go-build
80-
~/go/pkg/mod
81-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
82-
restore-keys: |
83-
${{ runner.os }}-go-
84-
8591
- name: Download Terraform binary
8692
uses: actions/download-artifact@v4
8793
with:
8894
name: terraform-binary
8995
path: bin/
9096

97+
- name: Download vendor directory
98+
uses: actions/download-artifact@v4
99+
with:
100+
name: vendor-dir
101+
path: vendor/
102+
91103
- name: Make Terraform executable
92104
run: chmod +x bin/terraform
93105

@@ -97,6 +109,8 @@ jobs:
97109
sudo apt-get -f -y install mysql-client
98110
99111
- name: Run tests {{ matrix.target }}
112+
env:
113+
GOFLAGS: -mod=vendor
100114
run: make ${{ matrix.target }}
101115
# DISABLED to figure out GPG signing issue on Github Actions
102116
# possibly due to lack of TTY inside docker?

0 commit comments

Comments
 (0)