├── .gitignore ├── CODEOWNERS ├── catalog-info.yaml ├── tests └── functional │ ├── confirm-install.bats │ └── remote-composer.bats ├── LICENSE ├── .github └── workflows │ └── ci.yml ├── .circleci ├── set-up-globals.sh └── config.yml ├── src └── Commands │ └── ComposerCommand.php ├── composer.json ├── CONTRIBUTING.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | tools 3 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @pantheon-systems/developer-experience 2 | -------------------------------------------------------------------------------- /catalog-info.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: backstage.io/v1alpha1 3 | kind: Component 4 | metadata: 5 | name: terminus-composer-plugin 6 | description: Auto-generated catalog info for pantheon-systems/terminus-composer-plugin 7 | annotations: 8 | backstage.io/techdocs-ref: dir:docs/ 9 | spec: 10 | type: tool 11 | lifecycle: mature 12 | owner: devx 13 | -------------------------------------------------------------------------------- /tests/functional/confirm-install.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # 4 | # confirm-install.bats 5 | # 6 | # Ensure that Terminus and the Composer plugin have been installed correctly 7 | # 8 | 9 | @test "confirm terminus version" { 10 | terminus --version 11 | } 12 | 13 | @test "get help on remote:composer command" { 14 | run terminus help remote:composer 15 | [[ $output == *"composer_command"* ]] 16 | [ "$status" -eq 0 ] 17 | } 18 | -------------------------------------------------------------------------------- /tests/functional/remote-composer.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # 4 | # remote-composer.bats 5 | # 6 | # Run the remote composer 7 | # 8 | 9 | @test "determine why symfony/console is required" { 10 | run terminus composer $TERMINUS_SITE.dev depends symfony/console 11 | [ "$status" -eq 0 ] 12 | [[ "$output" == *"drupal/core"* ]] 13 | [[ "$output" == *"drush/drush"* ]] 14 | } 15 | 16 | @test "look at licenses" { 17 | run terminus composer $TERMINUS_SITE.dev licenses 18 | [ "$status" -eq 0 ] 19 | [[ "$output" == *"GPL-2.0-or-later"* ]] 20 | [[ "$output" == *"MIT"* ]] 21 | } 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Pantheon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: PHP Compatibility 2 | on: 3 | push: 4 | 5 | jobs: 6 | phpcompatibility: 7 | runs-on: ubuntu-latest 8 | name: PHP Compatibility 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v2 12 | - name: PHPCompatibility 13 | uses: pantheon-systems/phpcompatibility-action@v1 14 | with: 15 | test-versions: 7.4- 16 | lint: 17 | runs-on: ${{ matrix.operating-system }} 18 | name: Lint checks - PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }} 19 | strategy: 20 | matrix: 21 | operating-system: [ 'macos-latest' ] 22 | php-versions: [ '7.4', '8.0', '8.2', '8.4' ] 23 | max-parallel: 3 24 | steps: 25 | - name: Checkout 26 | uses: actions/checkout@v3 27 | - name: Setup PHP with PECL extension 28 | uses: shivammathur/setup-php@v2 29 | with: 30 | php-version: ${{ matrix.php-versions }} 31 | extensions: gd, mbstring, zip, ssh2-1.3.1, pcov 32 | coverage: pcov 33 | ini-values: error_reporting=E_ALL 34 | - name: Full Composer Install 35 | run: composer install 36 | - name: Lint check 37 | run: composer lint 38 | - name: Deprecations check 39 | run: composer deprecations 40 | -------------------------------------------------------------------------------- /.circleci/set-up-globals.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #===================================================================================================================== 4 | # EXPORT needed environment variables 5 | # 6 | # Circle CI 2.0 does not yet expand environment variables so they have to be manually EXPORTed 7 | # Once environment variables can be expanded this section can be removed 8 | # See: https://discuss.circleci.com/t/unclear-how-to-work-with-user-variables-circleci-provided-env-variables/12810/11 9 | # See: https://discuss.circleci.com/t/environment-variable-expansion-in-working-directory/11322 10 | # See: https://discuss.circleci.com/t/circle-2-0-global-environment-variables/8681 11 | #===================================================================================================================== 12 | mkdir -p $(dirname $BASH_ENV) 13 | touch $BASH_ENV 14 | ( 15 | echo 'export PATH=$PATH:$HOME/bin' 16 | echo 'export TERMINUS_HIDE_UPDATE_MESSAGE=1' 17 | ) >> $BASH_ENV 18 | source $BASH_ENV 19 | 20 | set -ex 21 | 22 | TERMINUS_PLUGINS_DIR=.. terminus list -n remote 23 | 24 | set +ex 25 | echo "Test site is $TERMINUS_SITE" 26 | echo "Logging in with a machine token:" 27 | terminus auth:login -n --machine-token="$TERMINUS_TOKEN" 28 | terminus whoami 29 | touch $HOME/.ssh/config 30 | echo "StrictHostKeyChecking no" >> "$HOME/.ssh/config" 31 | git config --global user.email "$GIT_EMAIL" 32 | git config --global user.name "Circle CI" 33 | # Ignore file permissions. 34 | git config --global core.fileMode false 35 | -------------------------------------------------------------------------------- /src/Commands/ComposerCommand.php: -------------------------------------------------------------------------------- 1 | . -- 38 | * Runs the Composer command on the environment of 39 | */ 40 | public function composerCommand($site_env_id, array $composer_command) 41 | { 42 | $this->prepareEnvironment($site_env_id); 43 | 44 | return $this->executeCommand($composer_command); 45 | } 46 | 47 | /** 48 | * @inheritdoc 49 | */ 50 | protected function validateFramework($framework) 51 | { 52 | // no-op 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | defaults: &defaults 2 | docker: 3 | - image: quay.io/pantheon-public/terminus-plugin-test:4.x-php8.2 4 | working_directory: ~/work/terminus_plugin 5 | environment: 6 | BASH_ENV: ~/.bashrc 7 | TZ: "/usr/share/zoneinfo/America/Los_Angeles" 8 | TERM: dumb 9 | 10 | version: 2 11 | jobs: 12 | test: 13 | <<: *defaults 14 | steps: 15 | - checkout 16 | - add_ssh_keys 17 | - run: 18 | name: Set up environment 19 | command: ./.circleci/set-up-globals.sh 20 | - run: 21 | name: Check Terminus version 22 | command: terminus --version 23 | - run: 24 | name: Dependencies 25 | command: composer install 26 | - run: 27 | name: Lint 28 | command: composer lint 29 | - run: 30 | name: Unit 31 | command: composer unit 32 | - run: 33 | name: Install plugin 34 | command: terminus self:plugin:install /home/tester/work/terminus_plugin/ 35 | - run: 36 | name: Functional 37 | command: composer functional 38 | code-style: 39 | <<: *defaults 40 | steps: 41 | - checkout 42 | - run: 43 | name: Set up environment 44 | command: ./.circleci/set-up-globals.sh 45 | - run: 46 | name: Style 47 | command: composer cs 48 | 49 | workflows: 50 | version: 2 51 | build_test: 52 | jobs: 53 | - test 54 | - code-style 55 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pantheon-systems/terminus-composer-plugin", 3 | "description": "Composer - A Terminus plugin for running Composer commands on a Pantheon site", 4 | "type": "terminus-plugin", 5 | "license": "MIT", 6 | "autoload": { 7 | "psr-4": { "Pantheon\\TerminusComposer\\": "src" } 8 | }, 9 | "extra": { 10 | "terminus": { 11 | "compatible-version": "^3 || ^4" 12 | } 13 | }, 14 | "scripts": { 15 | "cs": "phpcs --standard=PSR2 -n src", 16 | "cbf": "phpcbf --standard=PSR2 -n src", 17 | "lint": "find src -name '*.php' -print0 | xargs -0 -n1 php -l", 18 | "deprecations": "find src -name '*.php' -print0 | xargs -0 -n1 php -l 2>&1 >/dev/null | tee /tmp/deprecations ; [ ! -s /tmp/deprecations ]", 19 | "unit": "phpunit --colors=always tests", 20 | "functional": "TERMINUS_PLUGINS_DIR=.. PATH=tools/bin:$PATH bats -p -t tests/functional", 21 | "install-bats": "if [ ! -f tools/bin/bats ] ; then git clone https://github.com/sstephenson/bats.git tools/bats; tools/bats/install.sh tools; fi", 22 | "install-phpcs": "mkdir -p tools/phpcs && cd tools/phpcs && COMPOSER_BIN_DIR=../../vendor/bin composer require squizlabs/php_codesniffer:^2.7", 23 | "install-phpunit": "mkdir -p tools/phpunit && cd tools/phpunit && COMPOSER_BIN_DIR=../../vendor/bin composer require phpunit/phpunit:^6", 24 | "install-tools": [ 25 | "@install-bats", 26 | "@install-phpcs", 27 | "@install-phpunit" 28 | ], 29 | "test": [ 30 | "@lint", 31 | "@functional", 32 | "@cs" 33 | ] 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | Pull requests to this project are welcome and encouraged. 4 | 5 | - Please ensure that all code conforms to PSR-2 conventions. `composer cbf` will fix many code style errors. 6 | - Run the unit tests before submitting a pull request (or fix any test failures after submission). 7 | - As new tests to cover new functionality as needed. 8 | 9 | ## Testing 10 | The preconditions to running tests locally are: 11 | 12 | - Run 'composer install' if your local working copy does not have a `vendor` directory yet. 13 | - Install Terminus 1.x, and ensure it is available on your PATH as `terminus` 14 | - Export the environment variable TERMINUS_SITE to point at a test site. 15 | - Run `terminus auth:login` 16 | 17 | Once that is done, use `composer test` to run the test suite. This will install the test runner, run the tests, and check the sources for PSR-2 compliance. 18 | 19 | ## Adding tests 20 | 21 | This project uses BATS, a shell-script testing framework, to manage functional tests for this project. BATS allows you to write tests with simple shell scripts. See the [documentation on writing BATS tests](https://github.com/sstephenson/bats#writing-tests) for more information. 22 | 23 | ## Seting up testing for your own Terminus plugin 24 | 25 | If you'd like to copy the test scripts here for use with your own Terminus plugin, follow the steps below: 26 | 27 | - Copy the circle.yml file. No changes should be necessary. 28 | - Copy the `require-dev` and `scripts` section from composer.json to your own project. Again, no changes should be necessary. 29 | - Add the contents of the .gitignore file to your .gitignore. 30 | - Duplicate the `tests` directory, and customize the tests to suite your plugin. 31 | 32 | You will also need to configure Circle CI to run your tests. In the Circle CI settings, set up the following environment variables: 33 | 34 | - TERMINUS_SITE: The name of a scratch Pantheon site to run tests against. 35 | - TERMINUS_TOKEN: A Pantheon machine token that has access to the test site. 36 | 37 | You will also need to create an ssh key pair, and add the private key to Circle CI (leave the "Hostname" field empty), and add the public key to your account on Pantheon. 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Terminus Composer Plugin 2 | 3 | [![CircleCI](https://circleci.com/gh/pantheon-systems/terminus-composer-plugin.svg?style=shield)](https://circleci.com/gh/pantheon-systems/terminus-composer-plugin) 4 | [![Actively Maintained](https://img.shields.io/badge/Pantheon-Actively_Maintained-yellow?logo=pantheon&color=FFDC28)](https://pantheon.io/docs/oss-support-levels#actively-maintained-support) 5 | 6 | 7 | Terminus Plugin to run [Composer](https://getcomposer.org/) commands on [Pantheon](https://www.pantheon.io) sites. 8 | 9 | Adds a command 'composer' to Terminus 1.x, 2.x or 3.x which you can use just like 'drush' or 'wp'. 10 | 11 | This project is a simplified version of the original [Terminus Composer Plugin](https://github.com/rvtraveller/terminus-composer) by Brian Thompson. 12 | 13 | ## Configuration 14 | 15 | This plugin should only be used with sites that are managed by Composer. The recommended upstreams are: 16 | 17 | - [WordPress](https://github.com/pantheon-upstreams/wordpress-project) 18 | - [Drupal 9](https://github.com/pantheon-upstreams/drupal-project) 19 | 20 | This plugin may also be used with "Build Tools" and "No CI Workflow" sites that were started with one of the following template projects: 21 | 22 | - WordPress: [Advanced WordPress on Pantheon](https://github.com/ataylorme/Advanced-WordPress-on-Pantheon) 23 | - Drupal 8: [Example Drops-8 Composer](https://github.com/pantheon-systems/example-drops-8-composer) 24 | - Drupal 7: [Example Drops-7 Composer](https://github.com/pantheon-systems/example-drops-7-composer) 25 | 26 | Using Composer to manage standard sites on Pantheon not started with these upstreams (or a similar variant thereof) is not recommended. Using with Drupal 8.8 on the [drops-8](https://github.com/pantheon-systems/drops-8) will produce a working site, but will make future dashboard updates difficult. Using with sites based on the [Standard non-Composer Pantheon WordPress upstream](https://github.com/pantheon-systems/wordpress), or Drupal versions prior to 8.8 is likely to break the site. 27 | 28 | ## Examples 29 | 30 | * `terminus composer my-script` 31 | * `terminus composer my-site.dev -- config repositories.drupal composer https://packages.drupal.org/8` 32 | * `terminus composer my-site.dev -- require drupal/media` 33 | * `terminus composer my-site.dev -- update` 34 | 35 | ## Installation 36 | 37 | ### Installing via Terminus 3 38 | `terminus self:plugin:install pantheon-systems/terminus-composer-plugin` 39 | 40 | On older versions of Terminus: 41 | ``` 42 | mkdir -p ~/.terminus/plugins 43 | composer create-project --no-dev -d ~/.terminus/plugins pantheon-systems/terminus-composer-plugin:~1 44 | ``` 45 | 46 | ## Help 47 | Run `terminus help composer` for help. 48 | --------------------------------------------------------------------------------