From bc627a6acad591f05e8b879a9388137859e10855 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Tue, 5 Mar 2024 15:25:16 +0100 Subject: build-support/php: move functions around (dry) --- .../php/hooks/composer-install-hook.sh | 21 +------------------ .../php/hooks/composer-repository-hook.sh | 21 +------------------ pkgs/build-support/php/hooks/php-script-utils.bash | 24 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/pkgs/build-support/php/hooks/composer-install-hook.sh b/pkgs/build-support/php/hooks/composer-install-hook.sh index f5c93a6e3d34e..edba0e5eec4e6 100644 --- a/pkgs/build-support/php/hooks/composer-install-hook.sh +++ b/pkgs/build-support/php/hooks/composer-install-hook.sh @@ -91,26 +91,7 @@ composerInstallBuildHook() { composerInstallCheckHook() { echo "Executing composerInstallCheckHook" - if ! composer validate --strict --no-ansi --no-interaction --quiet; then - if [ ! -z "${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 + checkComposerValidate echo "Finished composerInstallCheckHook" } diff --git a/pkgs/build-support/php/hooks/composer-repository-hook.sh b/pkgs/build-support/php/hooks/composer-repository-hook.sh index ffec58e552931..762e762761cc4 100644 --- a/pkgs/build-support/php/hooks/composer-repository-hook.sh +++ b/pkgs/build-support/php/hooks/composer-repository-hook.sh @@ -71,26 +71,7 @@ composerRepositoryBuildHook() { composerRepositoryCheckHook() { echo "Executing composerRepositoryCheckHook" - if ! composer validate --strict --no-ansi --no-interaction --quiet; then - if [ ! -z "${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 + checkComposerValidate echo "Finished composerRepositoryCheckHook" } diff --git a/pkgs/build-support/php/hooks/php-script-utils.bash b/pkgs/build-support/php/hooks/php-script-utils.bash index 163d9306f5f4a..60afacbed0af1 100644 --- a/pkgs/build-support/php/hooks/php-script-utils.bash +++ b/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,26 @@ setComposeRootVersion() { set -e } + +checkComposerValidate() { + if ! composer validate --strict --no-ansi --no-interaction; 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 +} -- cgit 1.4.1