about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/php/hooks/php-script-utils.bash
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/build-support/php/hooks/php-script-utils.bash')
-rw-r--r--nixpkgs/pkgs/build-support/php/hooks/php-script-utils.bash45
1 files changed, 45 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/build-support/php/hooks/php-script-utils.bash b/nixpkgs/pkgs/build-support/php/hooks/php-script-utils.bash
index 163d9306f5f4..9b5978865634 100644
--- a/nixpkgs/pkgs/build-support/php/hooks/php-script-utils.bash
+++ b/nixpkgs/pkgs/build-support/php/hooks/php-script-utils.bash
@@ -1,4 +1,5 @@
 declare version
+declare composerStrictValidation
 
 setComposeRootVersion() {
     set +e # Disable exit on error
@@ -10,3 +11,47 @@ setComposeRootVersion() {
 
     set -e
 }
+
+checkComposerValidate() {
+    if ! composer validate --strict --no-ansi --no-interaction --quiet --no-check-all --no-check-lock; then
+        if [ "1" == "${composerStrictValidation-}" ]; then
+            echo
+            echo -e "\e[31mERROR: composer files validation failed\e[0m"
+            echo
+            echo -e '\e[31mThe validation of the composer.json failed.\e[0m'
+            echo -e '\e[31mMake sure that the file composer.json is valid.\e[0m'
+            echo
+            exit 1
+        else
+            echo
+            echo -e "\e[33mWARNING: composer files validation failed\e[0m"
+            echo
+            echo -e '\e[33mThe validation of the composer.json failed.\e[0m'
+            echo -e '\e[33mMake sure that the file composer.json is valid.\e[0m'
+            echo
+            echo -e '\e[33mThis check is not blocking, but it is recommended to fix the issue.\e[0m'
+            echo
+        fi
+    fi
+
+    if ! composer validate --strict --no-ansi --no-interaction --quiet --no-check-all --check-lock; then
+        if [ "1" == "${composerStrictValidation-}" ]; then
+            echo
+            echo -e "\e[31mERROR: composer files validation failed\e[0m"
+            echo
+            echo -e '\e[31mThe validation of the composer.json and composer.lock failed.\e[0m'
+            echo -e '\e[31mMake sure that the file composer.lock is consistent with composer.json.\e[0m'
+            echo
+            exit 1
+        else
+            echo
+            echo -e "\e[33mWARNING: composer files validation failed\e[0m"
+            echo
+            echo -e '\e[33mThe validation of the composer.json and composer.lock failed.\e[0m'
+            echo -e '\e[33mMake sure that the file composer.lock is consistent with composer.json.\e[0m'
+            echo
+            echo -e '\e[33mThis check is not blocking, but it is recommended to fix the issue.\e[0m'
+            echo
+        fi
+    fi
+}