From bf5bff3dae605d738843322f9d7965e7a91b7c74 Mon Sep 17 00:00:00 2001
From: Florent Pruvost <florent.pruvost@inria.fr>
Date: Wed, 19 Apr 2023 16:40:50 +0200
Subject: [PATCH] gitlab-ci: replace only/except (not highly maintained) by
 rules keyword

---
 .gitlab/build.yml               |  2 +-
 .gitlab/common.yml              | 31 +++++++++++++++----------------
 .gitlab/coverage.yml            |  3 +--
 .gitlab/pages.yml               |  5 +----
 .gitlab/preliminary.yml         |  4 +---
 .gitlab/release.yml             |  6 ++----
 .gitlab/test_hmat.yml           |  2 +-
 .gitlab/test_openmp.yml         |  2 +-
 .gitlab/test_parsec.yml         |  2 +-
 .gitlab/test_quark.yml          |  2 +-
 .gitlab/test_starpu.yml         |  4 ++--
 .gitlab/test_starpu_simgrid.yml |  2 +-
 12 files changed, 28 insertions(+), 37 deletions(-)

diff --git a/.gitlab/build.yml b/.gitlab/build.yml
index d6e8941f3..22931bfc7 100644
--- a/.gitlab/build.yml
+++ b/.gitlab/build.yml
@@ -51,7 +51,7 @@ build_starpu_simgrid:
     VERSION: starpu_simgrid
 
 build_starpu_macosx:
-  extends: .only-branches
+  extends: .only-merge-request
   stage: build
   tags: ['macosx']
   variables:
diff --git a/.gitlab/common.yml b/.gitlab/common.yml
index 67b9defe5..50833083b 100644
--- a/.gitlab/common.yml
+++ b/.gitlab/common.yml
@@ -6,28 +6,26 @@ default:
   image: registry.gitlab.inria.fr/solverstack/docker/distrib
   tags: ['ci.inria.fr', 'linux', 'large']
 
+# push event: executed only if the source branch name is master or starts with ci-
+# merge request event: not executed
+# schedule event: not executed
 .only-master:
-  except: ['schedule']
   interruptible: true
-  only:
-    - master@solverstack/chameleon
-    - /^ci-.*$/
-  except:
-    - /^notest-.*$/
+  rules:
+    - if: ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /^ci-.*$/) && $CI_PIPELINE_SOURCE != "schedule"
 
-.only-branches:
-  except: ['schedule']
+# push event: executed only if the source branch name is master or starts with ci-
+# merge request event: executed if the source branch name does not start with notest-
+# schedule event: not executed
+.only-merge-request:
   interruptible: true
-  only:
-    - merge_requests
-    - master@solverstack/chameleon
-    - /^ci-.*$/
-  except:
-    - /^notest-.*$/
+  rules:
+    - if: ($CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH =~ /^ci-.*$/) && $CI_PIPELINE_SOURCE != "schedule"
+    - if: ($CI_MERGE_REQUEST_IID && $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME !~ /^notest-.*$/) && $CI_PIPELINE_SOURCE != "schedule"
 
 .build_script_template:
   stage: build
-  extends: .only-branches
+  extends: .only-merge-request
   script:
     - ./.gitlab/build.sh
   artifacts:
@@ -53,7 +51,8 @@ default:
       junit: junit.xml
 
 .bench_plafrim_common:
-  only: ['schedule']
+  rules:
+    - if: $CI_PIPELINE_SOURCE == "schedule"
   stage: test
   tags: ['plafrim']
   timeout: 1 week
diff --git a/.gitlab/coverage.yml b/.gitlab/coverage.yml
index 44d5576ae..d2393faac 100644
--- a/.gitlab/coverage.yml
+++ b/.gitlab/coverage.yml
@@ -6,8 +6,7 @@
 #
 ---
 coverage:
-  only:
-    - merge_requests
+  extends: .only-merge-request
   interruptible: true
   stage: analyse
   script:
diff --git a/.gitlab/pages.yml b/.gitlab/pages.yml
index 41aec70ac..8ae81ed8b 100644
--- a/.gitlab/pages.yml
+++ b/.gitlab/pages.yml
@@ -1,6 +1,7 @@
 ---
 pages:
   stage: deploy
+  extends: .only-master
   dependencies: []
   artifacts:
     name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
@@ -11,7 +12,3 @@ pages:
     VERSION: pages
   script:
     - ./tools/pages.sh
