From 4dd9498811821c14a9766d4357b542b94d1cafd7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ma=C3=ABl=20Gramain?= <mael@enpls.org>
Date: Mon, 6 Jan 2025 21:24:28 +0100
Subject: [PATCH 1/4] test

---
 .woodpecker/lint.yml | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/.woodpecker/lint.yml b/.woodpecker/lint.yml
index a9fea1e..97e6012 100644
--- a/.woodpecker/lint.yml
+++ b/.woodpecker/lint.yml
@@ -6,10 +6,7 @@ steps:
       - python3 .ci/port_attribution_watcher.py
       - python3 .ci/traefik_labels_watcher.py
     when:
-      - event: pull_request
-        repo: gnouseu/docker-services
-      - event: push
-        branch: main
+      - event: [push, pull_request]
   lint:
     image: debian:stable-slim
     commands:
@@ -19,7 +16,4 @@ steps:
       - chmod +x /usr/local/bin/docker-compose
       - sh .ci/lint.sh
     when:
-      - event: pull_request
-        repo: gnouseu/docker-services
-      - event: push
-        branch: main
\ No newline at end of file
+      - event: [push, pull_request]
-- 
2.49.1


From 6d3def79f645e6c814c9279f95280b97bea54b61 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ma=C3=ABl=20Gramain?= <mael@enpls.org>
Date: Mon, 6 Jan 2025 21:32:33 +0100
Subject: [PATCH 2/4] Fix CICD

---
 .ci/gen_output.sh               | 28 +++++++++++++++++++++++++
 .ci/lint_wrap.sh                |  7 +++++++
 .ci/port_attribution_watcher.py | 13 ++++--------
 .ci/traefik_label_watcher.py    |  2 +-
 .woodpecker/lint.yml            | 37 +++++++++++++++++++++++++--------
 5 files changed, 68 insertions(+), 19 deletions(-)
 create mode 100755 .ci/gen_output.sh
 create mode 100755 .ci/lint_wrap.sh

diff --git a/.ci/gen_output.sh b/.ci/gen_output.sh
new file mode 100755
index 0000000..7c7662c
--- /dev/null
+++ b/.ci/gen_output.sh
@@ -0,0 +1,28 @@
+echo "\`\`\`" > output.txt
+
+process_output() {
+    if [ $? -eq 0 ]; then
+        head -n 5 output_tmp.txt >> output.txt
+        echo "... [See pipeline output for full details]" >> output.txt
+        tail -n 5 output_tmp.txt >> output.txt
+    else
+        cat output_tmp.txt >> output.txt
+    fi
+}
+
+echo "-- START Port attribution watcher --" | tee -a output.txt
+python3 .ci/port_attribution_watcher.py | tee output_tmp.txt
+
+process_output
+
+echo "-- END Port attribution watcher --" | tee -a output.txt
+echo "" >> output.txt
+echo "-- START Traefik label watcher --" | tee -a output.txt
+
+python3 .ci/traefik_label_watcher.py | tee output_tmp.txt
+
+process_output
+
+echo "-- END Traefik label watcher --" | tee -a output.txt
+echo "\`\`\`" >> output.txt # Close the code block
+
diff --git a/.ci/lint_wrap.sh b/.ci/lint_wrap.sh
new file mode 100755
index 0000000..b75c527
--- /dev/null
+++ b/.ci/lint_wrap.sh
@@ -0,0 +1,7 @@
+set -o pipefail
+sh .ci/lint.sh 2>&1 | tee output_tmp.txt
+echo "\`\`\`" > output.txt
+grep 'msg=' output_tmp.txt | awk -F'msg="' '{print $2}' | sed 's/"$//' | sed 's/\\"/"/g' >> output.txt
+echo $?
+echo "\`\`\`" >> output.txt
+echo "END"
\ No newline at end of file
diff --git a/.ci/port_attribution_watcher.py b/.ci/port_attribution_watcher.py
index 8432fc9..d5e2ffa 100644
--- a/.ci/port_attribution_watcher.py
+++ b/.ci/port_attribution_watcher.py
@@ -52,25 +52,20 @@ def main(watchFolder: str):
         # Get exposed ports
         exposedPorts = getExposedPortsFromDockerComposeFile(dockerComposeFile)
         ports[dockerComposeFile] = exposedPorts
-        if len(exposedPorts) == 0:
+        if len(exposedPorts) != 0:
             print(f"\nšŸ“¦ {dockerComposeFile}"
-                  f"\nšŸ”“ No exposed ports found"
-                  f"\n")
-        else:
-            print(f"\nšŸ“¦ {dockerComposeFile}"
-                f"\nšŸ”— Exposed ports: {exposedPorts}"
-                f"\n")
+                f"\nšŸ”— Exposed ports: {exposedPorts}")
     
     wrong = checkPortUnique(ports)
     
     if wrong:
         exit(1)
     else:
-        print("\n\nāœ… All ports are unique\n\n")
+        print("\nāœ… All ports are unique")
         exit(0)
 
 if __name__ == "__main__":
