From 91f398db4c92056bc77c1c82fe9a61e2c8739e8d Mon Sep 17 00:00:00 2001
From: Chris Evich <cevich@redhat.com>
Date: Mon, 8 Oct 2018 09:40:31 -0400
Subject: Cirrus: Skip rebuilding images unless instructed

Given frequent merges, it doesn't make sense to rebuild the VM testing
images every time.  Instead, monitor the PR title and description for
a magic string, only triggering builds on a match:

***CIRRUS: REBUILD IMAGES***

Signed-off-by: Chris Evich <cevich@redhat.com>
---
 contrib/cirrus/build_vm_images.sh | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

(limited to 'contrib/cirrus/build_vm_images.sh')

diff --git a/contrib/cirrus/build_vm_images.sh b/contrib/cirrus/build_vm_images.sh
index 80c689a6c..ffbb2d5d5 100755
--- a/contrib/cirrus/build_vm_images.sh
+++ b/contrib/cirrus/build_vm_images.sh
@@ -22,9 +22,7 @@ SCRIPT_BASE $SCRIPT_BASE
 PACKER_BASE $PACKER_BASE
 "
 
-# TODO: Skip building images if $CIRRUS_BRANCH =~ "master" and
-# commit message of $CIRRUS_CHANGE_IN_REPO contains a magic word
-# produced by 'commit_and_create_upstream_pr.sh' script (see .cirrus.yml)
+require_regex '\*\*\*\s*CIRRUS:\s*REBUILD\s*IMAGES\s*\*\*\*' 'Not re-building VM images'
 
 show_env_vars
 
-- 
cgit v1.2.3-54-g00ecf


From aa742e9e681d91cf23a7e4e496358cab4d0ececa Mon Sep 17 00:00:00 2001
From: Chris Evich <cevich@redhat.com>
Date: Thu, 8 Nov 2018 09:28:48 -0500
Subject: Cirrus: Reveal magic, parallel system-testing

Previously, several magic strings were in place to affect cirrus-ci
operations.  Two were buried within scripts.  One to optionally
execute system-tests within a PR. Another to avoid re-building
cache-images upon every merge.

Move these magic strings out into the open, buy locating their
logic up-front in the ``.cirrus.yml`` file.  This improves
readability and reduces surprise/astonishment at runtime.

Signed-off-by: Chris Evich <cevich@redhat.com>
---
 .cirrus.yml                            | 49 +++++++++++++++++++++++++++-------
 contrib/cirrus/build_vm_images.sh      |  2 --
 contrib/cirrus/lib.sh                  | 17 ------------
 contrib/cirrus/optional_system_test.sh |  8 ------
 4 files changed, 40 insertions(+), 36 deletions(-)

(limited to 'contrib/cirrus/build_vm_images.sh')

diff --git a/.cirrus.yml b/.cirrus.yml
index f78205a49..6fd9dc444 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -63,24 +63,55 @@ full_vm_testing_task:
 
     integration_test_script: $SCRIPT_BASE/integration_test.sh
 
-    optional_system_test_script: $SCRIPT_BASE/optional_system_test.sh
+    success_script: $SCRIPT_BASE/success.sh
+
+
+# Because system tests are stored within the repository, it is sometimes
+# necessary to execute them within a PR to validate changes.
+
+optional_system_testing_task:
+
+    # Only run system tests in PRs (not on merge) if magic string is present
+    # in the PR description.  Post-merge system testing is assumed to happen
+    # later from OS distribution's build systems.
+    only_if: >-
+        $CIRRUS_BRANCH != 'master' &&
+        $CIRRUS_CHANGE_MESSAGE =~ '\*\*\*\s*CIRRUS:\s*SYSTEM\s*TEST\s*\*\*\*'
 
+    gce_instance:
+        matrix:
+            image_name: "ubuntu-1804-bionic-v20180911-libpod-63a86a18"
+            # TODO: Make these work (also build_images_task below)
+            #image_name: "rhel-server-ec2-7-5-165-1-libpod-fce09afe"
+            #image_name: "centos-7-v20180911-libpod-fce09afe"
+            #image_name: "fedora-cloud-base-28-1-1-7-libpod-fce09afe"
+
+    timeout_in: 60m
+
+    setup_environment_script: $SCRIPT_BASE/setup_environment.sh
+    verify_source_script: $SCRIPT_BASE/verify_source.sh
+    unit_test_script: $SCRIPT_BASE/unit_test.sh
+    integration_test_script: $SCRIPT_BASE/integration_test.sh
+    system_test_script: $SCRIPT_BASE/optional_system_test.sh
     success_script: $SCRIPT_BASE/success.sh
 
 
