summaryrefslogtreecommitdiffstats
path: root/ci/travis.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:55:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:55:53 +0000
commit3d0386f27ca66379acf50199e1d1298386eeeeb8 (patch)
treef87bd4a126b3a843858eb447e8fd5893c3ee3882 /ci/travis.py
parentInitial commit. (diff)
downloadknot-resolver-3d0386f27ca66379acf50199e1d1298386eeeeb8.tar.xz
knot-resolver-3d0386f27ca66379acf50199e1d1298386eeeeb8.zip
Adding upstream version 3.2.1.upstream/3.2.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ci/travis.py')
-rwxr-xr-xci/travis.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/ci/travis.py b/ci/travis.py
new file mode 100755
index 0000000..f0909ae
--- /dev/null
+++ b/ci/travis.py
@@ -0,0 +1,47 @@
+#!/usr/bin/python3
+import json
+import time
+import sys
+
+import requests
+
+
+BRANCH_API_ENDPOINT = "https://api.travis-ci.com/repos/CZ-NIC/knot-resolver/branches/{branch}"
+JOB_URL = "https://travis-ci.com/CZ-NIC/knot-resolver/jobs/{job_id}"
+TIMEOUT = 600 # 10 mins max
+POLL_DELAY = 15
+
+job_id = None
+
+
+def exit(msg='', code=1):
+ print(msg, file=sys.stderr)
+ if job_id is not None:
+ print(JOB_URL.format(job_id=job_id))
+ sys.exit(code)
+
+
+end_time = time.time() + TIMEOUT
+while time.time() < end_time:
+ response = requests.get(
+ BRANCH_API_ENDPOINT.format(branch=sys.argv[1]),
+ headers={"Accept": "application/vnd.travis-ci.2.1+json"})
+ if response.status_code == 404:
+ pass # not created yet?
+ elif response.status_code == 200:
+ data = json.loads(response.content.decode('utf-8'))
+ state = data['branch']['state']
+ try:
+ job_id = data['branch']['job_ids'][0]
+ except KeyError:
+ pass
+
+ if state == "errored":
+ exit("Travis CI Result: ERRORED!")
+ elif state == "passed":
+ exit("Travis CI Result: PASSED!", code=0)
+ else:
+ exit("API Response Code: {code}".format(response.status_code), code=2)
+ time.sleep(POLL_DELAY)
+
+exit("Timed out!")