From fe87679bd69d0ac6622ae551736d99a52771c3dd Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 14 Jun 2019 05:18:13 -0700 Subject: [PATCH] fix 'dirty build' logic Signed-off-by: Jeff Carr --- .gitignore | 2 +- autobuild/autobuild.go | 4 ++-- build/build.go | 50 ++++++++++++++++++++++++++++++++---------- config.go | 6 +++++ resources/tags/v0.6.36 | 1 + upgrade.go | 2 +- 6 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 resources/tags/v0.6.36 diff --git a/.gitignore b/.gitignore index 1a61243..5d746de 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/autobuild/autobuild.go b/autobuild/autobuild.go index a515e1c..a935dfe 100644 --- a/autobuild/autobuild.go +++ b/autobuild/autobuild.go @@ -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) diff --git a/build/build.go b/build/build.go index 2d50bda..92253de 100644 --- a/build/build.go +++ b/build/build.go @@ -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 } diff --git a/config.go b/config.go index 03b41f0..5dca597 100644 --- a/config.go +++ b/config.go @@ -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 + } } diff --git a/resources/tags/v0.6.36 b/resources/tags/v0.6.36 new file mode 100644 index 0000000..f2dd1c8 --- /dev/null +++ b/resources/tags/v0.6.36 @@ -0,0 +1 @@ +09793249ee459e6d60e9957924a33812728d5738 diff --git a/upgrade.go b/upgrade.go index d923518..d35e57f 100644 --- a/upgrade.go +++ b/upgrade.go @@ -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)