Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

An Example Repository to Build Drupal with Composer on Travis

Parent Feed: 

A robust Continuous Integration system with good test coverage is the best way to ensure that your project remains maintainable; it is also a great opportunity to enhance your development workflow with Composer. Composer is a dependency management system that collects and organizes all of the software that your project needs in order to run. 

Using Composer to manage the modules and themes used in your Drupal site offers many benefits. Your project Git repository remains very light, containing only the files customized for your project, and your autoload file is managed for you, making it easy to start using code written with generic php classes, either custom to your project, or provided via Packagist. In order to take advantage of these capabilities of Composer, though, it is necessary to add a build step to your development workflow. Composer will download all of the components needed for your project and generate your autoload file when you run composer install or composer update. However, it requires a bit of planning to figure out how this step should integrate into your existing processes. Which components should be committed to Git, and which should be ignored? How does this fit into the Dev / Test / Live workflow?

The Travis Continuous Integration service offers a framework wherein these questions can be resolved. Travis is just one of many services that provides the capability to automatically rebuild and test your software every time a change is committed to your repository. Travis is popular because it is easy to configure via a .travis.yml file committed to the root of your repository, and it is free to test public GitHub repositories. Getting started with Composer, Behat and Drupal using Travis CI is now easier than ever—just enter the following composer command:

composer create-project pantheon-systems/example-drupal7-travis-composer my-project

This will clone the example-drupal7-travis-composer project from our GitHub repository, set up your root project files, and commit it all to a local Git repository. From there, all you need to do is customize these files to suit your Drupal project.

Existing Drupal sites can be converted with the help of the Drush composer-generate command, which can quickly populate the requires section of your composer.json file. The rest of the steps are clearly documented in the pantheon-systems/travis-scripts project.

Once you follow these instructions, you’ll have a Drupal project that:

  • Does not store any core or contrib project files in your repository

  • Builds via composer install in Travis CI on every commit

  • Tests via Behat after every successful build

  • Pushes to a prepared Pantheon environment after every successful test

The last step is completely optional; we’ll be covering this in a future blog post. The rest of the steps will work fine, even if you haven’t set up a free Pantheon for Agencies account. If you are on Pantheon, though, your site will be ready to be deployed to the Test and Live environments with the click of a button, as soon as it is ready.

If you are not very familiar with the concept of using Composer to manage your Drupal projects, see the Composer Tools and Frameworks presentation I did with Doug Dobrzynski at DrupalCon LA.

Topics Development, Drupal Planet, Drupal
Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web