Skip to content

Commit a779588

Browse files
🌱 Add separate cache for long-running tests (#3293)
* Add separate cache for unit tests. Signed-off-by: Spencer Schrock <[email protected]> * share cache with gitlab tests too. Signed-off-by: Spencer Schrock <[email protected]> * share cache with github integration tests. Signed-off-by: Spencer Schrock <[email protected]> * explicitly download modules in unit test job Signed-off-by: Spencer Schrock <[email protected]> * checkout needs to be before the go.mod is read. Signed-off-by: Spencer Schrock <[email protected]> * checkout needs to be before the go.sum files are hashed. Signed-off-by: Spencer Schrock <[email protected]> --------- Signed-off-by: Spencer Schrock <[email protected]>
1 parent 67e3f75 commit a779588

File tree

3 files changed

+67
-33
lines changed

3 files changed

+67
-33
lines changed

.github/workflows/gitlab.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ on:
2424
branches:
2525
- main
2626

27+
env:
28+
GO_VERSION_FILE: go.mod # no good way of getting a mutual version between go.mod and tools/go.mod
29+
2730
jobs:
2831
gitlab-integration-trusted:
2932
runs-on: ubuntu-latest
@@ -33,17 +36,30 @@ jobs:
3336
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
3437
with:
3538
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
36-
3739
- name: Clone the code
3840
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
3941
with:
4042
ref: ${{ github.event.pull_request.head.sha || github.sha }} # head SHA if PR, else fallback to push SHA
41-
42-
- name: setup-go
43+
- name: Setup Go
4344
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
4445
with:
45-
go-version: '1.19'
46+
go-version-file: ${{ env.GO_VERSION_FILE }}
4647
check-latest: true
48+
cache: false # we manually manage caches below
49+
- id: go-cache-paths
50+
run: |
51+
echo "go-build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
52+
echo "go-mod=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
53+
- name: Cache builds
54+
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
55+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 #v3.3.1
56+
with:
57+
path: |
58+
${{ steps.go-cache-paths.outputs.go-build }}
59+
${{ steps.go-cache-paths.outputs.go-mod }}
60+
key: ${{ runner.os }}-go-tests-${{ hashFiles('**/go.sum') }}
61+
restore-keys: |
62+
${{ runner.os }}-go-tests-
4763
4864
- name: Prepare test env
4965
run: |

.github/workflows/integration.yml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ on:
2323
permissions:
2424
contents: read
2525

26+
env:
27+
GO_VERSION_FILE: go.mod # no good way of getting a mutual version between go.mod and tools/go.mod
28+
2629
jobs:
2730
approve:
2831
runs-on: ubuntu-latest
@@ -41,27 +44,40 @@ jobs:
4144
needs: [approve]
4245
steps:
4346
- name: Harden Runner
44-
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v1
47+
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
4548
with:
4649
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
47-
48-
- name: pull_request actions/checkout
49-
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v2.3.4
50+
- name: Clone the code
51+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
5052
with:
5153
ref: ${{ github.event.pull_request.head.sha }}
52-
53-
- name: setup-go
54-
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v2.2.0
54+
- name: Setup Go
55+
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
5556
with:
56-
go-version: '1.19'
57+
go-version-file: ${{ env.GO_VERSION_FILE }}
5758
check-latest: true
59+
cache: false # we manually manage caches below
60+
- id: go-cache-paths
61+
run: |
62+
echo "go-build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
63+
echo "go-mod=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
64+
- name: Cache builds
65+
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
66+
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 #v3.3.1
67+
with:
68+
path: |
69+
${{ steps.go-cache-paths.outputs.go-build }}
70+
${{ steps.go-cache-paths.outputs.go-mod }}
71+
key: ${{ runner.os }}-go-tests-${{ hashFiles('**/go.sum') }}
72+
restore-keys: |
73+
${{ runner.os }}-go-tests-
5874
5975
- name: Prepare test env
6076
run: |
6177
go mod download
6278
6379
- name: Run GITHUB_TOKEN E2E #using retry because the GitHub token is being throttled.
64-
uses: nick-invision/retry@943e742917ac94714d2f408a0e8320f2d1fcafcd
80+
uses: nick-invision/retry@943e742917ac94714d2f408a0e8320f2d1fcafcd # v2.8.3
6581
env:
6682
GITHUB_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6783
with:
@@ -71,7 +87,7 @@ jobs:
7187
command: make e2e-gh-token
7288

7389
- name: codecov
74-
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # 2.1.0
90+
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # 3.1.4
7591
with:
7692
files: "*e2e-coverage.out"
7793
verbose: true

.github/workflows/main.yml

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,36 +37,38 @@ jobs:
3737
contents: read
3838
steps:
3939
- name: Harden Runner
40-
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v1
40+
uses: step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4.1
4141
with:
4242
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs
43-
43+
- name: Clone the code
44+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
45+
- name: Setup Go
46+
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1
47+
with:
48+
go-version: ${{ env.GO_VERSION }}
49+
check-latest: true
50+
cache: false # we manually manage caches below
51+
- id: go-cache-paths
52+
run: |
53+
echo "go-build=$(go env GOCACHE)" >> "$GITHUB_OUTPUT"
54+
echo "go-mod=$(go env GOMODCACHE)" >> "$GITHUB_OUTPUT"
4455
- name: Cache builds
4556
# https://github.com/mvdan/github-actions-golang#how-do-i-set-up-caching-between-builds
4657
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 #v3.3.1
4758
with:
4859
path: |
49-
~/go/pkg/mod
50-
~/.cache/go-build
51-
~/Library/Caches/go-build
52-
%LocalAppData%\go-build
53-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
60+
${{ steps.go-cache-paths.outputs.go-build }}
61+
${{ steps.go-cache-paths.outputs.go-mod }}
62+
key: ${{ runner.os }}-go-tests-${{ hashFiles('**/go.sum') }}
5463
restore-keys: |
55-
${{ runner.os }}-go-
56-
- name: Clone the code
57-
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v2.3.4
58-
with:
59-
fetch-depth: 0
60-
- name: Setup Go
61-
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v2.2.0
62-
with:
63-
go-version: ${{ env.GO_VERSION }}
64-
check-latest: true
65-
cache: true
64+
${{ runner.os }}-go-tests-
65+
- name: Prepare test env
66+
run: |
67+
go mod download
6668
- name: Run unit-tests
6769
run: make unit-test
6870
- name: Upload codecoverage
69-
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # 2.1.0
71+
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # 3.1.4
7072
with:
7173
files: ./unit-coverage.out
7274
verbose: true

0 commit comments

Comments
 (0)