2017 © Pedro Peláez
 

library drupal_ti

Drupal - Travis Integration

image

burdamagazinorg/drupal_ti

Drupal - Travis Integration

  • Monday, December 11, 2017
  • by dbosen
  • Repository
  • 4 Watchers
  • 0 Stars
  • 39 Installations
  • Shell
  • 0 Dependents
  • 0 Suggesters
  • 43 Forks
  • 0 Open issues
  • 21 Versions
  • 3 % Grown

The README.md

drupal_ti - Travis Integration for Drupal modules

Build Status, (*1)

Versions

Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

Welcome!

Welcome and thanks for trying drupal_ti!, (*3)

This will make it simple to use travis to test your drupal modules with simpletest and phpunit tests., (*4)

All you need is to push your drupal.org repository to Github, setup the module below, login to travis-ci.org, setup the repo and you are up and running in no time., (*5)

Setup

Copy .travis.yml.dist to your root folder as .travis.yml and customize the DRUPAL_TI_MODULE_NAME global environment variable to match the name of your module., (*6)

You will also need to activate one matrix option, based on if you have support for Simpletest, PHPUnit, Behat or all together:, (*7)

env:
  matrix:
    # [[[ SELECT ANY OR MORE OPTIONS ]]]
    - DRUPAL_TI_RUNNERS="phpunit" 
    - DRUPAL_TI_RUNNERS="phpunit simpletest behat" 

This example would run phpunit as one matrix runner, which gives you results fast, then phpunit, simpletest and behat as the slow runner., (*8)

If you want to run drupal_ti with a Drupal-8 module, then you need to use:, (*9)

- DRUPAL_TI_ENVIROMENT="drupal-8"

Using a different tests/ directory.

If your tests/ and composer.json are not in tests/ directory you will want to change:, (*10)

before_install:
# Comment this line for different directories, e.g. composer in the root.
#  - cd ./tests

How does it work

drupal_ti provides a drupal-ti command, which is then called with each stage of travis-ci (e.g. install, before_script, ...)., (*11)

By providing different runners in runners/simpletest or runners/phpunit/ the corresponding scripts are executed (e.g. runners/phpunit/script.sh)., (*12)

Also diffent environments are included from environments/$DRUPAL_TI_ENVIRONMENT.sh, which makes it possible to distinguish easily between Drupal 7 and 8., (*13)

This gives you a modular travis experience and such the scripts can be very generic., (*14)

Drupal is installed in $TRAVIS_BUILD_DIR/drupal_travis/drupal and drush is available after before_script stage., (*15)

How to customize the default behavior

By using, (*16)

- DRUPAL_TI_SCRIPT_DIR_BEFORE="./drupal_ti/before"
- DRUPAL_TI_SCRIPT_DIR_AFTER="./drupal_ti/after"

you can define your own scripts from your base directory, and drupal_ti will call them before and after your main scripts., (*17)

This is useful to change default environment variables, e.g. environments/drupal-7.sh defines, (*18)

export DRUPAL_TI_DRUSH_VERSION="drush/drush:6.*"

but you might want a different version and also override the drupal_ti_install_drupal function (as core-quick-drupal command needs drush 6)., (*19)

Theoretically you can even define multiple by just seperating them with a space or installed via composer - the possibilities are endless :)., (*20)

Example:, (*21)

- DRUPAL_TI_SCRIPT_DIR_BEFORE="./drupal_ti/before ./vendor/lionsad/drupal_ti_base_cool/drupal_ti/before"
- DRUPAL_TI_SCRIPT_DIR_AFTER="./drupal_ti/after  ./vendor/lionsad/drupal_ti_base_cool/drupal_ti/after"

Adding module dependencies from Github repositories

Your module may have several dependencies that are not hosted on Drupal.org. These modules can be added using a custom script and including them in the .travis.yml file., (*22)

In .travis.yml you will have a section before_script. The default command here installs drupal and the module we are testing. We can add a command drupal-ti --include [script]. This command will load the script first and then run the default drupal-ti before_script command., (*23)

.travis.yml

before_script:
  # We run our script to add module dependencies
  # This uses git clone over HTTPS because the modules don't currently
  # exist on drupal.org.
  - drupal-ti --include drupal_ti/before/before_script.sh
  - drupal-ti before_script

