Skip to content

Commit 0881fc5

Browse files
committed
Optimize GitHub Actions workflow with Terraform binary and Go module caching
Adds prepare-terraform job to download Terraform once and share via artifacts. Implements Go module caching to avoid redundant downloads across test jobs. Expected to save ~3-8 minutes and ~1.3-2.6GB per workflow run.
1 parent a7ed858 commit 0881fc5

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

.github/workflows/main.yml

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

24+
prepare-terraform:
25+
name: Prepare Terraform Binary
26+
runs-on: ubuntu-22.04
27+
steps:
28+
- name: Checkout Git repo
29+
uses: actions/checkout@v4
30+
31+
- name: Download Terraform
32+
run: |
33+
mkdir -p bin
34+
curl -sfL https://releases.hashicorp.com/terraform/1.5.6/terraform_1.5.6_linux_amd64.zip > bin/terraform.zip
35+
cd bin && unzip terraform.zip && rm terraform.zip && chmod +x terraform
36+
37+
- name: Upload Terraform binary
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: terraform-binary
41+
path: bin/terraform
42+
retention-days: 1
43+
2444
tests:
2545
runs-on: ubuntu-22.04
46+
needs: [prepare-terraform]
2647
strategy:
2748
fail-fast: false
2849
matrix:
@@ -45,10 +66,36 @@ jobs:
4566
steps:
4667
- name: Checkout Git repo
4768
uses: actions/checkout@v4
69+
70+
- name: Set up Go
71+
uses: actions/setup-go@v4
72+
with:
73+
go-version-file: go.mod
74+
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+
85+
- name: Download Terraform binary
86+
uses: actions/download-artifact@v4
87+
with:
88+
name: terraform-binary
89+
path: bin/
90+
91+
- name: Make Terraform executable
92+
run: chmod +x bin/terraform
93+
4894
- name: Install mysql client
4995
run: |
5096
sudo apt-get update
5197
sudo apt-get -f -y install mysql-client
98+
5299
- name: Run tests {{ matrix.target }}
53100
run: make ${{ matrix.target }}
54101
# DISABLED to figure out GPG signing issue on Github Actions

0 commit comments

Comments
 (0)