From 20403466701340651b640dd977c98d6f52773a44 Mon Sep 17 00:00:00 2001
From: Timo Furrer <tfurrer@gitlab.com>
Date: Mon, 8 Apr 2024 11:04:59 +0200
Subject: [PATCH] Refine pipeline job rules

---
 .gitlab-ci.yml | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5467ee0..51bdcfc 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -14,7 +14,6 @@ include:
           - .gitlab-ci.yml
           - tests/unit.gitlab-ci.yml
       - if: $CI_COMMIT_TAG
-      - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
   - local: tests/integration.gitlab-ci.yml
     rules:
       - changes:
@@ -27,6 +26,7 @@ include:
           - tests/iac/**.tf
           - backports/*.gitlab-ci.yml
           - backports/OpenTofu/*.gitlab-ciyml
+      - if: $CI_COMMIT_TAG
   # FIXME: we cannot make this work for all use cases because of the following:
   # - cannot pass parallel.matrix to the component, thus we need to extend it
   # - that leads to a problem that when this component is ruled out, the extended job fails, 
@@ -108,6 +108,15 @@ gitlab-opentofu-image:build:
       --provenance=false
       --push
       .
+  rules:
+    - if: $CI_COMMIT_TAG
+    - changes:
+        - Dockerfile
+        - .gitlab-ci.yml
+        - src/**/*
+        - templates/**/*
+        - tests/**/*
+        - backports/**/*
 
 check-readme:
   stage: test
@@ -118,6 +127,14 @@ check-readme:
   script:
     - make docs
     - git diff --exit-code
+  rules:
+    - if: $CI_COMMIT_TAG
+    - changes:
+        - Makefile
+        - .gitlab-ci.yml
+        - README.md
+        - .gitlab/README.md.template
+        - templates/**/*
 
 check-backports:
   stage: test
@@ -128,6 +145,13 @@ check-backports:
   script:
     - make backports
     - git diff --exit-code
+  rules:
+    - if: $CI_COMMIT_TAG
+    - changes:
+        - Makefile
+        - .gitlab-ci.yml
+        - backports/**/*
+        - templates/**/*
 
 shellcheck:
   stage: test
@@ -142,7 +166,6 @@ shellcheck:
         - src/gitlab-tofu.sh
         - .gitlab/scripts/*.sh
     - if: $CI_COMMIT_TAG
-    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
 
 # FIXME: see component include why we have to disable this.
 # container_scanning:
-- 
GitLab