-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for build and linter cache and with-cache command (#90)
This PR aims to add a bunch more support for caching: - Support `build` cache, `golangci-lint` cache. - Rename `save-cache` and `load-cache` to `save-mod-cache` and `load-mod-cache`. - Add new command `with-cache` that wraps up some steps with all the caches.
- Loading branch information
1 parent
ee89c8a
commit f065dad
Showing
12 changed files
with
169 additions
and
56 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
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,10 @@ | ||
description: "Load cached Go build cache." | ||
parameters: | ||
key: | ||
description: "User-configurable component for cache key. Useful for avoiding collisions in complex workflows." | ||
type: string | ||
default: "" | ||
steps: | ||
- restore_cache: | ||
keys: | ||
- v1-<< parameters.key >>-go-build-{{ .Environment.CIRCLE_JOB }}-{{ arch }}-{{ checksum "go.sum" }}-{{ epoch | round "72h" }} |
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
description: "Load cached Go build cache." | ||
parameters: | ||
key: | ||
description: "User-configurable component for cache key. Useful for avoiding collisions in complex workflows." | ||
type: string | ||
default: "" | ||
steps: | ||
- restore_cache: | ||
keys: | ||
- v1-<< parameters.key >>-golangci-lint-{{ .Environment.CIRCLE_JOB }}-{{ arch }}-{{ checksum "go.sum" }}-{{ epoch | round "72h" }} |
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,10 @@ | ||
description: "Load cached Go modules." | ||
parameters: | ||
key: | ||
description: "User-configurable component for cache key. Useful for avoiding collisions in complex workflows." | ||
type: string | ||
default: "" | ||
steps: | ||
- restore_cache: | ||
keys: | ||
- v1-<< parameters.key >>-go-mod-{{ arch }}-{{ checksum "go.sum" }} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
description: "Download and cache Go modules" | ||
steps: | ||
- load-cache | ||
- load-mod-cache | ||
- mod-download | ||
- save-cache | ||
- save-mod-cache |
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,15 @@ | ||
description: "Save Go build cache." | ||
parameters: | ||
key: | ||
description: "User-configurable component for cache key. Useful for avoiding collisions in complex workflows." | ||
type: string | ||
default: "" | ||
path: | ||
description: "Path to cache." | ||
type: string | ||
default: "/home/circleci/.cache/go-build" | ||
steps: | ||
- save_cache: | ||
key: v1-<< parameters.key >>-go-build-{{ .Environment.CIRCLE_JOB }}-{{ arch }}-{{ checksum "go.sum" }}-{{ epoch | round "72h" }} | ||
paths: | ||
- << parameters.path >> |
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,16 @@ | ||
description: "Save golangci-lint cache." | ||
parameters: | ||
key: | ||
description: "User-configurable component for cache key. Useful for avoiding collisions in complex workflows." | ||
type: string | ||
default: "" | ||
path: | ||
description: "Path to cache." | ||
type: string | ||
default: "/home/circleci/.cache/golangci-lint" | ||
steps: | ||
- save_cache: | ||
key: v1-<< parameters.key >>-golangci-lint-{{ .Environment.CIRCLE_JOB }}-{{ arch }}-{{ checksum "go.sum" }}-{{ epoch | round "72h" }} | ||
paths: | ||
- << parameters.path >> | ||
|
6 changes: 3 additions & 3 deletions
6
src/commands/save-cache.yml → src/commands/save-mod-cache.yml
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 |
---|---|---|
@@ -1,16 +1,16 @@ | ||
description: "Save Go modules to cache." | ||
parameters: | ||
key: | ||
description: "The cache key to use. The key is immutable." | ||
description: "User-configurable component for cache key. Useful for avoiding collisions in complex workflows." | ||
type: string | ||
default: "go-mod" | ||
default: "" | ||
path: | ||
description: "Path to cache." | ||
type: string | ||
# /home/circleci/go is the GOPATH in the cimg/go Docker image | ||
default: "/home/circleci/go/pkg/mod" | ||
steps: | ||
- save_cache: | ||
key: << parameters.key >>-{{ arch }}-{{ checksum "go.sum" }} | ||
key: v1-<< parameters.key >>-go-mod-{{ arch }}-{{ checksum "go.sum" }} | ||
paths: | ||
- << parameters.path >> |
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,56 @@ | ||
description: | | ||
Runs the given steps | ||
parameters: | ||
steps: | ||
description: "The steps to run with caching." | ||
type: steps | ||
key: | ||
description: "User-configurable component for cache key. Useful for avoiding collisions in complex workflows." | ||
type: string | ||
default: "" | ||
build: | ||
description: "Whether to use go-build cache." | ||
type: boolean | ||
default: true | ||
mod: | ||
description: | | ||
Whether to use go module cache. If most of your dependencies are public, it is faster to use the public | ||
Go module proxy, so this defaults to `false`. | ||
type: boolean | ||
default: false | ||
golangci-lint: | ||
description: "Whether to use golangci-lint cache. Useful only in steps with linting, so defaults to false." | ||
type: boolean | ||
default: false | ||
steps: | ||
- when: | ||
condition: << parameters.build >> | ||
steps: | ||
- load-build-cache: | ||
key: << parameters.key >> | ||
- when: | ||
condition: << parameters.mod >> | ||
steps: | ||
- load-mod-cache: | ||
key: << parameters.key >> | ||
- when: | ||
condition: << parameters.golangci-lint >> | ||
steps: | ||
- load-golangci-lint-cache: | ||
key: << parameters.key >> | ||
- steps: << parameters.steps >> | ||
- when: | ||
condition: << parameters.build >> | ||
steps: | ||
- save-build-cache: | ||
key: << parameters.key >> | ||
- when: | ||
condition: << parameters.mod >> | ||
steps: | ||
- save-mod-cache: | ||
key: << parameters.key >> | ||
- when: | ||
condition: << parameters.golangci-lint >> | ||
steps: | ||
- save-golangci-lint-cache: | ||
key: << parameters.key >> |
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