The script path is relative to our /tests directory since we moved to that default directory during the before_install process., (*24)

We can now create our custom script as follows,, (*25)

/tests/drupal_ti/before/before_script.sh

#!/bin/bash

# Add an optional statement to see that this is running in Travis CI.
echo "running drupal_ti/before/before_script.sh"

set -e $DRUPAL_TI_DEBUG

# Ensure the right Drupal version is installed.
# The first time this is run, it will install Drupal.
# Note: This function is re-entrant.
drupal_ti_ensure_drupal

# Change to the Drupal directory
cd "$DRUPAL_TI_DRUPAL_DIR"

# Create the the module directory (only necessary for D7)
# For D7, this is sites/default/modules
# For D8, this is modules
mkdir -p "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_MODULES_PATH"
cd "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_MODULES_PATH"

# Manually clone the dependencies
git clone --depth 1 https://github.com/my-project/my-dependency.git
# or with a different branch
git clone --depth 1 --branch 8.x-1.x https://github.com/my-project/my-dependency.git

The directory /tests/drupal_ti/before/ can also be used to add auto-discovered scripts using a more complex pattern /tests/before/runners/[runner]/[command].sh. This will, however be limited to a specific runner, while the above include pattern will run for all runners., (*26)

Script with Composer Manager

Composer manager is a popular dependency and one that requires extra work in order to be set up., (*27)

#!/bin/bash

# Add an optional statement to see that this is running in Travis CI.
echo "running drupal_ti/before/before_script.sh"

set -e $DRUPAL_TI_DEBUG

# Ensure the right Drupal version is installed.
# The first time this is run, it will install Drupal.
# Note: This function is re-entrant.
drupal_ti_ensure_drupal

# Change to the Drupal directory
cd "$DRUPAL_TI_DRUPAL_DIR"

# Create the the module directory (only necessary for D7)
# For D7, this is sites/default/modules
# For D8, this is modules
mkdir -p "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_MODULES_PATH"
cd "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_MODULES_PATH"

# Manually clone the dependencies
git clone --depth 1 --branch 8.x-1.x http://git.drupal.org/project/composer_manager.git

# Initialize composer manage
php "$DRUPAL_TI_DRUPAL_DIR/$DRUPAL_TI_MODULES_PATH/composer_manager/scripts/init.php"

# Ensure the module is linked into the code base and enabled.
# Note: This function is re-entrant.
drupal_ti_ensure_module_linked

# Update composer
cd "$DRUPAL_TI_DRUPAL_DIR"
composer drupal-rebuild
composer install --prefer-source

Contributions

Contributions are welcome., (*28)

Drush

For your convenience the 'drush site-set' command is set for the Drupal installation, so any Drush commands triggered in your own scripts will be run against the test Drupal instance., (*29)

The Versions

11/12 2017

dev-master

9999999-dev https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

18/10 2016

dev-php-fpm-hhvm-serve-everywhere

dev-php-fpm-hhvm-serve-everywhere https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

11/09 2016

dev-revert-90-patch-2

dev-revert-90-patch-2 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

25/06 2016

1.4.4

1.4.4.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

28/04 2016

1.4.3

1.4.3.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

13/12 2015

dev-fix-kernel-test-base

dev-fix-kernel-test-base https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

04/10 2015

1.4.2

1.4.2.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

29/07 2015

dev-use-hhvm-serve-for-all

dev-use-hhvm-serve-for-all https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

25/07 2015

1.4.1

1.4.1.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

18/07 2015

1.4.0

1.4.0.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

15/07 2015

1.3.0

1.3.0.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

13/07 2015

1.2.1

1.2.1.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

09/12 2014

1.2.0

1.2.0.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

03/12 2014

1.1.6

1.1.6.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

03/12 2014

1.1.5

1.1.5.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

03/12 2014

1.1.4

1.1.4.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

03/12 2014

1.1.3

1.1.3.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

03/12 2014

1.1.2

1.1.2.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

01/12 2014

1.1.1

1.1.1.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

30/11 2014

1.1.0

1.1.0.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz

29/11 2014

1.0.0

1.0.0.0 https://github.com/LionsAd/drupal_ti

Drupal - Travis Integration

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.0

 

by Fabian Franz