0

I wrote a simple bash script to go build then run the binary

go build -o my-binary
./my-binary

Is there any way to find that my binary already the latest build (no code change)?

iman tung
  • 63
  • 2
  • If you use `go install` to build the binary, then you can run `go install -n` to determine if the installed binary is up-to-date. No output means that binary is up-to-date. If your goal update the binary before running it, then run `go install`. – Charlie Tumahai Jun 23 '19 at 17:08
  • 1
    `go build` only does the minimal amount of work necessary, so even a large project will only take a second to run a no-op build. – JimB Jun 23 '19 at 20:07
  • Although it doesn't make sense because as the others said go build caches outputs anyway, you can change your scripts to find changed (`git diff-index --quiet HEAD --`) files and if there aren’t any skip the build. – georgeok Jun 23 '19 at 22:54
  • Maybe a Makefile should be suitable for this task rather than a plain bash script. – delvatt Aug 18 '22 at 12:29

0 Answers0