From ca25c97093e21f707178313c1715f664a9e71637 Mon Sep 17 00:00:00 2001
From: Ole Langbehn <ole.langbehn@inoio.de>
Date: Wed, 5 Mar 2025 13:26:23 +0100
Subject: [PATCH] fix(CI): don't send webhook notifications on job failure

---
 .gitlab-ci-mobile.yml | 16 ++++++++++++----
 .gitlab-ci-web.yml    | 20 ++++++++++++--------
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/.gitlab-ci-mobile.yml b/.gitlab-ci-mobile.yml
index a8da49e00b..67d84e3c05 100644
--- a/.gitlab-ci-mobile.yml
+++ b/.gitlab-ci-mobile.yml
@@ -247,7 +247,9 @@ mobile_release_candidate_publish:
   rules:
     - !reference [.rule_templates, only_on_production_release]
   after_script: |
-    curl -X POST -H 'Content-Type: application/json' --data '{"channel": "#release-status", "branch": "'"$CI_COMMIT_REF_SLUG"'", "text":"The mobile release candidate \"'"$CI_COMMIT_BRANCH"'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")' has been updated to \"'"$CI_COMMIT_TITLE"'\" and is available for testing via:\n'"$CI_ENVIRONMENT_URL"'"}' "https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER"
+    if [ $CI_JOB_STATUS == 'success' ]; then
+      curl -X POST -H 'Content-Type: application/json' --data '{"channel": "#release-status", "branch": "'"$CI_COMMIT_REF_SLUG"'", "text":"The mobile release candidate \"'"$CI_COMMIT_BRANCH"'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")' has been updated to \"'"$CI_COMMIT_TITLE"'\" and is available for testing via:\n'"$CI_ENVIRONMENT_URL"'"}' "https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER"
+    fi
 
 mobile_release_publish:
   extends: .mobile_publish
@@ -263,7 +265,9 @@ mobile_release_publish:
   rules:
     - !reference [.rule_templates, manually_on_production_release]
   after_script: |
-    curl -X POST -H 'Content-Type: application/json' --data '{"channel": "#release-status", "branch": "'"$CI_COMMIT_REF_SLUG"'", "text":"The mobile release \"'"$CI_COMMIT_BRANCH"'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")' has been updated to \"'"$CI_COMMIT_TITLE"'\" and is published to the branch specific channel. You can find it at https://expo.dev/accounts/holistic-foundation/projects/projectholi/channels/\"'"$EXPO_PUBLISH_RELEASE_CHANNEL"'\" ."}' "https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER"
+    if [ $CI_JOB_STATUS == 'success' ]; then
+      curl -X POST -H 'Content-Type: application/json' --data '{"channel": "#release-status", "branch": "'"$CI_COMMIT_REF_SLUG"'", "text":"The mobile release \"'"$CI_COMMIT_BRANCH"'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")' has been updated to \"'"$CI_COMMIT_TITLE"'\" and is published to the branch specific channel. You can find it at https://expo.dev/accounts/holistic-foundation/projects/projectholi/channels/\"'"$EXPO_PUBLISH_RELEASE_CHANNEL"'\" ."}' "https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER"
+    fi
 
 mobile_release_build_android:
   extends: .mobile_build
@@ -317,7 +321,9 @@ mobile_release_submit_android:
     - !reference [.rule_templates, only_on_production_release]
   interruptible: false
   after_script: |
-    curl -X POST -H 'Content-Type: application/json' --data '{"channel": "#release-status", "branch": "'$CI_COMMIT_REF_SLUG'", "text":"The Android app for the release candidate \"'$CI_COMMIT_BRANCH'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")' has been updated to \"'"$CI_COMMIT_TITLE"'\" and was submitted to the Play Store."}' https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER
+    if [ $CI_JOB_STATUS == 'success' ]; then
+      curl -X POST -H 'Content-Type: application/json' --data '{"channel": "#release-status", "branch": "'$CI_COMMIT_REF_SLUG'", "text":"The Android app for the release candidate \"'$CI_COMMIT_BRANCH'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")' has been updated to \"'"$CI_COMMIT_TITLE"'\" and was submitted to the Play Store."}' https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER
+    fi
 
 mobile_release_submit_ios:
   needs: ['mobile_release_build_ios']
