nixpkgs/pkgs/build-support/php/hooks/composer-repository-hook.sh
2023-09-13 15:00:03 +02:00

67 lines
1.8 KiB
Bash

declare composerHomeDir
declare composerLock
declare version
preConfigureHooks+=(composerRepositoryConfigureHook)
preBuildHooks+=(composerRepositoryBuildHook)
preCheckHooks+=(composerRepositoryCheckHook)
preInstallHooks+=(composerRepositoryInstallHook)
composerRepositoryConfigureHook() {
echo "Executing composerRepositoryConfigureHook"
if [[ -e "$composerLock" ]]; then
cp $composerLock composer.lock
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 \
--no-plugins \
--no-scripts \
update
echo "Using an autogenerated composer.lock file."
fi
echo "Finished composerRepositoryConfigureHook"
}
composerRepositoryBuildHook() {
echo "Executing composerRepositoryBuildHook"
mkdir -p repository
# Build the local composer repository
# The command 'build-local-repo' is provided by the Composer plugin
# nix-community/composer-local-repo-plugin.
COMPOSER_CACHE_DIR=/dev/null \
composer-local-repo-plugin --no-ansi build-local-repo -r repository
echo "Finished composerRepositoryBuildHook"
}
composerRepositoryCheckHook() {
echo "Executing composerRepositoryCheckHook"
composer validate --no-ansi --no-interaction
echo "Finished composerRepositoryCheckHook"
}
composerRepositoryInstallHook() {
echo "Executing composerRepositoryInstallHook"
mkdir -p $out
cp -ar repository/. $out/
# Copy the composer.lock files to the output directory, in case it has been
# autogenerated.
cp composer.lock $out/
echo "Finished composerRepositoryInstallHook"
}