-  only:
-    - master@solverstack/chameleon
-    - /^ci.*$/
-  interruptible: true
diff --git a/.gitlab/preliminary.yml b/.gitlab/preliminary.yml
index a1e137cb5..a6d303831 100644
--- a/.gitlab/preliminary.yml
+++ b/.gitlab/preliminary.yml
@@ -4,12 +4,10 @@
 ---
 preliminary_checks:
   stage: .pre
+  extends: .only-merge-request
   parallel:
     matrix:
       - TEST: [rebase, draft, header]
   script:
     - .gitlab/check_ci.sh $TEST
-  only:
-    - merge_requests
-  interruptible: true
 
diff --git a/.gitlab/release.yml b/.gitlab/release.yml
index 5ed711f56..eade839d3 100644
--- a/.gitlab/release.yml
+++ b/.gitlab/release.yml
@@ -1,6 +1,8 @@
 ---
 release:
   stage: deploy
+  rules:
+    - if: $CI_COMMIT_BRANCH =~ /^release-.*$/ && $CI_PIPELINE_SOURCE != "schedule"
   dependencies: []
   artifacts:
     name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
@@ -11,7 +13,3 @@ release:
     VERSION: release
   script:
     - ./tools/release.sh
-  only:
-    - /^release-.*$/
-  except:
-    - schedules
diff --git a/.gitlab/test_hmat.yml b/.gitlab/test_hmat.yml
index 894dc50f1..23cc8a5cc 100644
--- a/.gitlab/test_hmat.yml
+++ b/.gitlab/test_hmat.yml
@@ -12,7 +12,7 @@
 .test_hmat_template_branches: &test_hmat_branches
   extends:
     - .test_hmat_template
-    - .only-branches
+    - .only-merge-request
 
 test_hmat:
   <<: *test_hmat_branches
diff --git a/.gitlab/test_openmp.yml b/.gitlab/test_openmp.yml
index b026ae451..dbb9271bc 100644
--- a/.gitlab/test_openmp.yml
+++ b/.gitlab/test_openmp.yml
@@ -12,7 +12,7 @@
 .test_openmp_template_branches: &test_openmp_branches
   extends:
     - .test_openmp_template
-    - .only-branches
+    - .only-merge-request
 
 test_openmp_shm_s:
   <<: *test_openmp_master
diff --git a/.gitlab/test_parsec.yml b/.gitlab/test_parsec.yml
index ae137fafe..842c7f13f 100644
--- a/.gitlab/test_parsec.yml
+++ b/.gitlab/test_parsec.yml
@@ -12,7 +12,7 @@
 .test_parsec_template_branches: &test_parsec_branches
   extends:
     - .test_parsec_template
-    - .only-branches
+    - .only-merge-request
 
 test_parsec_shm_s:
   <<: *test_parsec_master
diff --git a/.gitlab/test_quark.yml b/.gitlab/test_quark.yml
index 98d27b947..29421613e 100644
--- a/.gitlab/test_quark.yml
+++ b/.gitlab/test_quark.yml
@@ -12,7 +12,7 @@
 .test_quark_template_branches: &test_quark_branches
   extends:
     - .test_quark_template
-    - .only-branches
+    - .only-merge-request
 
 test_quark_shm_s:
   <<: *test_quark_branches
diff --git a/.gitlab/test_starpu.yml b/.gitlab/test_starpu.yml
index 2574cdc8a..251204f0b 100644
--- a/.gitlab/test_starpu.yml
+++ b/.gitlab/test_starpu.yml
@@ -12,7 +12,7 @@
 .test_starpu_template_branches: &test_starpu_branches
   extends:
     - .test_starpu_template
-    - .only-branches
+    - .only-merge-request
 
 test_starpu_shm_s:
   <<: *test_starpu_master
@@ -79,7 +79,7 @@ test_starpu_mpi_z:
     TESTS_RESTRICTION: "-R \"_${CATEGORY}_${PRECISION}\""
 
 test_starpu_shm_s_macosx:
-  extends: .only-branches
+  extends: .only-merge-request
   stage: test
   tags: ['macosx']
   needs: [build_starpu_macosx]
diff --git a/.gitlab/test_starpu_simgrid.yml b/.gitlab/test_starpu_simgrid.yml
index 0cd7b9ff3..17ae0afb6 100644
--- a/.gitlab/test_starpu_simgrid.yml
+++ b/.gitlab/test_starpu_simgrid.yml
@@ -12,7 +12,7 @@
 .test_starpu_simgrid_template_branches: &test_starpu_simgrid_branches
   extends:
     - .test_starpu_simgrid_template
-    - .only-branches
+    - .only-merge-request
 
 test_starpu_simgrid_simu_all:
   <<: *test_starpu_simgrid_branches
-- 
GitLab