ci: use cache properly
The cache has not been used properly due to a few of reasons:
- the
$GOPATHvariable is not being read properly by the job as the runner has no knowledge of this variable value. This turns into the cache upload stage to fail because/pkg/mod/does not exist. - The cache files need to be relative to the working directory!
- The default cache policy is
pull-push, which first downloads the cache and then uploads it again. - Most jobs do not depend on any other jobs ( i.e.
needs: []), especially the tests, when this is combined with thepull-pushcache policy, it means every job needs to work inefficiently by downloading an empty cache, downloading all the modules it needs and then failing to upload the cache due to reason 1. - The cache key is the branch name, this is fine but we can be more efficient by using
filesas keys.
To fix this:
- We define the default cache policy to be
pull - Change the cache key to use file names, such as
go.mod&go.sumand a prefix by$GO_VERSION - We add a new job
modules:downloadand set the cache policy topush - We make all tests depend on the
modules:downloadjob. - Each job downloads the cache for its own go version
You can see from the job logs that we no longer need to download the modules
Edited by Jaime Martinez

