aboutsummaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-04-06 18:53:33 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-04-06 18:53:33 +0800
commitc76ad944920300be58446ddd1a50c8d693957774 (patch)
treeec9aed051e82deb3c479ab1b7ab50aa2c07d9efb /internal
parent3d8de95f999de6f52f0c1605eb2913278f1d87d2 (diff)
downloadgo-tangerine-c76ad944920300be58446ddd1a50c8d693957774.tar
go-tangerine-c76ad944920300be58446ddd1a50c8d693957774.tar.gz
go-tangerine-c76ad944920300be58446ddd1a50c8d693957774.tar.bz2
go-tangerine-c76ad944920300be58446ddd1a50c8d693957774.tar.lz
go-tangerine-c76ad944920300be58446ddd1a50c8d693957774.tar.xz
go-tangerine-c76ad944920300be58446ddd1a50c8d693957774.tar.zst
go-tangerine-c76ad944920300be58446ddd1a50c8d693957774.zip
.travis, build: autodelete old unstable archives (#13867)
This commit adds a build step to travis to auto-delete unstable archives older than 14 days (our regular release schedule) from Azure via ci.go purge. The commit also pulls in the latest Azure storage code, also switching over from the old import path (github.com/Azure/azure-sdk-for-go) to the new split one (github.com/Azure/azure-storage-go).
Diffstat (limited to 'internal')
-rw-r--r--internal/build/azure.go50
-rw-r--r--internal/build/env.go7
2 files changed, 55 insertions, 2 deletions
diff --git a/internal/build/azure.go b/internal/build/azure.go
index 32f535558..2081a9a0b 100644
--- a/internal/build/azure.go
+++ b/internal/build/azure.go
@@ -20,7 +20,7 @@ import (
"fmt"
"os"
- "github.com/Azure/azure-sdk-for-go/storage"
+ storage "github.com/Azure/azure-storage-go"
)
// AzureBlobstoreConfig is an authentication and configuration struct containing
@@ -42,7 +42,6 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
fmt.Printf("would upload %q to %s/%s/%s\n", path, config.Account, config.Container, name)
return nil
}
-
// Create an authenticated client against the Azure cloud
rawClient, err := storage.NewBasicClient(config.Account, config.Token)
if err != nil {
@@ -63,3 +62,50 @@ func AzureBlobstoreUpload(path string, name string, config AzureBlobstoreConfig)
}
return client.CreateBlockBlobFromReader(config.Container, name, uint64(info.Size()), in, nil)
}
+
+// AzureBlobstoreList lists all the files contained within an azure blobstore.
+func AzureBlobstoreList(config AzureBlobstoreConfig) ([]storage.Blob, error) {
+ // Create an authenticated client against the Azure cloud
+ rawClient, err := storage.NewBasicClient(config.Account, config.Token)
+ if err != nil {
+ return nil, err
+ }
+ client := rawClient.GetBlobService()
+
+ // List all the blobs from the container and return them
+ container := client.GetContainerReference(config.Container)
+
+ blobs, err := container.ListBlobs(storage.ListBlobsParameters{
+ MaxResults: 1024 * 1024 * 1024, // Yes, fetch all of them
+ Timeout: 3600, // Yes, wait for all of them
+ })
+ if err != nil {
+ return nil, err
+ }
+ return blobs.Blobs, nil
+}
+
+// AzureBlobstoreDelete iterates over a list of files to delete and removes them
+// from the blobstore.
+func AzureBlobstoreDelete(config AzureBlobstoreConfig, blobs []storage.Blob) error {
+ if *DryRunFlag {
+ for _, blob := range blobs {
+ fmt.Printf("would delete %s (%s) from %s/%s\n", blob.Name, blob.Properties.LastModified, config.Account, config.Container)
+ }
+ return nil
+ }
+ // Create an authenticated client against the Azure cloud
+ rawClient, err := storage.NewBasicClient(config.Account, config.Token)
+ if err != nil {
+ return err
+ }
+ client := rawClient.GetBlobService()
+
+ // Iterate over the blobs and delete them
+ for _, blob := range blobs {
+ if err := client.DeleteBlob(config.Container, blob.Name, nil); err != nil {
+ return err
+ }
+ }
+ return nil
+}
diff --git a/internal/build/env.go b/internal/build/env.go
index 15b2dfe41..c47681ebe 100644
--- a/internal/build/env.go
+++ b/internal/build/env.go
@@ -30,6 +30,7 @@ var (
GitTagFlag = flag.String("git-tag", "", `Overrides git tag being built`)
BuildnumFlag = flag.String("buildnum", "", `Overrides CI build number`)
PullRequestFlag = flag.Bool("pull-request", false, `Overrides pull request status of the build`)
+ CronJobFlag = flag.Bool("cron-job", false, `Overrides cron job status of the build`)
)
// Environment contains metadata provided by the build environment.
@@ -39,6 +40,7 @@ type Environment struct {
Commit, Branch, Tag string // Git info
Buildnum string
IsPullRequest bool
+ IsCronJob bool
}
func (env Environment) String() string {
@@ -59,6 +61,7 @@ func Env() Environment {
Tag: os.Getenv("TRAVIS_TAG"),
Buildnum: os.Getenv("TRAVIS_BUILD_NUMBER"),
IsPullRequest: os.Getenv("TRAVIS_PULL_REQUEST") != "false",
+ IsCronJob: os.Getenv("TRAVIS_EVENT_TYPE") == "cron",
}
case os.Getenv("CI") == "True" && os.Getenv("APPVEYOR") == "True":
return Environment{
@@ -69,6 +72,7 @@ func Env() Environment {
Tag: os.Getenv("APPVEYOR_REPO_TAG_NAME"),
Buildnum: os.Getenv("APPVEYOR_BUILD_NUMBER"),
IsPullRequest: os.Getenv("APPVEYOR_PULL_REQUEST_NUMBER") != "",
+ IsCronJob: os.Getenv("APPVEYOR_SCHEDULED_BUILD") == "True",
}
default:
return LocalEnv()
@@ -118,5 +122,8 @@ func applyEnvFlags(env Environment) Environment {
if *PullRequestFlag {
env.IsPullRequest = true
}
+ if *CronJobFlag {
+ env.IsCronJob = true
+ }
return env
}