mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
77 lines
2.4 KiB
YAML
77 lines
2.4 KiB
YAML
name: "Go cache"
|
|
description: Restore and save Go build and module caches.
|
|
inputs:
|
|
cache-path:
|
|
description: "Optional newline-delimited cache paths. Defaults to go env GOCACHE and GOMODCACHE."
|
|
required: false
|
|
default: ""
|
|
key-prefix:
|
|
description: "Prefix for the cache key."
|
|
required: false
|
|
default: "go"
|
|
download-modules:
|
|
description: "Whether to run go mod download after restoring cache."
|
|
required: false
|
|
default: "true"
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Compute Go cache key
|
|
id: go-cache
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
if [[ -n "${INPUT_CACHE_PATH}" ]]; then
|
|
paths="${INPUT_CACHE_PATH}"
|
|
else
|
|
paths="$(printf '%s\n%s' "$(go env GOCACHE)" "$(go env GOMODCACHE)")"
|
|
fi
|
|
|
|
go_version="$(go env GOVERSION)"
|
|
paths_hash="$(printf '%s\n' "${paths}" | git hash-object --stdin)"
|
|
hash="$(
|
|
{
|
|
printf '%s\n' "${go_version}"
|
|
for file in go.mod go.sum; do
|
|
if [[ -f "${file}" ]]; then
|
|
git hash-object "${file}"
|
|
fi
|
|
done
|
|
} | git hash-object --stdin
|
|
)"
|
|
|
|
{
|
|
echo "path<<EOF"
|
|
echo "${paths}"
|
|
echo "EOF"
|
|
echo "key=${INPUT_KEY_PREFIX}-${RUNNER_OS}-${RUNNER_ARCH}-${paths_hash}-${hash}"
|
|
echo "restore-key=${INPUT_KEY_PREFIX}-${RUNNER_OS}-${RUNNER_ARCH}-${paths_hash}-"
|
|
} >> "$GITHUB_OUTPUT"
|
|
env:
|
|
INPUT_CACHE_PATH: ${{ inputs.cache-path }}
|
|
INPUT_KEY_PREFIX: ${{ inputs.key-prefix }}
|
|
|
|
- name: Restore Go cache, save on main
|
|
if: ${{ github.ref == 'refs/heads/main' }}
|
|
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
|
with:
|
|
path: ${{ steps.go-cache.outputs.path }}
|
|
key: ${{ steps.go-cache.outputs.key }}
|
|
restore-keys: |
|
|
${{ steps.go-cache.outputs.restore-key }}
|
|
|
|
- name: Restore Go cache read-only
|
|
if: ${{ github.ref != 'refs/heads/main' }}
|
|
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
|
with:
|
|
path: ${{ steps.go-cache.outputs.path }}
|
|
key: ${{ steps.go-cache.outputs.key }}
|
|
restore-keys: |
|
|
${{ steps.go-cache.outputs.restore-key }}
|
|
|
|
- name: Download Go modules
|
|
if: ${{ inputs.download-modules == 'true' }}
|
|
shell: bash
|
|
run: ./.github/scripts/retry.sh -- go mod download -x
|