Skip to content

Commit a78e947

Browse files
committed
Setup Go action
1 parent ed0ff76 commit a78e947

2 files changed

Lines changed: 60 additions & 93 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Prepare Go
2+
description: Set up Go, restore caches, and download modules with retry.
3+
4+
outputs:
5+
dependency-cache-hit:
6+
description: Whether the Go module cache was restored from an exact match.
7+
value: ${{ steps.restore-deps.outputs.cache-hit }}
8+
dependency-cache-primary-key:
9+
description: Primary key used for the Go module cache restore.
10+
value: ${{ steps.restore-deps.outputs.cache-primary-key }}
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
16+
id: setup-go
17+
with:
18+
go-version-file: "go.mod"
19+
cache: false # do our own caching
20+
21+
- name: Restore dependencies
22+
id: restore-deps
23+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
24+
with:
25+
path: ~/go/pkg/mod
26+
key: go-${{ runner.os }}${{ runner.arch }}-${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.mod') }}-deps-${{ hashFiles('go.sum') }}
27+
28+
# Cache restore can miss modules after go.sum changes or partial cache saves.
29+
# Retrying download here isolates transient Go proxy failures from the Go command.
30+
- name: Download Go modules
31+
uses: nick-fields/retry@ad984534de44a9489a53aefd81eb77f87c70dc60 # v4.0.0
32+
with:
33+
max_attempts: 3
34+
retry_wait_seconds: 10
35+
timeout_minutes: 5
36+
shell: bash
37+
command: go mod download
38+
39+
- name: Restore build outputs
40+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
41+
with:
42+
path: ~/.cache/go-build
43+
key: go-${{ runner.os }}${{ runner.arch }}-${{ steps.setup-go.outputs.go-version }}-build-${{ env.COMMIT }}
44+
restore-keys: |
45+
go-${{ runner.os }}${{ runner.arch }}-${{ steps.setup-go.outputs.go-version }}-build-

.github/workflows/run-tests.yml

Lines changed: 15 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -222,26 +222,18 @@ jobs:
222222
token: ${{ secrets.GITHUB_TOKEN }}
223223
ref: ${{ env.COMMIT }}
224224

225-
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
226-
with:
227-
go-version-file: "go.mod"
228-
cache: false # do our own caching
229-
230-
- name: Restore dependencies
231-
id: restore-deps
232-
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
233-
with:
234-
path: ~/go/pkg/mod
235-
key: go-${{ runner.os }}${{ runner.arch }}-${{ hashFiles('go.mod') }}-deps-${{ hashFiles('go.sum') }}
225+
- name: Set up Go
226+
id: prepare-go
227+
uses: ./.github/actions/prepare-go
236228

237229
- run: make pre-build-functional-test-coverage
238230

239231
- name: Save dependencies
240232
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
241-
if: ${{ steps.restore-deps.outputs.cache-hit != 'true' }}
233+
if: ${{ steps.prepare-go.outputs.dependency-cache-hit != 'true' }}
242234
with:
243235
path: ~/go/pkg/mod
244-
key: ${{ steps.restore-deps.outputs.cache-primary-key }}
236+
key: ${{ steps.prepare-go.outputs.dependency-cache-primary-key }}
245237

246238
- name: Save build outputs
247239
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
@@ -261,22 +253,8 @@ jobs:
261253
# buf-breaking tries to compare HEAD against merge base so we need to be able to find it
262254
fetch-depth: 100
263255

264-
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
265-
with:
266-
go-version-file: "go.mod"
267-
cache: false # do our own caching
268-
269-
- name: Restore dependencies
270-
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
271-
with:
272-
path: ~/go/pkg/mod
273-
key: go-${{ runner.os }}${{ runner.arch }}-${{ hashFiles('go.mod') }}-deps-${{ hashFiles('go.sum') }}
274-
275-
- name: Restore build outputs
276-
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
277-
with:
278-
path: ~/.cache/go-build
279-
key: go-${{ runner.os }}${{ runner.arch }}-build-${{ env.COMMIT }}
256+
- name: Set up Go
257+
uses: ./.github/actions/prepare-go
280258

281259
- uses: jdx/mise-action@dba19683ed58901619b14f395a24841710cb4925 # v4.1.0
282260
with:
@@ -299,22 +277,8 @@ jobs:
299277
token: ${{ secrets.GITHUB_TOKEN }}
300278
ref: ${{ env.COMMIT }}
301279

302-
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
303-
with:
304-
go-version-file: "go.mod"
305-
cache: false # do our own caching
306-
307-
- name: Restore dependencies
308-
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
309-
with:
310-
path: ~/go/pkg/mod
311-
key: go-${{ runner.os }}${{ runner.arch }}-${{ hashFiles('go.mod') }}-deps-${{ hashFiles('go.sum') }}
312-
313-
- name: Restore build outputs
314-
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
315-
with:
316-
path: ~/.cache/go-build
317-
key: go-${{ runner.os }}${{ runner.arch }}-build-${{ env.COMMIT }}
280+
- name: Set up Go
281+
uses: ./.github/actions/prepare-go
318282

319283
- name: Run unit tests
320284
timeout-minutes: 20
@@ -347,22 +311,8 @@ jobs:
347311
compose_file: ${{ env.DOCKER_COMPOSE_FILE }}
348312
services: ${{ env.CONTAINERS }}
349313

350-
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
351-
with:
352-
go-version-file: "go.mod"
353-
cache: false # do our own caching
354-
355-
- name: Restore dependencies
356-
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
357-
with:
358-
path: ~/go/pkg/mod
359-
key: go-${{ runner.os }}${{ runner.arch }}-${{ hashFiles('go.mod') }}-deps-${{ hashFiles('go.sum') }}
360-
361-
- name: Restore build outputs
362-
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
363-
with:
364-
path: ~/.cache/go-build
365-
key: go-${{ runner.os }}${{ runner.arch }}-build-${{ env.COMMIT }}
314+
- name: Set up Go
315+
uses: ./.github/actions/prepare-go
366316

367317
- name: Wait for containerized dependencies to be healthy
368318
uses: ./.github/actions/docker-compose-healthy
@@ -419,22 +369,8 @@ jobs:
419369
services: ${{ env.CONTAINERS }}
420370
cache: true
421371

422-
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
423-
with:
424-
go-version-file: "go.mod"
425-
cache: false # do our own caching
426-
427-
- name: Restore dependencies
428-
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
429-
with:
430-
path: ~/go/pkg/mod
431-
key: go-${{ runner.os }}${{ runner.arch }}-${{ hashFiles('go.mod') }}-deps-${{ hashFiles('go.sum') }}
432-
433-
- name: Restore build outputs
434-
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
435-
with:
436-
path: ~/.cache/go-build
437-
key: go-${{ runner.os }}${{ runner.arch }}-build-${{ env.COMMIT }}
372+
- name: Set up Go
373+
uses: ./.github/actions/prepare-go
438374

439375
- name: ${{ matrix.display_name == 'smoke' && 'ℹ️ Smoke test' || 'ℹ️ Full test' }}
440376
run: echo "::notice::${{ matrix.display_name == 'smoke' && 'This is a smoke test. Add the test-all-dbs label to run all tests on all DBs.' || needs.test-setup.outputs.full_test_reason }}"
@@ -493,22 +429,8 @@ jobs:
493429
compose_file: ${{ env.DOCKER_COMPOSE_FILE }}
494430
services: postgresql
495431

496-
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
497-
with:
498-
go-version-file: "go.mod"
499-
cache: false
500-
501-
- name: Restore dependencies
502-
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
503-
with:
504-
path: ~/go/pkg/mod
505-
key: go-${{ runner.os }}${{ runner.arch }}-${{ hashFiles('go.mod') }}-deps-${{ hashFiles('go.sum') }}
506-
507-
- name: Restore build outputs
508-
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
509-
with:
510-
path: ~/.cache/go-build
511-
key: go-${{ runner.os }}${{ runner.arch }}-build-${{ env.COMMIT }}
432+
- name: Set up Go
433+
uses: ./.github/actions/prepare-go
512434

513435
- name: Install PostgreSQL schema
514436
run: make install-schema-postgresql12

0 commit comments

Comments
 (0)