Skip to content

Commit abf2038

Browse files
committed
ci: add restore/save-build-cache actions with buildtag key
Extract build cache restore and save into composite actions that take a buildtag input (plain, race, coverage) to separate cache entries by use case. Key format: gocache-{tag}-{goversion}-{os}-{arch}-{run_id}. Each job sets BUILD_TAG env and passes it to both actions. Also adds build cache to the race workflow which previously had none.
1 parent bcec595 commit abf2038

File tree

6 files changed

+99
-36
lines changed

6 files changed

+99
-36
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Restore Go build cache
2+
description: Restore Go build cache with a tagged key
3+
4+
inputs:
5+
buildtag:
6+
description: "Build cache tag (e.g. plain, race, coverage)"
7+
required: true
8+
build:
9+
description: "GOCACHE path (from setup-go outputs)"
10+
required: true
11+
goversion:
12+
description: "Go version string (from setup-go outputs)"
13+
required: true
14+
15+
runs:
16+
using: composite
17+
steps:
18+
- uses: actions/cache/restore@v4
19+
with:
20+
path: ${{ inputs.build }}
21+
key: gocache-${{ inputs.buildtag }}-${{ inputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
22+
restore-keys: gocache-${{ inputs.buildtag }}-${{ inputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Save Go build cache
2+
description: Save Go build cache with a tagged key
3+
4+
inputs:
5+
buildtag:
6+
description: "Build cache tag (e.g. plain, race, coverage)"
7+
required: true
8+
build:
9+
description: "GOCACHE path (from setup-go outputs)"
10+
required: true
11+
goversion:
12+
description: "Go version string (from setup-go outputs)"
13+
required: true
14+
15+
runs:
16+
using: composite
17+
steps:
18+
- uses: actions/cache/save@v4
19+
with:
20+
path: ${{ inputs.build }}
21+
key: gocache-${{ inputs.buildtag }}-${{ inputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}

.github/workflows/lint.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
lint:
1212
if: ${{ !github.event.pull_request.draft }}
1313
runs-on: ubuntu-latest
14+
env:
15+
BUILD_TAG: plain
1416
concurrency:
1517
group: ${{ format('{0}-{1}', github.workflow, github.ref) }}
1618
cancel-in-progress: true
@@ -34,12 +36,11 @@ jobs:
3436
- uses: ./.github/actions/setup-go
3537
id: go
3638

37-
- name: Restore Go build cache
38-
uses: actions/cache/restore@v4
39+
- uses: ./.github/actions/restore-build-cache
3940
with:
40-
path: ${{ steps.go.outputs.build }}
41-
key: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
42-
restore-keys: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-
41+
buildtag: ${{ env.BUILD_TAG }}
42+
build: ${{ steps.go.outputs.build }}
43+
goversion: ${{ steps.go.outputs.goversion }}
4344

4445
- name: Restore golangci-lint cache
4546
uses: actions/cache/restore@v4
@@ -60,12 +61,12 @@ jobs:
6061
echo "golangci-lint cache:"
6162
du -sh ~/.cache/golangci-lint || true
6263
63-
- name: Save Go build cache
64+
- uses: ./.github/actions/save-build-cache
6465
if: always()
65-
uses: actions/cache/save@v4
6666
with:
67-
path: ${{ steps.go.outputs.build }}
68-
key: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
67+
buildtag: ${{ env.BUILD_TAG }}
68+
build: ${{ steps.go.outputs.build }}
69+
goversion: ${{ steps.go.outputs.goversion }}
6970

7071
- name: Save golangci-lint cache
7172
if: always()

.github/workflows/sonar.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ on:
2020

2121
jobs:
2222
sonar:
23+
env:
24+
BUILD_TAG: coverage
2325
concurrency:
2426
group: >-
2527
${{
@@ -47,12 +49,11 @@ jobs:
4749
- uses: ./.github/actions/setup-go
4850
id: go
4951

50-
- name: Restore Go build cache
51-
uses: actions/cache/restore@v4
52+
- uses: ./.github/actions/restore-build-cache
5253
with:
53-
path: ${{ steps.go.outputs.build }}
54-
key: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
55-
restore-keys: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-
54+
buildtag: ${{ env.BUILD_TAG }}
55+
build: ${{ steps.go.outputs.build }}
56+
goversion: ${{ steps.go.outputs.goversion }}
5657

5758
- name: Install dependencies
5859
run: sudo apt-get update -q && sudo apt-get install -q -y build-essential
@@ -76,9 +77,9 @@ jobs:
7677
echo "Build/test cache:"
7778
du -sh ${{ steps.go.outputs.build }} || true
7879
79-
- name: Save Go build cache
80+
- uses: ./.github/actions/save-build-cache
8081
if: always()
81-
uses: actions/cache/save@v4
8282
with:
83-
path: ${{ steps.go.outputs.build }}
84-
key: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
83+
buildtag: ${{ env.BUILD_TAG }}
84+
build: ${{ steps.go.outputs.build }}
85+
goversion: ${{ steps.go.outputs.goversion }}

.github/workflows/test-all-erigon-race.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
- '**/.github/workflows/backups-dashboards.yml'
3636
tests-linux:
3737
needs: source-of-changes
38+
env:
39+
BUILD_TAG: race
3840
timeout-minutes: 90
3941
concurrency:
4042
# concurrency group: there can be at most one running and one pending job in a
@@ -88,6 +90,13 @@ jobs:
8890
uses: ./.github/actions/setup-go
8991
id: go
9092

93+
- uses: ./.github/actions/restore-build-cache
94+
if: needs.source-of-changes.outputs.changed_files != 'true'
95+
with:
96+
buildtag: ${{ env.BUILD_TAG }}
97+
build: ${{ steps.go.outputs.build }}
98+
goversion: ${{ steps.go.outputs.goversion }}
99+
91100
- name: Install dependencies on Linux
92101
if: needs.source-of-changes.outputs.changed_files != 'true'
93102
run: sudo apt-get update -q && sudo apt-get install -q -y build-essential
@@ -142,6 +151,13 @@ jobs:
142151
;;
143152
esac
144153
154+
- uses: ./.github/actions/save-build-cache
155+
if: always() && needs.source-of-changes.outputs.changed_files != 'true'
156+
with:
157+
buildtag: ${{ env.BUILD_TAG }}
158+
build: ${{ steps.go.outputs.build }}
159+
goversion: ${{ steps.go.outputs.goversion }}
160+
145161
- name: This ${{ matrix.os }} check does not make sense for changes within out-of-scope directories
146162
if: needs.source-of-changes.outputs.changed_files == 'true'
147163
run: echo "This check does not make sense for changes within out-of-scope directories"

.github/workflows/test-all-erigon.yml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jobs:
4444
4545
tests-mac-linux:
4646
needs: source-of-changes
47+
env:
48+
BUILD_TAG: plain
4749
concurrency:
4850
# concurrency group: there can be at most one running and one pending job in a
4951
# concurrency group at any time. So for commits on main/release, we use different
@@ -116,13 +118,12 @@ jobs:
116118
uses: ./.github/actions/setup-go
117119
id: go
118120

119-
- name: Restore Go build cache
121+
- uses: ./.github/actions/restore-build-cache
120122
if: needs.source-of-changes.outputs.changed_files != 'true'
121-
uses: actions/cache/restore@v4
122123
with:
123-
path: ${{ steps.go.outputs.build }}
124-
key: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
125-
restore-keys: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-
124+
buildtag: ${{ env.BUILD_TAG }}
125+
build: ${{ steps.go.outputs.build }}
126+
goversion: ${{ steps.go.outputs.goversion }}
126127

127128
- name: Install dependencies on Linux
128129
if: runner.os == 'Linux' && needs.source-of-changes.outputs.changed_files != 'true'
@@ -153,12 +154,12 @@ jobs:
153154
echo "Build/test cache:"
154155
du -sh ${{ steps.go.outputs.build }} || true
155156
156-
- name: Save Go build cache
157+
- uses: ./.github/actions/save-build-cache
157158
if: always() && needs.source-of-changes.outputs.changed_files != 'true'
158-
uses: actions/cache/save@v4
159159
with:
160-
path: ${{ steps.go.outputs.build }}
161-
key: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
160+
buildtag: ${{ env.BUILD_TAG }}
161+
build: ${{ steps.go.outputs.build }}
162+
goversion: ${{ steps.go.outputs.goversion }}
162163

163164
- name: This ${{ matrix.os }} check does not make sense for changes within out-of-scope directories
164165
if: needs.source-of-changes.outputs.changed_files == 'true'
@@ -167,6 +168,8 @@ jobs:
167168

168169
tests-windows:
169170
needs: source-of-changes
171+
env:
172+
BUILD_TAG: plain
170173
concurrency:
171174
group: >-
172175
${{
@@ -228,13 +231,12 @@ jobs:
228231
uses: ./.github/actions/setup-go
229232
id: go
230233

231-
- name: Restore Go build cache
234+
- uses: ./.github/actions/restore-build-cache
232235
if: needs.source-of-changes.outputs.changed_files != 'true'
233-
uses: actions/cache/restore@v4
234236
with:
235-
path: ${{ steps.go.outputs.build }}
236-
key: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
237-
restore-keys: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-
237+
buildtag: ${{ env.BUILD_TAG }}
238+
build: ${{ steps.go.outputs.build }}
239+
goversion: ${{ steps.go.outputs.goversion }}
238240

239241
- name: Install make
240242
run: choco install make -y
@@ -253,12 +255,12 @@ jobs:
253255
echo "Build/test cache:"
254256
du -sh ${{ steps.go.outputs.build }} || true
255257
256-
- name: Save Go build cache
258+
- uses: ./.github/actions/save-build-cache
257259
if: always() && needs.source-of-changes.outputs.changed_files != 'true'
258-
uses: actions/cache/save@v4
259260
with:
260-
path: ${{ steps.go.outputs.build }}
261-
key: ${{ steps.go.outputs.goversion }}-${{ runner.os }}-${{ runner.arch }}-${{ github.run_id }}
261+
buildtag: ${{ env.BUILD_TAG }}
262+
build: ${{ steps.go.outputs.build }}
263+
goversion: ${{ steps.go.outputs.goversion }}
262264

263265
- name: This ${{ matrix.os }} check does not make sense for changes within out-of-scope directories
264266
if: needs.source-of-changes.outputs.changed_files == 'true'

0 commit comments

Comments
 (0)