From 46a7c4cade9d3ac19650341a5b9de31fd6bd83d8 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Fri, 20 Oct 2023 23:36:26 +0200 Subject: [PATCH] build-support/php: add `composerStrictValidation` attribute Set to `true` by default --- .../php/build-composer-project.nix | 2 ++ .../php/build-composer-repository.nix | 1 + .../php/hooks/composer-install-hook.sh | 21 +++++++++++++++++- .../php/hooks/composer-repository-hook.sh | 22 ++++++++++++++++++- 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/php/build-composer-project.nix b/pkgs/build-support/php/build-composer-project.nix index d614ca01eb71..778aa35fa6a5 100644 --- a/pkgs/build-support/php/build-composer-project.nix +++ b/pkgs/build-support/php/build-composer-project.nix @@ -13,6 +13,7 @@ let composerNoDev = previousAttrs.composerNoDev or true; composerNoPlugins = previousAttrs.composerNoPlugins or true; composerNoScripts = previousAttrs.composerNoScripts or true; + composerStrictValidation = previousAttrs.composerStrictValidation or true; nativeBuildInputs = (previousAttrs.nativeBuildInputs or [ ]) ++ [ composer @@ -69,6 +70,7 @@ let composerNoDev = previousAttrs.composerNoDev or true; composerNoPlugins = previousAttrs.composerNoPlugins or true; composerNoScripts = previousAttrs.composerNoScripts or true; + composerStrictValidation = previousAttrs.composerStrictValidation or true; }; COMPOSER_CACHE_DIR="/dev/null"; diff --git a/pkgs/build-support/php/build-composer-repository.nix b/pkgs/build-support/php/build-composer-repository.nix index 9487b61e16cb..5b31f86e61cf 100644 --- a/pkgs/build-support/php/build-composer-repository.nix +++ b/pkgs/build-support/php/build-composer-repository.nix @@ -32,6 +32,7 @@ let composerNoDev = previousAttrs.composerNoDev or true; composerNoPlugins = previousAttrs.composerNoPlugins or true; composerNoScripts = previousAttrs.composerNoScripts or true; + composerStrictValidation = previousAttrs.composerStrictValidation or true; name = "${previousAttrs.pname}-${previousAttrs.version}-composer-repository"; diff --git a/pkgs/build-support/php/hooks/composer-install-hook.sh b/pkgs/build-support/php/hooks/composer-install-hook.sh index 3326f99b6dd4..6fe1c4e5f7dd 100644 --- a/pkgs/build-support/php/hooks/composer-install-hook.sh +++ b/pkgs/build-support/php/hooks/composer-install-hook.sh @@ -107,7 +107,26 @@ composerInstallBuildHook() { composerInstallCheckHook() { echo "Executing composerInstallCheckHook" - composer validate --no-ansi --no-interaction + 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 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 d8f204e5df2f..03783d9d639c 100644 --- a/pkgs/build-support/php/hooks/composer-repository-hook.sh +++ b/pkgs/build-support/php/hooks/composer-repository-hook.sh @@ -3,6 +3,7 @@ declare version declare composerNoDev declare composerNoPlugins declare composerNoScripts +declare composerStrictValidation preConfigureHooks+=(composerRepositoryConfigureHook) preBuildHooks+=(composerRepositoryBuildHook) @@ -65,7 +66,26 @@ composerRepositoryBuildHook() { composerRepositoryCheckHook() { echo "Executing composerRepositoryCheckHook" - composer validate --no-ansi --no-interaction + 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 echo "Finished composerRepositoryCheckHook" }