-# This task build new images for future PR testing, but only after a PR merge.
-# These images save needing to install/setup the same environment to test every
-# PR.  The 'active' image for testing is selected by the 'image_name' items in
-# task above.  Currently this requires manually updating them, but this could
-# be automated (see comment at end).
+# This task builds new cache-images for future PR testing.  These images save
+# time installing/setting up the environment while an engineer is waiting.
+# The 'active' cache-images for full_vm_testing are selected by the
+# 'image_name' keys.  Updating those items requires manually modification,
+# but this could be automated (see comment at end of build_vm_images_task).
 
 build_vm_images_task:
-    # Only produce new images after a PR merge
-    only_if: $CIRRUS_BRANCH == 'master'
+    # Only produce new cache-images after a PR merge, and if a magic string
+    # is present in the most recent commit-message.
+    only_if: >-
+        $CIRRUS_BRANCH == 'master' &&
+        $CIRRUS_CHANGE_MESSAGE =~ '\*\*\*\s*CIRRUS:\s*REBUILD\s*IMAGES\s*\*\*\*'
 
     # Require tests to pass first.
     depends_on:
-        - test  # i.e. 'test_task'
+        - full_vm_testing  # i.e. 'full_vm_testing_task'
 
     env:
         # CSV of packer builder names to enable (see $PACKER_BASE/libpod_images.json)
diff --git a/contrib/cirrus/build_vm_images.sh b/contrib/cirrus/build_vm_images.sh
index ffbb2d5d5..c8ff55445 100755
--- a/contrib/cirrus/build_vm_images.sh
+++ b/contrib/cirrus/build_vm_images.sh
@@ -22,8 +22,6 @@ SCRIPT_BASE $SCRIPT_BASE
 PACKER_BASE $PACKER_BASE
 "
 
-require_regex '\*\*\*\s*CIRRUS:\s*REBUILD\s*IMAGES\s*\*\*\*' 'Not re-building VM images'
-
 show_env_vars
 
 # Everything here is running on the 'image-builder-image' GCE image
diff --git a/contrib/cirrus/lib.sh b/contrib/cirrus/lib.sh
index 4a3efb8ff..6d43c6ea5 100644
--- a/contrib/cirrus/lib.sh
+++ b/contrib/cirrus/lib.sh
@@ -120,23 +120,6 @@ cdsudo() {
     sudo --preserve-env=GOPATH --non-interactive bash -c "$CMD"
 }
 
-# Skip a build if $1 does not match in the PR Title/Description with message $2
-require_regex() {
-    req_env_var "
-        CIRRUS_CHANGE_MESSAGE $CIRRUS_CHANGE_MESSAGE
-        1 $1
-        2 $2
-    "
-    regex="$1"
-    msg="$2"
-    if ! echo "$CIRRUS_CHANGE_MESSAGE" | egrep -q "$regex"
-    then
-        echo "***** The PR Title/Description did not match the regular expression: $MAGIC_RE"
-        echo "***** $msg"
-        exit 0
-    fi
-}
-
 # Helper/wrapper script to only show stderr/stdout on non-zero exit
 install_ooe() {
     req_env_var "SCRIPT_BASE $SCRIPT_BASE"
diff --git a/contrib/cirrus/optional_system_test.sh b/contrib/cirrus/optional_system_test.sh
index 705dda5ad..dfe8e8a2c 100755
--- a/contrib/cirrus/optional_system_test.sh
+++ b/contrib/cirrus/optional_system_test.sh
@@ -3,14 +3,6 @@
 set -e
 source $(dirname $0)/lib.sh
 
-MAGIC_RE='\*\*\*\s*CIRRUS:\s*SYSTEM\s*TEST\s*\*\*\*'
-if ! echo "$CIRRUS_CHANGE_MESSAGE" | egrep -q "$MAGIC_RE"
-then
-    echo "Skipping system-testing because PR title or description"
-    echo "does not match regular expression: $MAGIC_RE"
-    exit 0
-fi
-
 req_env_var "
 GOSRC $GOSRC
 OS_RELEASE_ID $OS_RELEASE_ID
-- 
cgit v1.2.3-54-g00ecf