From 00e4dddb4d84ba1b48797aa39a5fc45ce3090b03 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Mon, 25 Jan 2021 15:55:05 +0100
Subject: [PATCH] gitlab-ci-cd/drupal#2 Add support for "[INITIAL_INSTALL]" in
 the commit message to trigger the initial installation of a Drupal site
 without DB and without tests

---
 test-and-deploy.yml | 84 +++++++++++++++++++++++++++++----------------
 1 file changed, 55 insertions(+), 29 deletions(-)

diff --git a/test-and-deploy.yml b/test-and-deploy.yml
index 7398fc9..67d15c4 100644
--- a/test-and-deploy.yml
+++ b/test-and-deploy.yml
@@ -93,6 +93,12 @@ stages:
     else
       echo "No pulling required."
     fi
+
+    INITIALINSTALL="no"
+    if [[ "$CI_COMMIT_MESSAGE" == *"[INITIAL_INSTALL]"* ]]; then
+      INITIALINSTALL="yes"
+    fi
+    echo "INITIALINSTALL=${INITIALINSTALL}" >> validation.env
   except:
     variables:
       - $CAE
@@ -188,7 +194,9 @@ stages:
     GIT_STRATEGY: none
   script: |
     if [[ "$DBREQUIRED" == "yes" ]]; then
-      ascr drupal-dump-db ${CI_PROJECT_PATH} ${PWD}/${CI_PROJECT_NAME}.sql master
+      if [[ "$INITIALINSTALL" == "no" ]]; then
+        ascr drupal-dump-db ${CI_PROJECT_PATH} ${PWD}/${CI_PROJECT_NAME}.sql master
+      fi
     fi
   cache: {}
   dependencies:
@@ -214,13 +222,15 @@ stages:
     GIT_STRATEGY: none
   script: |
     if [[ "$DBREQUIRED" == "yes" ]]; then
-      docker cp ${CI_PROJECT_NAME}.sql ${COMPOSE_PROJECT_NAME}_php_1:/var/www/html
-      drush sql:drop --yes
-      drush sql:query --file=../${CI_PROJECT_NAME}.sql
-      drush cr
-      drush updatedb
-      drush config-import sync
-      drush cr
+      if [[ "$INITIALINSTALL" == "no" ]]; then
+        docker cp ${CI_PROJECT_NAME}.sql ${COMPOSE_PROJECT_NAME}_php_1:/var/www/html
+        drush sql:drop --yes
+        drush sql:query --file=../${CI_PROJECT_NAME}.sql
+        drush cr
+        drush updatedb
+        drush config-import sync
+        drush cr
+      fi
     fi
   except:
     refs:
@@ -242,10 +252,12 @@ stages:
     GIT_STRATEGY: none
   script: |
     if [[ "$DBREQUIRED" == "no" ]]; then
-      drush cr
-      drush updatedb
-      drush config-import sync
-      drush cr
+      if [[ "$INITIALINSTALL" == "no" ]]; then
+        drush cr
+        drush updatedb
+        drush config-import sync
+        drush cr
+      fi
     fi
   except:
     refs:
@@ -289,10 +301,12 @@ stages:
     - default
   variables:
     GIT_STRATEGY: none
-  script:
-    #- ahoy test phpcs -- -n --report=xml --report-file=phpcs.xml
-    #- docker cp ${COMPOSE_PROJECT_NAME}_php_1:/var/www/html/phpcs.xml ./phpcs.xml
-    - echo "Disabled because of Drupal Coder issues" > ./phpcs.xml
+  script: |
+    if [[ "$INITIALINSTALL" == "no" ]]; then
+      # ahoy test phpcs -- -n --report=xml --report-file=phpcs.xml
+      # docker cp ${COMPOSE_PROJECT_NAME}_php_1:/var/www/html/phpcs.xml ./phpcs.xml
+      echo "Disabled because of Drupal Coder issues" > ./phpcs.xml
+    fi
   artifacts:
     name: phpcs
     when: always
@@ -315,8 +329,10 @@ stages:
     - default
   variables:
     GIT_STRATEGY: none
-  script:
-    - ahoy test phpunit -- --log-junit junit.xml --testdox-html testdox.html
+  script: |
+    if [[ "$INITIALINSTALL" == "no" ]]; then
+      ahoy test phpunit -- --log-junit junit.xml --testdox-html testdox.html
+    fi
   after_script:
     - docker cp ${COMPOSE_PROJECT_NAME}_php_1:/var/www/html/junit.xml ./junit.xml
     - docker cp ${COMPOSE_PROJECT_NAME}_php_1:/var/www/html/testdox.html ./testdox.html
@@ -345,11 +361,11 @@ stages:
     - default
   variables:
     GIT_STRATEGY: none
-  script:
-    - ls tests -lisa
-    - ahoy behat update
-    - ls tests/behat/ -lisa
-    - ahoy behat test2xml
+  script: |
+    if [[ "$INITIALINSTALL" == "no" ]]; then
+      ahoy behat update
+      ahoy behat test2xml
+    fi
   after_script:
     - docker cp ${COMPOSE_PROJECT_NAME}_php_1:/var/www/html/tests/output/default.xml ./behat.xml
   retry: 1
@@ -376,8 +392,10 @@ stages:
     - default
   variables:
     GIT_STRATEGY: none
-  script:
-    - backstop test
+  script: |
+    if [[ "$INITIALINSTALL" == "no" ]]; then
+      backstop test
+    fi
   artifacts:
     name: backstop
     when: always
@@ -404,8 +422,12 @@ stages:
     GIT_STRATEGY: none
   environment:
     name: ${ENVIRONMENT_NAME}
-  script:
-    - ascr drupal-deploy $HOST_NAME $SITE_NAME --extra-vars="DRUPAL_ARTEFACT_SRC=${PWD}" ${CAE}
+  script: |
+    if [[ "$INITIALINSTALL" == "no" ]]; then
+      ascr drupal-deploy $HOST_NAME $SITE_NAME --extra-vars="DRUPAL_ARTEFACT_SRC=${PWD}" ${CAE}
+    else
+      ascr drupal-config $HOST_NAME $SITE_NAME --extra-vars="DRUPAL_ARTEFACT_SRC=${PWD}" ${CAE}
+    fi
   cache: {}
   dependencies:
     - 'Build Theme'
@@ -424,8 +446,12 @@ stages:
     GIT_STRATEGY: none
   environment:
     name: ${ENVIRONMENT_NAME}
-  script:
-    - ascr drupal-deploy $HOST_NAME $SITE_NAME --extra-vars="DRUPAL_ARTEFACT_SRC=${PWD}" ${CAE}
+  script: |
+    if [[ "$INITIALINSTALL" == "no" ]]; then
+      ascr drupal-deploy $HOST_NAME $SITE_NAME --extra-vars="DRUPAL_ARTEFACT_SRC=${PWD}" ${CAE}
+    else
+      ascr drupal-config $HOST_NAME $SITE_NAME --extra-vars="DRUPAL_ARTEFACT_SRC=${PWD}" ${CAE}
+    fi
   cache: {}
   dependencies:
     - 'Build Prod Site'
-- 
GitLab