summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-10-20 15:33:20 +0200
committerPeter Wu <peter@lekensteyn.nl>2018-10-20 15:37:52 +0200
commit61fa7d1fd6cb97430df28610e8c10d4d6cd59d61 (patch)
treedfb3a00272c473473f78ed82432895dd1bf1206c
parent63c0ea81f672f883568eb54f6f0c788a2097e50d (diff)
downloadwireshark-notes-61fa7d1fd6cb97430df28610e8c10d4d6cd59d61.tar.gz
appveyor-clear.py: script to delete old builds
Large artifacts may be accumulated and at the moment hits the 50GB limit. Deleting them one by one is cumbersome, so here is a way to automate it. Motivation: https://code.wireshark.org/review/30268
-rwxr-xr-xappveyor-clear.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/appveyor-clear.py b/appveyor-clear.py
new file mode 100755
index 0000000..a247eac
--- /dev/null
+++ b/appveyor-clear.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+"""
+Clears the build history, removing all but the last 100 builds. Usage:
+
+Go to https://ci.appveyor.com/api-keys for an account-specific (v1) token. Then:
+
+ export APPVEYOR_TOKEN=...
+ ./appveyor-clear.py Lekensteyn/wireshark
+
+Other options exist, use ./appveyor-clear.py --help to see them all.
+"""
+
+import argparse
+import os
+import sys
+import requests
+
+parser = argparse.ArgumentParser()
+parser.add_argument("--token", default=os.environ.get("APPVEYOR_TOKEN"),
+ help="v1 API token (defaults to APPVEYOR_TOKEN environment variable). See "
+ "https://ci.appveyor.com/api-keys")
+parser.add_argument("--max-builds", type=int, default=100,
+ help="Maximum number of recent builds to keep")
+parser.add_argument("--dry-run", action="store_true",
+ help="Do not actually delete builds")
+parser.add_argument("project",
+ help="Account name plus project slug (e.g. Lekensteyn/wireshark)")
+
+base = "https://ci.appveyor.com/api"
+history_url = "%s/projects/{project}/history?recordsNumber=1000" % base
+build_url = "%s/builds/{buildId}" % base
+
+args = parser.parse_args()
+if not args.token:
+ parser.error("Missing APPVEYOR_TOKEN environment variable")
+if args.token.startswith("v2."):
+ parser.error("Only a v1 token is supported")
+
+headers = {
+ "Authorization": "Bearer %s" % args.token,
+}
+# Retrieve builds for the project
+r = requests.get(history_url.format(project=args.project), headers=headers)
+r.raise_for_status() # Does the project exist?
+builds = r.json()["builds"]
+count = len(builds)
+builds = builds[args.max_builds:]
+if not builds:
+ print("Found %d builds, nothing to remove" % count)
+else:
+ print("About to remove %d builds" % len(builds))
+ for build in builds:
+ print("Removing %d %s" % (build["buildId"], build["message"]))
+ if not args.dry_run:
+ r = requests.delete(build_url.format(buildId=build["buildId"]),
+ headers=headers)
+ r.raise_for_status() # If this fails, perhaps token is invalid.