[ci] wrong cache key for go modules
Parallel jobs are trying to save cache using commit SHA as a key. This approach in not working. E.g. https://github.com/flant/shell-operator/pull/525/checks — all 3 jobs for this PR start downloading Go modules without cache.
Observed steps:
-
Restore Go modules
Cache not found for input keys: Linux-gomod-8e1baab1250f4cf5ce645ed41c9c4ff10cb431c494ef1f379617ca1bbb0ee8aa, Linux-gomod-
-
Run go mod download
-
Post restore Go modules
-
2 jobs can't save cache Failed to save: Unable to reserve cache with key Linux-gomod-8e1baab1250f4cf5ce645ed41c9c4ff10cb431c494ef1f379617ca1bbb0ee8aa, another job may be creating this cache. More details: Cache already exists. Scope: refs/pull/525/merge, Key: Linux-gomod-8e1baab1250f4cf5ce645ed41c9c4ff10cb431c494ef1f379617ca1bbb0ee8aa, Version: 2a8d0f2be1a88abb057cd9fcea9832bd16e7ab71798dbf93cd890eb9add83cf6
-
Only one job saves the cache Cache Size: ~65 MB (67768951 B) Cache saved successfully Cache saved with key: Linux-gomod-8e1baab1250f4cf5ce645ed41c9c4ff10cb431c494ef1f379617ca1bbb0ee8aa
It is better to have predictable key to use cached modules. E.g., use keys linux-gomod-$BRANCH_NAME and linux-gomod-main. So jobs will always have cache from main branch.