hgraca/composer-system-requirements-plugin

A composer plugin to manage system dependencies.

v1.0.0 2023-04-03 20:38 UTC

This package is auto-updated.

Last update: 2024-03-30 00:26:58 UTC


README

build status coverage report

This is a composer plugin that will check for requirements at the OS level itself, for example checking if Bash is installed and at a version above 5.0.

How to use

Install and allow the plugin

composer require "hgraca/composer-system-requirements-plugin"
{
  "name": "hgraca/some-project",
  "type": "project",
  "require": {
    "hgraca/composer-system-requirements-plugin": "^1.0"
  },
  "config": {
    "allow-plugins": {
      "hgraca/composer-system-requirements-plugin": true
    }
  }
}

Configure the requirements

At the moment of this writing, there is only one built in requirement, bash, which is validated by the class in src/Package/RequirementValidator/BashRequirementValidator.php.

If/when more requirements validators are added, you can find them in the same location.

The system requirements can be configured as:

{
  "name": "hgraca/dummy-shell-project-1",
  "type": "project",
  "extra": {
    "hgraca/composer-system-requirements-plugin": {
      "require": {
        "bash": "^5.1"
      }
    }
  }
}

Create your own validators

Your validators need to implement the interface \Hgraca\ComposerSystemRequirementsPlugin\Package\RequirementValidator\RequirementValidatorInterface.

For an example, see src/Package/RequirementValidator/BashRequirementValidator.php.

Add your custom requirements validators

{
  "name": "hgraca/dummy-shell-project-1",
  "type": "project",
  "extra": {
    "hgraca/composer-system-requirements-plugin": {
      "require": {
        "bash": "^5.1"
      },
      "validators": [
        "MyVendor\\MyProject\\MyValidatorClass"
      ]
    }
  }
}

A working example

For a working example, please check tests/PluginTestPlayground.

Feel free to run any of the following:

export COMPOSER="composer_with_successful_root_requirement-run_on_shell.json" && composer -d tests/PluginTestPlayground/TestProject install
export COMPOSER="composer_with_failed_root_requirement-run_on_shell.json" && composer -d tests/PluginTestPlayground/TestProject install

How to run

Using local PHP (8.2):

  • Install the dependencies with composer install;
  • The tests can be run with composer test;
  • To list all custom scripts run composer run-script --list.

Using Docker:

  • Change PHP and xdebug configs in ./build;
  • Install the dependencies with docker compose -f ./build/docker-compose.yaml run app composer install;
  • The tests can be run with composer docker-test;
  • To list all custom scripts run docker compose -f ./build/docker-compose.yaml run app composer run-script --list.

Other commands

  • composer git-bundle: create a git bundle
  • git clone -b main composer-system-requirements-plugin.gitbundle composer-system-requirements-plugin: recreate the repository from the git bundle

Author

Herberto Graca