From a841297398cb624529a1434361a35325bfaffe47 Mon Sep 17 00:00:00 2001
From: Marek Szuba <marek.szuba@ebi.ac.uk>
Date: Tue, 12 Nov 2019 12:32:54 +0000
Subject: [PATCH] .gitlab-ci.yml: Do not launch MySQL or run before_script for
 non-test jobs

That way the runner will not waste time on installing Ensembl
dependencies in containers used to launch trigger-dependent-build.sh
---
 .gitlab-ci.yml | 66 +++++++++++++++++++++++++++-----------------------
 1 file changed, 36 insertions(+), 30 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8f05475120..2a952d71e6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,38 +2,42 @@ stages:
   - test
   - posttest
 
-services:
-  - mysql:5.6
+#
+# Test-job template
+#
 
-variables:
-  # FIXME: set some password for both users
-  MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
-  MYSQL_USER: "travis"
-  MYSQL_PASSWORD: ""
-  USER: "gitlabci"
+.ensembl_test_template:
+  services:
+    - mysql:5.6
+
+  variables:
+    # FIXME: set some password for both users
+    MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
+    MYSQL_USER: "travis"
+    MYSQL_PASSWORD: ""
+    USER: "gitlabci"
 
-# Run before each job not defining its own before_script
-before_script:
-  - apt-get update
-  - apt-get install -y build-essential cpanminus git
-  - apt-get install -y libmysqlclient-dev mysql-client || apt-get install -y default-libmysqlclient-dev default-mysql-client
-  - apt-get install -y libssl-dev sqlite3
-  - git clone --branch=master --depth=1 https://github.com/Ensembl/ensembl-test.git
-  - git clone --branch=master --depth=1 https://github.com/Ensembl/ensembl-io.git
-  - git clone --branch=master --depth=1 https://github.com/Ensembl/ensembl-variation.git
-  - git clone --branch=master --depth=1 https://github.com/Ensembl/ensembl-compara.git
-  - git clone --branch=release-1-6-924 --depth=1 https://github.com/bioperl/bioperl-live.git
-  - cpanm -v --installdeps --notest .
-  - ( cd ensembl-test && cpanm -v --installdeps --notest . )
-#  - ( cd ensembl-io && cpanm -v --installdeps --notest . )
-#  - ( cd ensembl-variation && cpanm -v --installdeps --notest . )
-  - ( cd ensembl-compara && cpanm -v --installdeps --notest . )
-  - ( cd misc-scripts/xref_mapping && cpanm -v --installdeps --notest . )
-  - cpanm -n Devel::Cover::Report::Coveralls
-  - cpanm -n DBD::SQLite
-  - cp travisci/MultiTestDB.conf.gitlabci.mysql  modules/t/MultiTestDB.conf.mysql
-  - cp travisci/MultiTestDB.conf.travisci.SQLite modules/t/MultiTestDB.conf.SQLite
-  - mysql -u root -h mysql -e 'GRANT ALL PRIVILEGES ON *.* TO "travis"@"%"'
+  before_script:
+    - apt-get update
+    - apt-get install -y build-essential cpanminus git
+    - apt-get install -y libmysqlclient-dev mysql-client || apt-get install -y default-libmysqlclient-dev default-mysql-client
+    - apt-get install -y libssl-dev sqlite3
+    - git clone --branch=master --depth=1 https://github.com/Ensembl/ensembl-test.git
+    - git clone --branch=master --depth=1 https://github.com/Ensembl/ensembl-io.git
+    - git clone --branch=master --depth=1 https://github.com/Ensembl/ensembl-variation.git
+    - git clone --branch=master --depth=1 https://github.com/Ensembl/ensembl-compara.git
+    - git clone --branch=release-1-6-924 --depth=1 https://github.com/bioperl/bioperl-live.git
+    - cpanm -v --installdeps --notest .
+    - ( cd ensembl-test && cpanm -v --installdeps --notest . )
+#    - ( cd ensembl-io && cpanm -v --installdeps --notest . )
+#    - ( cd ensembl-variation && cpanm -v --installdeps --notest . )
+    - ( cd ensembl-compara && cpanm -v --installdeps --notest . )
+    - ( cd misc-scripts/xref_mapping && cpanm -v --installdeps --notest . )
+    - cpanm -n Devel::Cover::Report::Coveralls
+    - cpanm -n DBD::SQLite
+    - cp travisci/MultiTestDB.conf.gitlabci.mysql  modules/t/MultiTestDB.conf.mysql
+    - cp travisci/MultiTestDB.conf.travisci.SQLite modules/t/MultiTestDB.conf.SQLite
+    - mysql -u root -h mysql -e 'GRANT ALL PRIVILEGES ON *.* TO "travis"@"%"'
 
 #
 # Test jobs
@@ -41,6 +45,7 @@ before_script:
 
 test:perl5.14-sqlite:
   stage: test
+  extends: .ensembl_test_template
   image: perl:5.14
   variables:
     COVERALLS: "false"
@@ -50,6 +55,7 @@ test:perl5.14-sqlite:
 
 test:perl5.30-mysql:
   stage: test
+  extends: .ensembl_test_template
   image: perl:5.30
   variables:
     # Note: relies on the secret variable COVERALLS_REPO_TOKEN for report uploads to work
-- 
GitLab