binaryVersion returns a string that uniquely identifies the binary. We prefer to use the VCS info embedded in the build if possible falling back to the MD5 of the binary.
()
| 267 | // We prefer to use the VCS info embedded in the build if possible |
| 268 | // falling back to the MD5 of the binary. |
| 269 | func binaryVersion() (string, error) { |
| 270 | sha, ok := readBuildSHA() |
| 271 | if ok { |
| 272 | return sha, nil |
| 273 | } |
| 274 | |
| 275 | exe, err := os.Executable() |
| 276 | if err != nil { |
| 277 | return "", errtrace.Wrap(err) |
| 278 | } |
| 279 | |
| 280 | contents, err := os.ReadFile(exe) |
| 281 | if err != nil { |
| 282 | return "", errtrace.Wrap(err) |
| 283 | } |
| 284 | |
| 285 | binaryHash := md5.Sum(contents) |
| 286 | return hex.EncodeToString(binaryHash[:]), nil |
| 287 | } |
| 288 | |
| 289 | // readBuildSHA returns the VCS SHA, if it's from an unmodified VCS state. |
| 290 | func readBuildSHA() (_ string, ok bool) { |
no test coverage detected