Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it work with renovate #20

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
*/
class Plugin implements PluginInterface, EventSubscriberInterface {

/**
* @var \Composer\Composer $composer
*/
protected $composer;

/**
* @param \Composer\Composer $composer
* @param \Composer\IO\IOInterface $io
Expand All @@ -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;
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -80,6 +72,7 @@ public function updateManifest(BaseEvent $event) {

$yaml = Yaml::dump($yaml_data);
file_put_contents('composer-manifest.yaml', $yaml);
$event->getIO()->write('<info>Composer manifest updated!</info>');
}

/**
Expand Down
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,50 @@ 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"
}
}
```
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.

```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$']
}
```