-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: cache go module downloads and other build and test artifacts (#3727
- Loading branch information
1 parent
8f9a595
commit 13ea996
Showing
5 changed files
with
76 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: 'Setup the Go environment' | ||
description: 'Installs go and restores/saves the build/module cache' | ||
inputs: | ||
go-version: | ||
required: true | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ${{ inputs.go-version }} | ||
stable: ${{ !(contains(inputs.go-version, 'beta') || contains(inputs.go-version, 'rc')) }} | ||
|
||
# Restore original modification time of files based on the date of the most | ||
# recent commit that modified them as mtimes affect the Go test cache. | ||
- name: Restore modification time of checkout files | ||
shell: bash | ||
run: | | ||
# Set a base, fixed modification time of all directories. | ||
# git-restore-mtime doesn't set the mtime of of all directories. | ||
# (see https://github.com/MestreLion/git-tools/issues/47 for details) | ||
touch -m -t '201509301646' $(find . -type d -not -path '.git/*') | ||
# Restore original modification time from git. git clone sets the | ||
# modification time to the current time, but Go tests that access fixtures | ||
# get invalidated if their modification times change. | ||
sudo apt-get install -y git-restore-mtime | ||
git restore-mtime | ||
# The PREFIX must uniquely identify the specific instance of a job executing. | ||
- shell: bash | ||
run: echo 'PREFIX=${{ github.workflow }}-${{ github.job }}-${{ runner.os }}-${{ inputs.go-version }}-matrix(${{ join(matrix.*,'|') }})' >> $GITHUB_ENV | ||
|
||
# Cache the Go Modules downloaded during the job. | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ env.PREFIX }}-go-mod-${{ hashFiles('**/go.sum') }} | ||
restore-keys: ${{ env.PREFIX }}-go-mod | ||
|
||
# Cache any build and test artifacts during the job, which will speed up | ||
# rebuilds and cause test runs to skip tests that have no reason to rerun. | ||
# Don't run this for protected branches like master/main. | ||
- uses: actions/cache@v2 | ||
if: ${{ github.ref_protected || github.ref != 'master' || github.ref != 'main' }} | ||
with: | ||
path: ~/.cache/go-build | ||
key: ${{ env.PREFIX }}-go-build-${{ github.ref }}-${{ hashFiles('**', '!.git') }} | ||
restore-keys: | | ||
${{ env.PREFIX }}-go-build-${{ github.ref }} | ||
${{ env.PREFIX }}-go-build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters