From d45a6d815359c53b7b343d1182b633f0f9b25498 Mon Sep 17 00:00:00 2001
From: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de>
Date: Mon, 17 Feb 2025 15:48:15 +0100
Subject: [PATCH 1/6] ci: generate the style patch artifact

---
 .gitlab-ci.yml  | 28 ++++++++++++++++++++++++++--
 CONTRIBUTING.md |  2 +-
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 077b8580..e2dd1ab2 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -68,9 +68,33 @@ Check licenses:
   interruptible: true
 
 Check style:
-  extends: .common_pre_commit
+  extends:
+    - .colorized
+    - .common_pre_commit
+  variables:
+    STYLE_PATCH: style.patch
   script:
-    - pre-commit run --show-diff-on-failure --color=always --all-files
+    - |
+      # pre-commit run --all-files
+      pre-commit run --color=always --all-files || {
+        printf "${RED}The source code does not meet the style requirements:\n
+        ${CI_PROJECT_URL}/-/blob/${CI_DEFAULT_BRANCH}/CONTRIBUTING.md#coding-style.\n${DEFAULT}"
+        git diff --ignore-submodules --patch-with-raw > "${STYLE_PATCH}"
+        test -s "${STYLE_PATCH}" && {
+          printf "${RED}At least some of the issues can be resolved with the patch (see artifacts):\n
+        ${CI_JOB_URL}/artifacts/raw/${STYLE_PATCH}.\n${DEFAULT}"
+        } || {
+          printf "${RED}The issues cannot be resolved with a patch.\n${DEFAULT}"
+          rm -rf "${STYLE_PATCH}"
+        }
+        exit 1
+      }
+  artifacts:
+    paths:
+      - ${STYLE_PATCH}
+    expose_as: 'Style Patch'
+    when: on_failure
+
   rules:
     - if: $CI_PIPELINE_SOURCE == "web"
       when: manual
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 3a86addc..becbb1ec 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,4 +1,4 @@
-# Formatting and linting
+# Coding style
 We use [`pre-commit`](https://pre-commit.com) hooks to maintain a set of
 formatting and linting rules. Although there is a CI job that runs for each
 merge request and checks whether the contribution does not break the rules, we
-- 
GitLab


From 39b62d16536cbb939da82fdb2718bbabdcea5872 Mon Sep 17 00:00:00 2001
From: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de>
Date: Mon, 17 Feb 2025 16:06:06 +0100
Subject: [PATCH 2/6] ci: instructions on how to run the license check

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

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e2dd1ab2..cc817da9 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -58,9 +58,17 @@ workflow:
         - ${PRE_COMMIT_HOME}
 
 Check licenses:
-  extends: .common_pre_commit
+  extends:
+    - .colorized
+    - .common_pre_commit
   script:
-    - pre-commit run --color=always --hook-stage manual reuse
+    - |
+      # pre-commit run --hook-stage manual reuse
+      pre-commit run --color=always --hook-stage manual reuse || {
+        printf "${RED}You can reproduce this check locally with \`pre-commit run --hook-stage manual reuse\`.
+      See also ${CI_PROJECT_URL}/-/blob/${CI_DEFAULT_BRANCH}/CONTRIBUTING.md#coding-style.\n${DEFAULT}"
+        exit 1
+      }
   rules:
     - if: $CI_PIPELINE_SOURCE == "web"
       when: manual
-- 
GitLab


From 5fdcc71f7f9fed2ed3b9b012454b95f39da4510a Mon Sep 17 00:00:00 2001
From: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de>
Date: Mon, 17 Feb 2025 16:09:24 +0100
Subject: [PATCH 3/6] ci: homogenize job messages

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

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index cc817da9..d90f7fd0 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -85,8 +85,6 @@ Check style:
     - |
       # pre-commit run --all-files
       pre-commit run --color=always --all-files || {
-        printf "${RED}The source code does not meet the style requirements:\n
-        ${CI_PROJECT_URL}/-/blob/${CI_DEFAULT_BRANCH}/CONTRIBUTING.md#coding-style.\n${DEFAULT}"
         git diff --ignore-submodules --patch-with-raw > "${STYLE_PATCH}"
         test -s "${STYLE_PATCH}" && {
           printf "${RED}At least some of the issues can be resolved with the patch (see artifacts):\n
@@ -95,6 +93,8 @@ Check style:
           printf "${RED}The issues cannot be resolved with a patch.\n${DEFAULT}"
           rm -rf "${STYLE_PATCH}"
         }
+        printf "${RED}You can reproduce this check locally with \`pre-commit run --all-files\`.
+      See also ${CI_PROJECT_URL}/-/blob/${CI_DEFAULT_BRANCH}/CONTRIBUTING.md#coding-style.\n${DEFAULT}"
         exit 1
       }
   artifacts:
-- 
GitLab


From 641f53e9e84ee6fc8fea590426703bb565f57922 Mon Sep 17 00:00:00 2001
From: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de>
Date: Mon, 17 Feb 2025 16:25:16 +0100
Subject: [PATCH 4/6] ci: drop redundant new lines

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

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index d90f7fd0..fb08c5e1 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -87,7 +87,7 @@ Check style:
       pre-commit run --color=always --all-files || {
         git diff --ignore-submodules --patch-with-raw > "${STYLE_PATCH}"
         test -s "${STYLE_PATCH}" && {
-          printf "${RED}At least some of the issues can be resolved with the patch (see artifacts):\n
+          printf "${RED}At least some of the issues can be resolved with the patch (see artifacts):
         ${CI_JOB_URL}/artifacts/raw/${STYLE_PATCH}.\n${DEFAULT}"
         } || {
           printf "${RED}The issues cannot be resolved with a patch.\n${DEFAULT}"
@@ -186,7 +186,7 @@ include:
         --exclude-standard \
       )
       test -z "${untracked_files}" || {
-        printf "${RED}The job produced unexpected files:\n${untracked_files}\n\
+        printf "${RED}The job produced unexpected files:\n${untracked_files}
       Update the '.gitignore' file.\n${DEFAULT}"
         exit 1
       }
-- 
GitLab


From 338c28706cf7cd4d53639453544eed6c6ae39ec7 Mon Sep 17 00:00:00 2001
From: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de>
Date: Mon, 17 Feb 2025 16:12:57 +0100
Subject: [PATCH 5/6] ci: fix rm flags

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

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index fb08c5e1..77b69b87 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -91,7 +91,7 @@ Check style:
         ${CI_JOB_URL}/artifacts/raw/${STYLE_PATCH}.\n${DEFAULT}"
         } || {
           printf "${RED}The issues cannot be resolved with a patch.\n${DEFAULT}"
-          rm -rf "${STYLE_PATCH}"
+          rm -f "${STYLE_PATCH}"
         }
         printf "${RED}You can reproduce this check locally with \`pre-commit run --all-files\`.
       See also ${CI_PROJECT_URL}/-/blob/${CI_DEFAULT_BRANCH}/CONTRIBUTING.md#coding-style.\n${DEFAULT}"
@@ -176,7 +176,7 @@ include:
         printf "${DEFAULT}"
         exit 1
       }
