From 2d1cca1138bee82359a1d275121ab7f35aee559d Mon Sep 17 00:00:00 2001
From: Sylvester Joosten <sjoosten@anl.gov>
Date: Tue, 1 Dec 2020 16:00:11 +0000
Subject: [PATCH] Streamlining gitlab CI, removed testing/staging step from
 workflow and added CI rules for merge requests

---
 .gitlab-ci.yml | 155 ++++++++++++++-----------------------------------
 1 file changed, 43 insertions(+), 112 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6de0ebee1..a95406254 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,5 +1,5 @@
 image: eicweb.phy.anl.gov:4567/containers/image_recipes/ubuntu_dind:latest
-#
+
 stages:
   - builder
   - config
@@ -9,68 +9,41 @@ stages:
 builder:stable:
   stage: builder
   tags:
-     - silicon
-  only:
-     - tags
-     - master
-  script:
-     - cd containers/builder
-     - head Dockerfile
-     - make login
-     - make release-cached
-builder:testing:
-  stage: builder
-  tags:
-     - silicon
+    - silicon
   only:
-     - staging
+    - tags
+    - master
   script:
-     - cd containers/builder
-     - head Dockerfile
-     - make login
-     - make staging-cached
+    - cd containers/builder
+    - head Dockerfile
+    - make login
+    - make release-cached
 builder:unstable:
   stage: builder
   tags:
-     - silicon
-  except:
-     - tags
-     - master
-     - staging
+    - silicon
+  rules:
+    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_SOURCE_BRANCH != develop'
+      when: always
+    - if: '$CI_COMMIT_BRANCH == "develop"'
+      when: always
   script:
-     - cd containers/builder
-     - head Dockerfile
-     - make login
-     - make develop-cached
+    - cd containers/builder
+    - head Dockerfile
+    - make login
+    - make develop-cached
 
-## I wish there were a simple way to transfer the "latest/unstable" strings
-## between jobs...
 config:stable:
   image: eicweb.phy.anl.gov:4567/containers/eic_container/eic_builder:latest
   stage: config
   tags:
     - silicon
   only:
-     - tags
-     - master
+    - tags
+    - master
   needs: ["builder:stable"]
   script:
-    - bash containers/release/configure_release.sh latest
-  artifacts:
-    paths:
-      - config/spack-env.sh
-      - config/eic-env.sh
-      - config/Dockerfile
-config:testing:
-  image: eicweb.phy.anl.gov:4567/containers/eic_container/eic_builder:testing
-  stage: config
-  tags:
-    - silicon
-  only:
-     - staging
-  needs: ["builder:testing"]
-  script:
-    - bash containers/release/configure_release.sh testing
+   - bash containers/release/configure_release.sh latest
   artifacts:
     paths:
       - config/spack-env.sh
@@ -81,10 +54,11 @@ config:unstable:
   stage: config
   tags:
     - silicon
-  except:
-     - tags
-     - master
-     - staging
+  rules:
+    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_SOURCE_BRANCH != develop'
+      when: manual
+    - if: '$CI_COMMIT_BRANCH == "develop"'
+      when: always
   needs: ["builder:unstable"]
   script:
     - bash containers/release/configure_release.sh unstable
@@ -108,27 +82,15 @@ release:stable:
      - cd containers/release
      - make login
      - make release-cached
-release:testing:
-  stage: slim
-  tags:
-     - silicon
-  only:
-     - staging
-  needs: ["config:testing"]
-  script:
-     - cp config/Dockerfile containers/release/Dockerfile
-     - cp config/eic-env.sh containers/release/eic-env.sh
-     - cd containers/release
-     - make login
-     - make staging-cached
 release:unstable:
   stage: slim
   tags:
      - silicon
-  except:
-     - tags
-     - master
-     - staging
+  rules:
+    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_SOURCE_BRANCH != develop'
+      when: manual
+    - if: '$CI_COMMIT_BRANCH == "develop"'
+      when: always
   needs: ["config:unstable"]
   script:
      - cp config/Dockerfile containers/release/Dockerfile
@@ -141,6 +103,11 @@ release:singularity:
   stage: singularity
   tags:
      - silicon
+  rules:
+    - if: '$CI_COMMIT_TAG'
+      when: always
+    - if: '$CI_COMMIT_BRANCH == "master"'
+      when: manual
   only:
      - tags
   needs: ["release:stable"]
@@ -152,47 +119,7 @@ release:singularity:
      - cp eic.sif build/.
      - cp eic.def build/.
   artifacts:
-      expire_in: 90 days # this will change in future gitlab vesions :https://docs.gitlab.com/13.3/ee/ci/yaml/README.html#artifactsexpire_in
-      paths:
-        - build/eic.sif
-        - build/eic.def
-release:singularity:stable:
-  stage: singularity
-  tags:
-     - silicon
-  only:
-     - master
-  when: manual
-  needs: ["release:stable"]
-  script:
-     - cp containers/release/eic.def .
-     - /bin/bash .gitlabci/setup.sh
-     - /bin/bash .gitlabci/build.sh eic.def
-     - mkdir -p build 
-     - cp eic.sif build/.
-     - cp eic.def build/.
-  artifacts:
-      expire_in: 90 days # this will change in future gitlab vesions :https://docs.gitlab.com/13.3/ee/ci/yaml/README.html#artifactsexpire_in
-      paths:
-        - build/eic.sif
-        - build/eic.def
-release:singularity:testing:
-  stage: singularity
-  tags:
-     - silicon
-  only:
-     - staging
-  when: manual
-  needs: ["release:testing"]
-  script:
-     - cp containers/release/eic.def .
-     - /bin/bash .gitlabci/setup.sh
-     - /bin/bash .gitlabci/build.sh eic.def
-     - mkdir -p build 
-     - cp eic.sif build/.
-     - cp eic.def build/.
-  artifacts:
-      expire_in: 90 days # this will change in future gitlab vesions :https://docs.gitlab.com/13.3/ee/ci/yaml/README.html#artifactsexpire_in
+      expire_in: 90 days
       paths:
         - build/eic.sif
         - build/eic.def
@@ -203,7 +130,11 @@ release:singularity:unstable:
   only:
      - develop
   needs: ["release:unstable"]
-  when: manual
+  rules:
+    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_SOURCE_BRANCH != develop'
+      when: manual
+    - if: '$CI_COMMIT_BRANCH == "develop"'
+      when: manual
   script:
      - cp containers/release/eic.def .
      - /bin/bash .gitlabci/setup.sh
@@ -212,7 +143,7 @@ release:singularity:unstable:
      - cp eic.sif build/.
      - cp eic.def build/.
   artifacts:
-      expire_in: 90 days # this will change in future gitlab vesions :https://docs.gitlab.com/13.3/ee/ci/yaml/README.html#artifactsexpire_in
+      expire_in: 90 days 
       paths:
         - build/eic.sif
         - build/eic.def
-- 
GitLab