aboutsummaryrefslogtreecommitdiffstats
path: root/build/ci.go
diff options
context:
space:
mode:
Diffstat (limited to 'build/ci.go')
-rw-r--r--build/ci.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/build/ci.go b/build/ci.go
index 9a6f1e196..cb89e914b 100644
--- a/build/ci.go
+++ b/build/ci.go
@@ -32,6 +32,7 @@ Available commands are:
aar [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an Android archive
xcode [ -local ] [ -sign key-id ] [-deploy repo] [ -upload dest ] -- creates an iOS XCode framework
xgo [ -alltools ] [ options ] -- cross builds according to options
+ purge [ -store blobstore ] [ -days threshold ] -- purges old archives from the blobstore
For all commands, -n prevents execution of external programs (dry run mode).
@@ -146,6 +147,8 @@ func main() {
doXCodeFramework(os.Args[2:])
case "xgo":
doXgo(os.Args[2:])
+ case "purge":
+ doPurge(os.Args[2:])
default:
log.Fatal("unknown command ", os.Args[1])
}
@@ -427,6 +430,10 @@ func maybeSkipArchive(env build.Environment) {
log.Printf("skipping because this is a PR build")
os.Exit(0)
}
+ if env.IsCronJob {
+ log.Printf("skipping because this is a cron job")
+ os.Exit(0)
+ }
if env.Branch != "master" && !strings.HasPrefix(env.Tag, "v1.") {
log.Printf("skipping because branch %q, tag %q is not on the whitelist", env.Branch, env.Tag)
os.Exit(0)
@@ -952,3 +959,62 @@ func xgoTool(args []string) *exec.Cmd {
}
return cmd
}
+
+// Binary distribution cleanups
+
+func doPurge(cmdline []string) {
+ var (
+ store = flag.String("store", "", `Destination from where to purge archives (usually "gethstore/builds")`)
+ limit = flag.Int("days", 30, `Age threshold above which to delete unstalbe archives`)
+ )
+ flag.CommandLine.Parse(cmdline)
+
+ if env := build.Env(); !env.IsCronJob {
+ log.Printf("skipping because not a cron job")
+ os.Exit(0)
+ }
+ // Create the azure authentication and list the current archives
+ auth := build.AzureBlobstoreConfig{
+ Account: strings.Split(*store, "/")[0],
+ Token: os.Getenv("AZURE_BLOBSTORE_TOKEN"),
+ Container: strings.SplitN(*store, "/", 2)[1],
+ }
+ blobs, err := build.AzureBlobstoreList(auth)
+ if err != nil {
+ log.Fatal(err)
+ }
+ // Iterate over the blobs, collect and sort all unstable builds
+ for i := 0; i < len(blobs); i++ {
+ if !strings.Contains(blobs[i].Name, "unstable") {
+ blobs = append(blobs[:i], blobs[i+1:]...)
+ i--
+ }
+ }
+ for i := 0; i < len(blobs); i++ {
+ for j := i + 1; j < len(blobs); j++ {
+ iTime, err := time.Parse(time.RFC1123, blobs[i].Properties.LastModified)
+ if err != nil {
+ log.Fatal(err)
+ }
+ jTime, err := time.Parse(time.RFC1123, blobs[j].Properties.LastModified)
+ if err != nil {
+ log.Fatal(err)
+ }
+ if iTime.After(jTime) {
+ blobs[i], blobs[j] = blobs[j], blobs[i]
+ }
+ }
+ }
+ // Filter out all archives more recent that the given threshold
+ for i, blob := range blobs {
+ timestamp, _ := time.Parse(time.RFC1123, blob.Properties.LastModified)
+ if time.Since(timestamp) < time.Duration(*limit)*24*time.Hour {
+ blobs = blobs[:i]
+ break
+ }
+ }
+ // Delete all marked as such and return
+ if err := build.AzureBlobstoreDelete(auth, blobs); err != nil {
+ log.Fatal(err)
+ }
+}