-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
62 lines (58 loc) · 2.18 KB
/
action.yml
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
54
55
56
57
58
59
60
61
62
name: Golang with cache
inputs:
version:
description: Golang version.
default:
version-file:
description: Golang version from go.mod. Used in place of `version`.
default:
cache-key-suffix:
description: Optional cache key suffix.
default:
runs:
using: composite
steps:
- name: Resolve Golang version and set GOTOOLCHAIN
id: version
run: |
semver="${{ inputs.version }}"
if [[ -n "${{ inputs.version-file }}" ]]; then
if [[ ! -f "${{ inputs.version-file }}" ]]; then
echo "::error title=Extract Golang version from file::Requested module file not found: ${{ inputs.version-file }}."
exit 1
fi
goVersion=$(cat "${{ inputs.version-file }}" | grep --extended-regexp "^go +[0-9]")
# ignore PATCH component - only consider MAJOR.MINOR
if [[ $goVersion =~ ^go\ +([0-9]\.[0-9]+) ]]; then
semver=${BASH_REMATCH[1]}
else
echo "::error title=Extract Golang version from file::Unable to locate valid semver from module file: ${{ inputs.version-file }}."
exit 1
fi
fi
echo "semver=$semver" >>"$GITHUB_OUTPUT"
echo "GOTOOLCHAIN=local" >>"$GITHUB_ENV"
shell: bash
- name: Setup Golang
uses: actions/setup-go@v5
with:
cache: false
go-version: ${{ steps.version.outputs.semver }}
- name: Determine cache paths/cache key
id: vars
run: |
echo "path-build=$(go env GOCACHE)" >>"$GITHUB_OUTPUT"
echo "path-module=$(go env GOMODCACHE)" >>"$GITHUB_OUTPUT"
cacheKeyRoot="golang-${{ runner.os }}${{ 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:
key: ${{ steps.vars.outputs.cache-key }}
path: |
${{ steps.vars.outputs.path-build }}
${{ steps.vars.outputs.path-module }}
restore-keys: |
${{ steps.vars.outputs.cache-key-restore }}