fix 'dirty build' logic

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-14 05:18:13 -07:00
parent 09793249ee
commit fe87679bd6
6 changed files with 49 additions and 16 deletions

2
.gitignore vendored
View File

@ -5,7 +5,7 @@
# the binaries were built, how they were
# built. what version was built, etc
# TODO: find a better way (not via ldflags)
resources/build
resources/build.*
resources/BUILDREF
resources/BUILDDATE

View File

@ -98,8 +98,8 @@ func build(tag string) *bool {
// setup the files that will end up in the binary
epoch := fmt.Sprintf("%d", time.Now().Unix())
shell.Write("./resources/BUILDDATE", epoch)
shell.Write("./resources/BUILDREF", gitref)
shell.Write("./resources/build.DATE", epoch)
shell.Write("./resources/build.REF", gitref)
// rebuild the binary (always remove the old one
shell.Run("rm " + filename)

View File

@ -15,6 +15,23 @@ var filename string
func main() {
shell.Quiet(false)
md5sum := build()
log.Println("\tmd5sum =", md5sum)
if (md5sum == "") {
log.Println("\tBUILD FAILED")
return
}
/*
// upload test
sess := shell.SSH("mirrors.wit.com", 22, "jcarr", "")
shell.Scp(sess, filename, "/tmp/jcarr-testing")
*/
}
func build() string {
user, _ := user.Current()
log.Println("user.HomeDir =", user.HomeDir)
@ -24,8 +41,26 @@ func main() {
// setup the files that will end up in the binary
epoch := fmt.Sprintf("%d", time.Now().Unix())
shell.Write("./resources/BUILDDATE", epoch)
shell.Write("./resources/BUILDREF", gitref)
shell.Write("./resources/build.DATE", epoch)
shell.Write("./resources/build.REF", gitref)
// make a dirty file if this build is dirty
shell.Run("rm ./resources/build.DIRTY")
version := shell.Run("cat ./resources/VERSION")
versionref := shell.Run("git rev-list -1 v" + version)
if (gitref != versionref) {
log.Println("build is DIRTY", gitref, "!=", versionref)
shell.Write("./resources/build.DIRTY", versionref)
}
// Test if there are pending diffs. If so, also mark this as dirty.
diff := shell.Run("git diff HEAD")
if (diff != "") {
log.Println("build is DIRTY -- pending diffs")
shell.Write("./resources/build.DIRTY", "pending diffs")
}
// rebuild the binary (always remove the old one
shell.Run("rm " + filename)
@ -34,16 +69,7 @@ func main() {
md5sum := shell.Md5sum(filename)
log.Println("\tmd5sum =", md5sum)
if (md5sum == "") {
log.Println("\tBUILD FAILED")
return
}
shell.Write("/tmp/build.md5sum", md5sum)
/*
// upload test
sess := shell.SSH("mirrors.wit.com", 22, "jcarr", "")
shell.Scp(sess, filename, "/tmp/jcarr-testing")
*/
return md5sum
}

View File

@ -221,4 +221,10 @@ func parseConfig() {
}
}
config.Dirty = false
dirty, err := packrBox.FindString("build.DIRTY")
if (err == nil) {
log.Println("dirty =", dirty)
config.Dirty = true
}
}

1
resources/tags/v0.6.36 Normal file
View File

@ -0,0 +1 @@
09793249ee459e6d60e9957924a33812728d5738

View File

@ -22,7 +22,7 @@ func upgrade() {
mirrorsBUILDDATE := shell.Chomp(shell.Wget(builddateURL))
epoch := time.Now().Unix()
myBUILDDATE, _ := packrBox.FindString("BUILDDATE")
myBUILDDATE, _ := packrBox.FindString("build.DATE")
myBUILDDATE = shell.Chomp(myBUILDDATE)
myBUILDVERSION, _ := packrBox.FindString("VERSION")
myBUILDVERSION = shell.Chomp(myBUILDVERSION)