]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
ci: add OSX test via Travis CI API
authorTomas Krizek <tomas.krizek@nic.cz>
Wed, 7 Nov 2018 13:19:17 +0000 (14:19 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 14 Nov 2018 13:34:17 +0000 (14:34 +0100)
.gitlab-ci.yml
ci/travis.py [new file with mode: 0755]

index 77392ce131c68e9480e232939b0feb306062beaf..989efba021f1aac031f6a3d76e803321b1bf1ee2 100644 (file)
@@ -223,6 +223,17 @@ installcheck:valgrind:linux:amd64:
     - linux
     - amd64
 
+osx:build:
+  stage: test
+  except:
+    - master
+  script:
+    - ci/travis.py ${CI_COMMIT_REF_NAME}
+  dependencies: []
+  tags:
+    - docker
+
+
 # temporarily disabled - we need to fix issues first
 #deckard:linux:amd64:valgrind:
 #  stage: test
diff --git a/ci/travis.py b/ci/travis.py
new file mode 100755 (executable)
index 0000000..f0909ae
--- /dev/null
@@ -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!")