attempt local action for cache control (#1003)

## Description

Attempting to fix cache control.

## Type of change

- [x] 💻 CI/Deployment

## Issue(s)

* #790

## Test Plan

- [x] 💪 Manual
This commit is contained in:
Keepers 2022-10-03 17:52:36 -06:00 committed by GitHub
parent c6a9d2feb6
commit af12fba0c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 4 deletions

View File

@ -0,0 +1,61 @@
name: Setup and Cache Golang
# clone of: https://github.com/magnetikonline/action-golang-cache/blob/main/action.yaml
#
# action-golang-cache runs an optimistic restore key prefix `${{runner.os}}-golang`.
# This causes the cache@v3 to restore from any preexisting module cache in the main
# branch, whether or not that the go.sum in that cache differs from the current branch's
# go.sum. IE: once a cache exists for the main branch, we will always re-use it.
#
# Problem is, the cache identifies that as a 'cache hit', and as a result it refuses to
# store any differences we downloaded or removed using the current go.sum. IE: once
# established, it always re-uses the old cache, and never updates it.
#
# This version will only match on exact caches, and will run `go mod download` on any
# cache miss. In a workflow with chained jobs, this action should be run prior to any
# jobs that build binaries (testing, linting, etc). Downstream jobs should still use
# the magnetikonline action, since some cache restoration is better than none.
inputs:
go-version:
description: Desired Golang version to use.
go-version-file:
description: Path to go.mod file, determines Golang version to use. Used in place of `go-version` input.
cache-key-suffix:
description: Optional cache key suffix.
default:
runs:
using: composite
steps:
- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version: ${{ inputs.go-version }}
go-version-file: ${{ inputs.go-version-file }}
- name: Determine Golang cache paths
id: golang-path
run: |
echo "::set-output name=build::$(go env GOCACHE)"
echo "::set-output name=module::$(go env GOMODCACHE)"
shell: bash
- name: Setup Golang cache
id: cache
uses: actions/cache@v3
with:
path: |
${{ steps.golang-path.outputs.build }}
${{ steps.golang-path.outputs.module }}
key: ${{ runner.os }}-golang${{ inputs.cache-key-suffix }}-${{ hashFiles('src/go.sum') }}
- name: Module Download and Test Compilation, for future caching
working-directory: src
if: steps.cache.outputs.cache-hit != 'true'
# cover all the bases, just to be make sure we loaded everything we'll use
run: |
go mod download -v
go build -o compile
go test -v -c -o compile_test
shell: bash

View File

@ -33,12 +33,10 @@ jobs:
working-directory: src working-directory: src
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# single setup and sum cache handling here.
# the results will cascade onto both testing and linting.
- name: Setup Golang with cache - name: Setup Golang with cache
if: needs.precheck.outputs.fileschanged == 'true' if: needs.precheck.outputs.fileschanged == 'true'
uses: magnetikonline/action-golang-cache@v3 uses: ./.github/actions/go-setup-cache
with: with:
go-version-file: src/go.mod go-version-file: src/go.mod