-      rm -rf "${BUILD_LOG}" "${compiler_warnings}"
+      rm -f "${BUILD_LOG}" "${compiler_warnings}"
     - |
       # Check if there are untracked files
       untracked_files=$( \
-- 
GitLab


From fda712139671f19491b618a8d405d28142c8d906 Mon Sep 17 00:00:00 2001
From: Sergey Kosukhin <sergey.kosukhin@mpimet.mpg.de>
Date: Mon, 17 Feb 2025 16:27:52 +0100
Subject: [PATCH 6/6] ci: handle problems with patch generation

---
 .gitlab-ci.yml | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 77b69b87..4709bd6d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -85,12 +85,16 @@ Check style:
     - |
       # pre-commit run --all-files
       pre-commit run --color=always --all-files || {
-        git diff --ignore-submodules --patch-with-raw > "${STYLE_PATCH}"
-        test -s "${STYLE_PATCH}" && {
-          printf "${RED}At least some of the issues can be resolved with the patch (see artifacts):
+        git diff --ignore-submodules --patch-with-raw > "${STYLE_PATCH}" && {
+          test -s "${STYLE_PATCH}" && {
+            printf "${RED}At least some of the issues can be resolved with the patch (see artifacts):
         ${CI_JOB_URL}/artifacts/raw/${STYLE_PATCH}.\n${DEFAULT}"
+          } || {
+            printf "${RED}The issues cannot be resolved with a patch.\n${DEFAULT}"
+            rm -f "${STYLE_PATCH}"
+          }
         } || {
-          printf "${RED}The issues cannot be resolved with a patch.\n${DEFAULT}"
+          printf "${RED}Failed to generate a patch file.\n${DEFAULT}"
           rm -f "${STYLE_PATCH}"
         }
         printf "${RED}You can reproduce this check locally with \`pre-commit run --all-files\`.
-- 
GitLab