]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
ci: use GitHub Actions for mac testing
authorTomas Krizek <tomas.krizek@nic.cz>
Wed, 25 Nov 2020 12:24:44 +0000 (13:24 +0100)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 25 Nov 2020 17:21:32 +0000 (18:21 +0100)
.gitlab-ci.yml
ci/gh_actions.py [new file with mode: 0755]
ci/travis.py [deleted file]

index c2a243f5c7b00e4c8aab78c6dd0f7048f9d024f9..6543b7978d9036a44777f4b1fa892eaca78f358e 100644 (file)
@@ -100,15 +100,13 @@ build-asan:
       # TODO skip_asan: all three of these disappear locally when using gcc 9.1 (except some leaks)
     - ASAN_OPTIONS=detect_leaks=0 ${MESON_TEST} --suite unit --suite config --no-suite skip_asan --no-suite snowflake
 
-build:darwin:
+build:macOS:
   <<: *nodep
   stage: build
   when: delayed
-  start_in: 20 minutes  # give the build in Travis CI time to finish
-    # ^^ Travis takes around 20m recently and the CI script waits for 15m,
-    #    and it gets ran a bit later due to the previous phase(s).
+  start_in: 1 minutes  # allow some time for mirrorring, job creation
   script:
-    - ci/travis.py ${CI_COMMIT_REF_NAME}
+    - ci/gh_actions.py ${CI_COMMIT_REF_NAME} ${CI_COMMIT_SHA}
 
 docker:
   <<: *nodep
diff --git a/ci/gh_actions.py b/ci/gh_actions.py
new file mode 100755 (executable)
index 0000000..849ffff
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/python3
+# SPDX-License-Identifier: GPL-3.0-or-later
+import json
+import time
+import sys
+
+import requests
+
+
+BRANCH_API_ENDPOINT = "https://api.github.com/repos/CZ-NIC/knot-resolver/actions/runs?branch={branch}"  # noqa
+TIMEOUT = 15*60  # 15 mins max
+POLL_DELAY = 60
+
+
+def exit(msg='', html_url='', code=1):
+    print(msg, file=sys.stderr)
+    print(html_url)
+    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.github.v3+json"})
+    if response.status_code == 404:
+        pass  # not created yet?
+    elif response.status_code == 200:
+        data = json.loads(response.content.decode('utf-8'))
+        try:
+            run = data['workflow_runs'][0]
+            conclusion = run['conclusion']
+            html_url = run['html_url']
+            commit_sha = run['head_sha']
+        except KeyError:
+            pass
+
+        if commit_sha != sys.argv[2]:
+            exit("Fetched invalid GH Action: commit mismatch. Re-run or push again?")
+
+        if conclusion is None:
+            pass
+        if conclusion == "success":
+            exit("SUCCESS!", html_url, code=0)
+        elif isinstance(conclusion, str):
+            # failure, neutral, cancelled, skipped, timed_out, or action_required
+            exit("GitHub Actions Conclusion: {}!".format(conclusion.upper()), html_url)
+    else:
+        exit("API Response Code: {}".format(response.status_code), code=2)
+    time.sleep(POLL_DELAY)
+
+exit("Timed out!")
diff --git a/ci/travis.py b/ci/travis.py
deleted file mode 100755 (executable)
index 0c68582..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/python3
-# SPDX-License-Identifier: GPL-3.0-or-later
-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 = 15*60 # 15 mins max
-POLL_DELAY = 20
-
-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 == "passed":
-            exit("Travis CI Result: PASSED!", code=0)
-        elif state == "created" or state == "started":
-            pass
-        else:
-            exit("Travis CI Result: {}!".format(state.upper()))
-    else:
-        exit("API Response Code: {}".format(response.status_code), code=2)
-    time.sleep(POLL_DELAY)
-
-exit("Timed out!")