From 75627ad8dd2e28f535cca76df17f25e7f57edcb1 Mon Sep 17 00:00:00 2001
From: Robert Rosca <robert.rosca@xfel.eu>
Date: Thu, 4 Mar 2021 21:41:52 +0100
Subject: [PATCH] Template entire before script section

---
 .gitlab-ci.yml | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4441873da..a1a869857 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,14 +2,28 @@ stages:
   - check
   - test
 
-checks:
-  stage: check
-  only: [merge_requests]
-  allow_failure: true
+.before_script: &before_script
   before_script:
+    - eval $(ssh-agent -s)
+    - echo "$SSH_PRIVATE_KEY_GITLAB" | tr -d '\r' | ssh-add -
+    #  Our self-hosted runners have persistent home directories, so here we store
+    #  the known_hosts file in the temporary project dir and tell git to use a ssh
+    #  command that uses this hosts file during operations
+    - export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=$CI_PROJECT_DIR/.ssh/known_hosts"
+    - mkdir -p $CI_PROJECT_DIR/.ssh
+    - chmod 700 $CI_PROJECT_DIR/.ssh
+    - ssh-keyscan -p 10022 git.xfel.eu > $CI_PROJECT_DIR/.ssh/known_hosts
+    - ls  $CI_PROJECT_DIR/.ssh
+    - echo $GIT_SSH_COMMAND
     - python3 -m venv .venv
     - source .venv/bin/activate
     - python3 -m pip install --upgrade pip
+
+checks:
+  stage: check
+  only: [merge_requests]
+  allow_failure: true
+  <<: *before_script
   script:
     - export PATH=/home/gitlab-runner/.local/bin:$PATH
     #  We'd like to run the pre-commit hooks only on files that are being
@@ -26,21 +40,7 @@ checks:
 pytest:
   stage: test
   only: [merge_requests]
-  before_script:
-    - eval $(ssh-agent -s)
-    - echo "$SSH_PRIVATE_KEY_GITLAB" | tr -d '\r' | ssh-add -
-    #  Our self-hosted runners have persistent home directories, so here we store
-    #  the known_hosts file in the temporary project dir and tell git to use a ssh
-    #  command that uses this hosts file during operations
-    - export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=$CI_PROJECT_DIR/.ssh/known_hosts"
-    - mkdir -p $CI_PROJECT_DIR/.ssh
-    - chmod 700 $CI_PROJECT_DIR/.ssh
-    - ssh-keyscan -p 10022 git.xfel.eu > $CI_PROJECT_DIR/.ssh/known_hosts
-    - ls  $CI_PROJECT_DIR/.ssh
-    - echo $GIT_SSH_COMMAND
-    - python3 -m venv .venv
-    - source .venv/bin/activate
-    - python3 -m pip install --upgrade pip
+  <<: *before_script
   script:
     - python3 -m pip install ".[test]"
     - python3 -m pytest --cov=cal_tools --cov=xfel_calibrate  --ignore=tests/legacy
-- 
GitLab