@@ -335,4 +341,6 @@ mobile_release_submit_ios:
     - !reference [.rule_templates, only_on_production_release]
   interruptible: false
   after_script: |
-    curl -X POST -H 'Content-Type: application/json' --data '{"channel": "#release-status", "branch": "'$CI_COMMIT_REF_SLUG'", "text":"The IOS app for the release candidate \"'$CI_COMMIT_BRANCH'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")' has been updated to \"'"$CI_COMMIT_TITLE"'\" and was submitted to the App Store."}' https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER
+    if [ $CI_JOB_STATUS == 'success' ]; then
+      curl -X POST -H 'Content-Type: application/json' --data '{"channel": "#release-status", "branch": "'$CI_COMMIT_REF_SLUG'", "text":"The IOS app for the release candidate \"'$CI_COMMIT_BRANCH'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")' has been updated to \"'"$CI_COMMIT_TITLE"'\" and was submitted to the App Store."}' https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER
+    fi
diff --git a/.gitlab-ci-web.yml b/.gitlab-ci-web.yml
index 7e23401e13..89b84caf63 100644
--- a/.gitlab-ci-web.yml
+++ b/.gitlab-ci-web.yml
@@ -297,10 +297,12 @@ web_release_candidate_deploy:
   rules:
     - !reference [.rule_templates, only_on_production_release]
   after_script: | # only wget is available in the terraform image
-    wget --header="Content-Type: application/json" \
-      --post-data='{"channel": "#release-status", "branch": "'$CI_COMMIT_REF_SLUG'", "text":"The web environment for the release candidate \"'$CI_COMMIT_REF_SLUG'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")'. has been updated to \"'"$CI_COMMIT_TITLE"'\". and is available and/or updated under:\nhttps://'"$(cat $UI_DOMAIN_PATH)"'\nIf the environment was deployed for the first time, availability might take 30 to 60 minutes due to SSL certificate rollout. Meanwhile, you will see a 'PR_END_OF_FILE_ERROR' in your browser.\nTo deploy this version to web production go to this Pipeline: '$CI_PIPELINE_URL'"}' \
-      --output-document - \
-      https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER
+    if [ $CI_JOB_STATUS == 'success' ]; then
+      wget --header="Content-Type: application/json" \
+        --post-data='{"channel": "#release-status", "branch": "'$CI_COMMIT_REF_SLUG'", "text":"The web environment for the release candidate \"'$CI_COMMIT_REF_SLUG'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")'. has been updated to \"'"$CI_COMMIT_TITLE"'\". and is available and/or updated under:\nhttps://'"$(cat $UI_DOMAIN_PATH)"'\nIf the environment was deployed for the first time, availability might take 30 to 60 minutes due to SSL certificate rollout. Meanwhile, you will see a 'PR_END_OF_FILE_ERROR' in your browser.\nTo deploy this version to web production go to this Pipeline: '$CI_PIPELINE_URL'"}' \
+        --output-document - \
+        https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER
+    fi
 
 web_release_candidate_destroy:
   extends: .web_destroy
@@ -325,10 +327,12 @@ web_release_deploy:
   rules:
     - !reference [.rule_templates, manually_on_production_release]
   after_script: | # only wget is available in the terraform image
-    wget --header="Content-Type: application/json" \
-      --post-data='{"channel": "#release-status", "branch": "'$CI_COMMIT_REF_SLUG'", "text":"The production web environment has been manually released from \"'$CI_COMMIT_REF_SLUG'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")'. It has been updated to \"'"$CI_COMMIT_TITLE"'\" and is available and/or updated under https://app.holi.social"}' \
-      --output-document - \
-      https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER
+    if [ $CI_JOB_STATUS == 'success' ]; then
+      wget --header="Content-Type: application/json" \
+        --post-data='{"channel": "#release-status", "branch": "'$CI_COMMIT_REF_SLUG'", "text":"The production web environment has been manually released from \"'$CI_COMMIT_REF_SLUG'\" for release '$(git describe --tags --abbrev=0|sed "s|release/||")'. It has been updated to \"'"$CI_COMMIT_TITLE"'\" and is available and/or updated under https://app.holi.social"}' \
+        --output-document - \
+        https://projectholi.rocket.chat/hooks/$ROCKETCHAT_HOOK_RELEASE_NOTIFIER
+    fi
 
 web_release_smoketest:
   needs: ['web_release_deploy']
-- 
GitLab