cloud-control-panel/build/build.go

76 lines
1.8 KiB
Go

package main
// This should build the control panel correctly on each platform
// Then, upload the binaries to mirrors.wit.com/cloud/control-panel
import "log"
import "fmt"
import "time"
import "os/user"
import "git.wit.com/wit/shell"
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)
filename = shell.Execname("cloud-control-panel") // returns the right name for each OS
gitref := shell.Run("git rev-list -1 HEAD")
// setup the files that will end up in the binary
epoch := fmt.Sprintf("%d", time.Now().Unix())
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)
shell.Run("packr build")
log.Println("build finished")
md5sum := shell.Md5sum(filename)
log.Println("\tmd5sum =", md5sum)
shell.Write("/tmp/build.md5sum", md5sum)
return md5sum
}