From 27cd9216bdf1ba7310a2bd5ae35cb87d5b4e59a2 Mon Sep 17 00:00:00 2001 From: Simon Baese Date: Thu, 22 Aug 2024 19:19:44 +0900 Subject: [PATCH 1/4] Make composer manifest update callable from script (cherry picked from commit daf2a0aa10e4035873e5063ad6d8621caf134cd0) --- Plugin.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Plugin.php b/Plugin.php index 1179a74..1ecdf0a 100644 --- a/Plugin.php +++ b/Plugin.php @@ -16,11 +16,6 @@ */ class Plugin implements PluginInterface, EventSubscriberInterface { - /** - * @var \Composer\Composer $composer - */ - protected $composer; - /** * @param \Composer\Composer $composer * @param \Composer\IO\IOInterface $io @@ -29,8 +24,6 @@ public function activate(Composer $composer, IOInterface $io) { // Development: this makes symfony var-dumper work. // See https://github.com/composer/composer/issues/7911 // include './vendor/symfony/var-dumper/Resources/functions/dump.php'; - - $this->composer = $composer; } /** @@ -49,9 +42,10 @@ public static function getSubscribedEvents() { * * @param \Composer\EventDispatcher\Event $event */ - public function updateManifest(BaseEvent $event) { - $repositoryManager = $this->composer->getRepositoryManager(); + public static function updateManifest(BaseEvent $event) { + $repositoryManager = $event->getComposer()->getRepositoryManager(); $localRepository = $repositoryManager->getLocalRepository(); + $localRepository->reload(); $packages = $localRepository->getPackages(); // TODO: do we want to include the lock hash? Not sure it's useful, and it's @@ -80,6 +74,7 @@ public function updateManifest(BaseEvent $event) { $yaml = Yaml::dump($yaml_data); file_put_contents('composer-manifest.yaml', $yaml); + $event->getIO()->write('Composer manifest updated!'); } /** From 9c1fffb785112ca4a90e4de2c20567ac61f5dcfd Mon Sep 17 00:00:00 2001 From: Simon Baese Date: Sun, 25 Aug 2024 23:50:49 +0900 Subject: [PATCH 2/4] Add readme for renovate configuration --- README.md | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 24022c1..a86f484 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,46 @@ composer-manifest.yaml file in your project root. You should commit this to version control at the same time as you commit changes to composer.json and composer.lock to keep a history of changes. -### Integrations +## Integrations -With [Renovate](https://github.com/renovatebot/renovate), use the fileFilters -config option to ensure the manifest file is committed by the renovate bot. +### Renovate + +With [Renovate](https://github.com/renovatebot/renovate), use the post upgrade +tasks in the project-specific configuration to ensure that the manifest file is +committed by the renovate bot. Note that the composer script command must be +added to the allowed post upgrade commands in the global configuration. + +#### Project-specific configuration + +Add the following post upgrade tasks to the `renovate.json` file. See +[Configuration Options: postUpgradeTasks](https://docs.renovatebot.com/configuration-options/#postupgradetasks) for reference. + +```json +{ + "postUpgradeTasks": { + "commands": ["composer update-manifest"], + "fileFilters": ["composer-manifest.yaml"], + "executionMode": "branch" + } +} +``` + +Add the following script to the `composer.json` file. This way no extra +resources are used for other event listeners. + +```json +{ + "scripts": { + "update-manifest": "ComposerManifest\\Plugin::updateManifest" + } +} +``` +#### Global configuration + +See [Self-Hosted configuration options: allowedPostUpgradeCommands](https://docs.renovatebot.com/self-hosted-configuration/#allowedpostupgradecommands) for reference. + +```json +{ + allowedPostUpgradeCommands: ['^composer update-manifest$'] +} +``` From 57667e3d5d08736b005c3795c0ecbae4612d63ed Mon Sep 17 00:00:00 2001 From: Stephan Huber Date: Mon, 2 Sep 2024 17:59:18 +0200 Subject: [PATCH 3/4] Use locked repository instead of the local one --- Plugin.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Plugin.php b/Plugin.php index 1179a74..a91affb 100644 --- a/Plugin.php +++ b/Plugin.php @@ -16,11 +16,6 @@ */ class Plugin implements PluginInterface, EventSubscriberInterface { - /** - * @var \Composer\Composer $composer - */ - protected $composer; - /** * @param \Composer\Composer $composer * @param \Composer\IO\IOInterface $io @@ -29,8 +24,6 @@ public function activate(Composer $composer, IOInterface $io) { // Development: this makes symfony var-dumper work. // See https://github.com/composer/composer/issues/7911 // include './vendor/symfony/var-dumper/Resources/functions/dump.php'; - - $this->composer = $composer; } /** @@ -49,9 +42,8 @@ public static function getSubscribedEvents() { * * @param \Composer\EventDispatcher\Event $event */ - public function updateManifest(BaseEvent $event) { - $repositoryManager = $this->composer->getRepositoryManager(); - $localRepository = $repositoryManager->getLocalRepository(); + public static function updateManifest(BaseEvent $event) { + $localRepository = $event->getComposer()->getLocker()->getLockedRepository(true); $packages = $localRepository->getPackages(); // TODO: do we want to include the lock hash? Not sure it's useful, and it's @@ -80,6 +72,7 @@ public function updateManifest(BaseEvent $event) { $yaml = Yaml::dump($yaml_data); file_put_contents('composer-manifest.yaml', $yaml); + $event->getIO()->write('Composer manifest updated!'); } /** From 563b4552b697a2ac73d34911bb0ee8c1a68203e5 Mon Sep 17 00:00:00 2001 From: Stephan Maximilian Huber Date: Tue, 10 Sep 2024 13:53:06 +0200 Subject: [PATCH 4/4] Update README.md Clarify configuration for the case that the composer.json is not in the root-folder --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a86f484..79e55c7 100644 --- a/README.md +++ b/README.md @@ -43,11 +43,15 @@ Add the following post upgrade tasks to the `renovate.json` file. See { "postUpgradeTasks": { "commands": ["composer update-manifest"], - "fileFilters": ["composer-manifest.yaml"], + "fileFilters": ["**/composer-manifest.yaml"], "executionMode": "branch" } } ``` +Note: If your composer-file is located in a subfolder of your repository, +change the `commands`-line to sth like +`cd apps/drupal && composer update-manifest` -- postUgradeTasks are +executed at the root of the git-repository. Add the following script to the `composer.json` file. This way no extra resources are used for other event listeners. @@ -65,6 +69,6 @@ See [Self-Hosted configuration options: allowedPostUpgradeCommands](https://docs ```json { - allowedPostUpgradeCommands: ['^composer update-manifest$'] + allowedPostUpgradeCommands: ['composer update-manifest$'] } ```