From f4ee02e6fe0a27b54fe135f13783ecd8644c4e54 Mon Sep 17 00:00:00 2001
From: Timo Furrer <tfurrer@gitlab.com>
Date: Thu, 16 May 2024 09:36:21 +0200
Subject: [PATCH] Support skipping tests in CI for self-managed

This change set allows to disable the unit and integration tests in the
pipeline intended for GitLab self-managed to save runner resources.

Changelog: added

Closes https://gitlab.com/components/opentofu/-/issues/40
---
 .gitlab-ci.yml             | 4 ++++
 .gitlab/README.md.template | 3 +++
 README.md                  | 3 +++
 3 files changed, 10 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4d31d09..1f3861b 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,6 +8,8 @@ workflow:
 include:
   - local: tests/unit.gitlab-ci.yml
     rules:
+      - if: $SKIP_TESTS == "true"
+        when: never
       - changes:
           - src/gitlab-tofu.sh
           - Dockerfile
@@ -16,6 +18,8 @@ include:
       - if: $CI_COMMIT_TAG
   - local: tests/integration.gitlab-ci.yml
     rules:
+      - if: $SKIP_TESTS == "true"
+        when: never
       - changes:
           - src/gitlab-tofu.sh
           - Dockerfile
diff --git a/.gitlab/README.md.template b/.gitlab/README.md.template
index 03983f9..cb132e7 100644
--- a/.gitlab/README.md.template
+++ b/.gitlab/README.md.template
@@ -274,6 +274,9 @@ need to change that path in the `include:component` and additionally provide the
 See also the official GitLab documentation for it
 [here](https://docs.gitlab.com/ee/ci/components/#use-a-gitlabcom-component-in-a-self-managed-instance).
 
+If you want to save runner resources you may disable the unit and integration tests
+by setting the `SKIP_TESTS` CI/CD variable to `true`.
+
 ## Migrating from the Terraform CI/CD templates
 
 When migrating from the GitLab Terraform CI/CD templates you can use the following migration rules:
diff --git a/README.md b/README.md
index a6f8592..d74b269 100644
--- a/README.md
+++ b/README.md
@@ -299,6 +299,9 @@ need to change that path in the `include:component` and additionally provide the
 See also the official GitLab documentation for it
 [here](https://docs.gitlab.com/ee/ci/components/#use-a-gitlabcom-component-in-a-self-managed-instance).
 
+If you want to save runner resources you may disable the unit and integration tests
+by setting the `SKIP_TESTS` CI/CD variable to `true`.
+
 ## Migrating from the Terraform CI/CD templates
 
 When migrating from the GitLab Terraform CI/CD templates you can use the following migration rules:
-- 
GitLab