Make build/test environment cache friendly

go build and go test caches rely on a consistent environment:

  • file modification, permissions being identical
  • any file or environment variable that is used as part of a file needs to have consistent content
  • flags passed to the go binary need to be identical

We're currently invalidating these caches because:

  • After clone, git doesn't update the files to use the last modification date. We can fix this with a simple script.
  • For environment variables, we already have a strict allowlist, and this doesn't change often.
  • Some tests pull in files that have modified dates (for example, the "test repo" we use is checked out, added to an artifact - whilst artifact extracting keeps the correct date, git in the first instance did not again).
  • We pass unique LDFLAGS for each revision, invalidating the cache.

make, when checking to see if a target already exists, builds if the source input is newer than the existing target. If we don't modify the file dates after a git checkout, this will always be the case, because artifact extracting restores time.