build-support/php: add composerStrictValidation attribute

Set to `true` by default
This commit is contained in:
Pol Dellaiera 2023-10-20 23:36:26 +02:00
parent 921e3c16cc
commit 46a7c4cade
No known key found for this signature in database
GPG Key ID: D476DFE9C67467CA
4 changed files with 44 additions and 2 deletions

View File

@ -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";

View File

@ -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";

View File

@ -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"
}

View File

@ -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"
}