Skip to content

Commit 2fac1aa

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 2fac1aa

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

.github/workflows/main.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,30 @@ 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
36+
chmod +x bin/terraform
37+
38+
- name: Upload Terraform binary
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: terraform-binary
42+
path: bin/terraform
43+
retention-days: 1
44+
2445
tests:
2546
runs-on: ubuntu-22.04
47+
needs: [prepare-terraform]
2648
strategy:
2749
fail-fast: false
2850
matrix:
@@ -45,10 +67,36 @@ jobs:
4567
steps:
4668
- name: Checkout Git repo
4769
uses: actions/checkout@v4
70+
71+
- name: Set up Go
72+
uses: actions/setup-go@v4
73+
with:
74+
go-version-file: go.mod
75+
76+
- name: Cache Go modules
77+
uses: actions/cache@v4
78+
with:
79+
path: |
80+
~/.cache/go-build
81+
~/go/pkg/mod
82+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
83+
restore-keys: |
84+
${{ runner.os }}-go-
85+
86+
- name: Download Terraform binary
87+
uses: actions/download-artifact@v4
88+
with:
89+
name: terraform-binary
90+
path: bin/
91+
92+
- name: Make Terraform executable
93+
run: chmod +x bin/terraform
94+
4895
- name: Install mysql client
4996
run: |
5097
sudo apt-get update
5198
sudo apt-get -f -y install mysql-client
99+
52100
- name: Run tests {{ matrix.target }}
53101
run: make ${{ matrix.target }}
54102
# DISABLED to figure out GPG signing issue on Github Actions

0 commit comments

Comments
 (0)