[gnome-build-meta/abderrahim/update-refs-script: 2/2] ci script




commit 56466f5c6a36beeeaa3d1cb636e8eb5fe85d075c
Author: Jordan Petridis <jordan centricular com>
Date:   Tue Oct 4 16:44:26 2022 +0200

    ci script

 .gitlab-ci.yml          | 57 ++++++++++++++++++++++++++++++++++++++++++++++++-
 utils/check-open-mrs.py | 18 ++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7293194a8..2985b2d79 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -14,7 +14,7 @@ variables:
 
   # Docker Images
   DOCKER_REGISTRY: "registry.gitlab.com/freedesktop-sdk/infrastructure/freedesktop-sdk-docker-images"
-  DOCKER_IMAGE_ID: "3bee7d7876bc776cdf8379ab0713fcd405ac5002"
+  DOCKER_IMAGE_ID: "a470cd0ecc1a005e9456b98845455ed1bcdc6b7b"
 
 stages:
 - track
@@ -529,6 +529,61 @@ test-pinephone-pro-aarch64:
   - aarch64
   - gnome-build-meta
 
+update_refs:
+  stage: 'track'
+  tags:
+  - x86_64
+  - gnome-build-meta
+  # FIXME:
+  # Weird bst tracking the same repo issue
+  retry: 2
+  rules:
+    # FIXME: filter out the rest of the jobs on this pipeline
+    - if: $UPDATE_REFS == "yes" && $CI_PIPELINE_SOURCE == "schedule"
+    # FIXME: remove me
+    - if: $CI_COMMIT_REF_NAME == "abderrahim/update-refs-script"
+  script:
+    # Setup ssh
+    - eval $(ssh-agent -s)
+    - echo "$SSH_PRIVATE_KEY" | ssh-add -
+
+    - mkdir -p ~/.ssh
+    - chmod 700 ~/.ssh
+
+    # FIXME: use static known keys with a var
+    # https://gitlab.com/gitlab-examples/ssh-private-key/-/blob/master/.gitlab-ci.yml#L38
+    - ssh-keyscan gitlab.gnome.org >> ~/.ssh/known_hosts
+    - chmod 644 ~/.ssh/known_hosts
+
+    - ssh -Tv git gitlab gnome org
+
+    - git config --global user.email "sysadmin gnome org"
+    - git config --global user.name "gnomebot"
+
+    # When tracking the same repo from multiple elements, gtk3 & gtk4,
+    # bst can bug out and one of the tracks will fail. Only run 1 fetch
+    # at a time to avoid this.
+    - export BST="$BST --fetchers=1"
+
+    # - OPEN_MRS=$(gitlab project-merge-request list --project-id $CI_PROJECT_ID --author-id 540 --state 
opened)
+    - OPEN_MRS=$(gitlab project-merge-request list --project-id $CI_PROJECT_ID --author-id 274 --state 
opened)
+    # If the bot has already opened a merge request, abort
+    - |
+      if [ ! -n "$OPEN_MRS" ]; then
+        exit 1
+      fi
+
+    # - python3 utils/check-open-mrs.py
+    - python3 utils/update-refs.py --switch-branch
+
+    - git show
+
+    - git remote set-url --push origin git gitlab gnome org:GNOME/gnome-build-meta.git
+
+    # - git push -o merge_request.create -o merge_request.assign=44433 -o merge_request.remove_source_branch 
origin HEAD
+  after_script:
+    - rm ssh.key
+
 
 pages:
   stage: 'reports'
diff --git a/utils/check-open-mrs.py b/utils/check-open-mrs.py
new file mode 100644
index 000000000..ca19a279f
--- /dev/null
+++ b/utils/check-open-mrs.py
@@ -0,0 +1,18 @@
+#! /usr/bin/env python3
+
+import requests
+import os
+
+def check_for_existing_mr():
+  headers = {'JOB_TOKEN': os.environ["CI_JOB_TOKEN"] }
+
+  # FIXME:
+  url = f"https://gitlab.gnome.org/api/v4/projects/456/merge_requests?author_username=bertob&state=opened";
+
+  resp = requests.get(url, headers=headers)
+  print(resp.json())
+  resp.raise_for_status()
+
+  if resp.json():
+    print("There's an existing MR already. Exiting!")
+    exit(1)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]