-    print("Traefik label watcher CI/CD")
+    print("Port Attribution Watcher")
     # Read folder from env
     watchFolder = os.getenv("WATCH_FOLDER")
     if watchFolder == None:
diff --git a/.ci/traefik_label_watcher.py b/.ci/traefik_label_watcher.py
index dda93b0..a3e3868 100644
--- a/.ci/traefik_label_watcher.py
+++ b/.ci/traefik_label_watcher.py
@@ -85,7 +85,7 @@ def main(watchFolder: str):
     if wrong:
         exit(1)
     else:
-        print("\n\nāœ… All routers are unique\n\n")
+        print("\n\nāœ… All routers are unique")
         exit(0)
 
 if __name__ == "__main__":
diff --git a/.woodpecker/lint.yml b/.woodpecker/lint.yml
index 97e6012..7089ae1 100644
--- a/.woodpecker/lint.yml
+++ b/.woodpecker/lint.yml
@@ -1,19 +1,38 @@
 steps:
   check_ports_labels:
-    image: python:3.12-slim
+    image: python:3.12
     commands:
       - pip3 install -r .ci/requirements.txt
-      - python3 .ci/port_attribution_watcher.py
-      - python3 .ci/traefik_labels_watcher.py
-    when:
-      - event: [push, pull_request]
+      - ./.ci/gen_output.sh
+  comment:
+      image: git.gnous.eu/enpls/gitea-comment-plugin:1.1
+      settings:
+        gitea_address: https://git.gnous.eu
+        gitea_token:
+          from_secret: gnous_cicd_token
+        comment_file: output.txt
+      when:
+        status: [failure, success]
+        event: [pull_request]
   lint:
-    image: debian:stable-slim
+    image: debian:stable
     commands:
+      - rm -rf output.txt
       - apt-get update
       - apt-get install -y curl
       - curl -SL https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
       - chmod +x /usr/local/bin/docker-compose
-      - sh .ci/lint.sh
-    when:
-      - event: [push, pull_request]
+      - bash .ci/lint_wrap.sh
+  comment_2:
+      image: git.gnous.eu/enpls/gitea-comment-plugin:1.1
+      settings:
+        gitea_address: https://git.gnous.eu
+        gitea_token:
+          from_secret: gnous_cicd_token
+        comment_file: output.txt
+      when:
+        status: [failure, success]
+        event: [pull_request]
+when:
+  - event: [push, pull_request]
+  - evaluate: 'CI_COMMIT_AUTHOR in ["gnous-ci-bot", "mael", "ada"]'
\ No newline at end of file
-- 
2.49.1


From ec22cbb3657ebd76797b56b60f59d72d948b7487 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ma=C3=ABl=20Gramain?= <mael@enpls.org>
Date: Mon, 6 Jan 2025 23:22:10 +0100
Subject: [PATCH 3/4] keep exit code

---
 .ci/lint_wrap.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/.ci/lint_wrap.sh b/.ci/lint_wrap.sh
index b75c527..29626d9 100755
--- a/.ci/lint_wrap.sh
+++ b/.ci/lint_wrap.sh
@@ -1,7 +1,8 @@
 set -o pipefail
 sh .ci/lint.sh 2>&1 | tee output_tmp.txt
+EXIT_CODE=$?
 echo "\`\`\`" > output.txt
 grep 'msg=' output_tmp.txt | awk -F'msg="' '{print $2}' | sed 's/"$//' | sed 's/\\"/"/g' >> output.txt
-echo $?
 echo "\`\`\`" >> output.txt
-echo "END"
\ No newline at end of file
+echo "END"
+exit $EXIT_CODE
\ No newline at end of file
-- 
2.49.1


From 95f5c919f17f3a590cd9454b3c02679ca66cd00b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ma=C3=ABl=20Gramain?= <mael@enpls.org>
Date: Mon, 6 Jan 2025 23:37:04 +0100
Subject: [PATCH 4/4] also keep non greped lines.

---
 .ci/lint_wrap.sh | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/.ci/lint_wrap.sh b/.ci/lint_wrap.sh
index 29626d9..20a6432 100755
--- a/.ci/lint_wrap.sh
+++ b/.ci/lint_wrap.sh
@@ -2,7 +2,10 @@ set -o pipefail
 sh .ci/lint.sh 2>&1 | tee output_tmp.txt
 EXIT_CODE=$?
 echo "\`\`\`" > output.txt
-grep 'msg=' output_tmp.txt | awk -F'msg="' '{print $2}' | sed 's/"$//' | sed 's/\\"/"/g' >> output.txt
+
+grep -n 'msg=' output_tmp.txt | awk -F'msg="' '{print $2}' | sed 's/"$//' | sed 's/\\"/"/g' >> output.txt
+grep -v 'msg=' output_tmp.txt >> output.txt
+
 echo "\`\`\`" >> output.txt
 echo "END"
-exit $EXIT_CODE
\ No newline at end of file
+exit $EXIT_CODE
-- 
2.49.1