summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2020-03-04 11:53:01 +0200
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2020-03-20 13:59:23 +0200
commitef19a338666bbfcd2cdb218efd14e66754074d67 (patch)
tree55aa2d787447189b1bd2bcae7b38994dbb88e6b7
parent8bf841a9513c28057fcedb0dab032bb00016b90c (diff)
downloadqtlocation-mapboxgl-ef19a338666bbfcd2cdb218efd14e66754074d67.tar.gz
[build] Trigger the downstream CI and get the status back
Allows triggering a pipeline at any other repository passing parameters.
-rw-r--r--circle.yml20
-rwxr-xr-xscripts/ci-circleci-start-pipeline.py71
2 files changed, 91 insertions, 0 deletions
diff --git a/circle.yml b/circle.yml
index deebba1aa1..0ce326d64d 100644
--- a/circle.yml
+++ b/circle.yml
@@ -33,6 +33,15 @@ workflows:
- linux-gcc8-release
- macos-xcode11-release
- ios-render-test-runner
+ - trigger-pipeline:
+ requires:
+ - android-render-test-runner
+ - ios-render-test-runner
+ - linux-clang8-release
+ - linux-gcc8-release
+ - macos-xcode11-release
+ name: mapboxci
+ slug: mapbox/mapbox-gl-native-internal
- build-template:
name: android-armeabi-v7a-release
executor_name: ubuntu-disco
@@ -631,6 +640,17 @@ jobs:
metricsResult=$(gsutil ls -d gs://test-lab-186672a0qp5bq-ycr70axads3nc/render-test-app-${CIRCLE_BUILD_NUM}/*/*/sdcard/baselines/*) || true
gsutil -m cp -r $metricsResult metrics/android-render-test-runner/ || true
- save
+ trigger-pipeline:
+ executor: ubuntu-disco
+ parameters:
+ slug:
+ type: string
+ steps:
+ - checkout
+ - run:
+ name: Trigger Pipeline
+ command: |
+ scripts/ci-circleci-start-pipeline.py --target-slug << parameters.slug >>
sanity-checks:
executor: ubuntu-disco
steps:
diff --git a/scripts/ci-circleci-start-pipeline.py b/scripts/ci-circleci-start-pipeline.py
new file mode 100755
index 0000000000..a7aa0f49ad
--- /dev/null
+++ b/scripts/ci-circleci-start-pipeline.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python3
+
+# Implements https://circleci.com/docs/api/v2/#trigger-a-new-pipeline
+
+import argparse
+import os
+import requests
+import sys
+
+
+def TriggerPiperline(slug, token, branch, params):
+ url = "https://circleci.com/api/v2/project/github/%s/pipeline" % (slug)
+
+ headers = {
+ "Content-Type": "application/json",
+ "Accept": "application/json",
+ }
+
+ data = {
+ "parameters": params
+ }
+
+ if branch:
+ data["branch"] = branch
+
+ r = requests.post(url, auth=(token, ""), headers=headers, json=data)
+
+ if r.status_code != 201:
+ print("Error triggering the CircleCI: %s." % r.json()["message"])
+ sys.exit(1)
+
+
+def Main():
+ token = os.getenv("CIRCLE_API_TOKEN")
+ hash = os.getenv("CIRCLE_SHA1", default="1234567890")
+ username = os.getenv("CIRCLE_PROJECT_USERNAME", default="username")
+ project = os.getenv("CIRCLE_PROJECT_REPONAME", default="repository")
+
+ parser = argparse.ArgumentParser(
+ description="Creates CircleCI jobs and waits for the result.")
+
+ parser.add_argument("--token", default=token,
+ help="CircleCI token, otherwise environment CIRCLE_API_TOKEN.")
+ parser.add_argument("--origin-slug", default="mapbox/mapbox-gl-native",
+ help="Origin repository, otherwise CIRCLE_PROJECT_USERNAME/CIRCLE_PROJECT_REPONAME.")
+ parser.add_argument("--target-slug", default="".join((username, '/', project)),
+ help="Repository to trigger the pipeline, example: mapbox/mapbox-gl-native-internal.")
+ parser.add_argument("--hash", default=hash,
+ help="Commit git hash that triggered the pipeline, otherwise environment CIRCLE_SHA1.")
+ parser.add_argument("--branch",
+ help="Build a specific branch, otherwise it will build the default branch.")
+
+ args = parser.parse_args()
+
+ if not args.token:
+ print("CircleCI token not set. Use --token or set CIRCLE_API_TOKEN.")
+ sys.exit(1)
+
+ params = {
+ "mapbox_upstream": True,
+ "mapbox_slug": args.origin_slug,
+ "mapbox_hash": args.hash
+ }
+
+ TriggerPiperline(args.target_slug, args.token, args.branch, params)
+
+ return 0
+
+
+if __name__ == "__main__":
+ Main()