php.buildComposerProject: improve workflow in case of missing composer.lock file

This commit is contained in:
Pol Dellaiera 2023-10-04 14:58:40 +02:00 committed by Yureka
parent dd104a90a8
commit 2b12e3efe3
2 changed files with 47 additions and 3 deletions

View file

@ -22,12 +22,34 @@ composerInstallConfigureHook() {
fi
if [[ ! -f "composer.lock" ]]; then
echo "No composer.lock file found, consider adding one to your repository to ensure reproducible builds."
composer \
--no-ansi \
--no-install \
--no-interaction \
${composerNoDev:+--no-dev} \
${composerNoPlugins:+--no-plugins} \
${composerNoScripts:+--no-scripts} \
update
mkdir -p $out
cp composer.lock $out/
echo
echo 'No composer.lock file found, consider adding one to your repository to ensure reproducible builds.'
echo "In the meantime, a composer.lock file has been generated for you in $out/composer.lock"
echo
echo 'To fix the issue:'
echo "1. Copy the composer.lock file from $out/composer.lock to the project's source:"
echo " cp $out/composer.lock <path>"
echo '2. Add the composerLock attribute, pointing to the copied composer.lock file:'
echo ' composerLock = ./composer.lock;'
echo
exit 1
fi
echo "Validating consistency between composer.lock and ${composerRepository}/composer.lock"
if ! @diff@ composer.lock "${composerRepository}/composer.lock"; then
if [[! @diff@ composer.lock "${composerRepository}/composer.lock"]]; then
echo
echo "ERROR: vendorHash is out of date"
echo

View file

@ -17,7 +17,29 @@ composerRepositoryConfigureHook() {
fi
if [[ ! -f "composer.lock" ]]; then
echo "No composer.lock file found, consider adding one to your repository to ensure reproducible builds."
composer \
--no-ansi \
--no-install \
--no-interaction \
${composerNoDev:+--no-dev} \
${composerNoPlugins:+--no-plugins} \
${composerNoScripts:+--no-scripts} \
update
mkdir -p $out
cp composer.lock $out/
echo
echo 'No composer.lock file found, consider adding one to your repository to ensure reproducible builds.'
echo "In the meantime, a composer.lock file has been generated for you in $out/composer.lock"
echo
echo 'To fix the issue:'
echo "1. Copy the composer.lock file from $out/composer.lock to the project's source:"
echo " cp $out/composer.lock <path>"
echo '2. Add the composerLock attribute, pointing to the copied composer.lock file:'
echo ' composerLock = ./composer.lock;'
echo
exit 1
fi