-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yaml
53 lines (50 loc) · 1.88 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
name: Golang with cache
author: Peter Mescalchin
description: Setup requested Golang version with managed module and build caching.
inputs:
go-version:
description: Desired Golang version.
default:
go-version-file:
description: Path to go.mod file, will determine Golang version. Use in place of `go-version` input.
default:
cache-key-suffix:
description: Optional cache key suffix.
default:
outputs:
build-cache-path:
description: Golang build cache path.
value: ${{ steps.golang-env.outputs.build-cache-path }}
module-cache-path:
description: Golang module cache path.
value: ${{ steps.golang-env.outputs.module-cache-path }}
cache-key:
description: Cache key holding Golang build and module cache paths.
value: ${{ steps.golang-env.outputs.cache-key }}
runs:
using: composite
steps:
- name: Setup Golang
uses: actions/setup-go@v5
with:
cache: false
go-version: ${{ inputs.go-version }}
go-version-file: ${{ inputs.go-version-file }}
- name: Determine Golang cache paths and construct cache key
id: golang-env
run: |
echo "build-cache-path=$(go env GOCACHE)" >>"$GITHUB_OUTPUT"
echo "module-cache-path=$(go env GOMODCACHE)" >>"$GITHUB_OUTPUT"
cacheKeyRoot="${{ runner.os }}-golang${{ inputs.cache-key-suffix && format('-{0}',inputs.cache-key-suffix) }}-"
echo "cache-key-restore=$cacheKeyRoot" >>"$GITHUB_OUTPUT"
echo "cache-key=${cacheKeyRoot}${{ hashFiles('**/go.sum') }}" >>"$GITHUB_OUTPUT"
shell: bash
- name: Setup Golang cache
uses: actions/cache@v4
with:
path: |
${{ steps.golang-env.outputs.build-cache-path }}
${{ steps.golang-env.outputs.module-cache-path }}
key: ${{ steps.golang-env.outputs.cache-key }}
restore-keys: |
${{ steps.golang-env.outputs.cache-key-restore }}