Last active
January 20, 2023 09:23
-
-
Save iamEAP/8855842 to your computer and use it in GitHub Desktop.
Template for integrating Travis-CI and Pantheon Multidev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
language: php | |
# | |
# Important to note, this is the version of PHP used to run this build, not the | |
# one used to run your Drupal installation. Ensure compatibility with the Drush | |
# and Terminus versions you're using for this build. | |
# | |
php: | |
- 5.3 | |
# | |
# Travis/Pantheon integration requires an RSA key that at least has read access | |
# to your GitHub repo and write access to Pantheon's git repo. Create a user on | |
# both systems with the most restricted access, given the aforementioned | |
# constraints. Then, for the given user, generate and load a public key to both | |
# GitHub/Pantheon. Follow instructions from Travis-CI on using this new key. | |
# | |
# Keep the Pantheon account e-mail address and password handy, you'll need it | |
# below in env.global. | |
# | |
# http://docs.travis-ci.com/user/travis-pro/ | |
# https://help.github.com/articles/generating-ssh-keys | |
# | |
source_key: INSERT_KEY_HERE | |
env: | |
global: | |
# Your Pantheon site's UUID (e.g. from your dashboard URL) | |
- PUUID='aaaaaaaa-0000-bbbb-1111-cccccccccccc' | |
# Your Pantheon site's name. | |
- PNAME='site-name' | |
# The Pantheon environment name from which Multidev DB/files will be pulled. | |
# Probably one of: dev, test, live. | |
- PSOURCE='test' | |
# | |
# PEMAIL environment variable: represents the Pantheon account e-mail with | |
# access to this site. Used to authenticate to Pantheon via Terminus. You | |
# must cd to your project root and run: | |
# | |
# travis encrypt PEMAIL='[email protected]' --add env.global | |
# | |
# Which will eventually look something like the key below. | |
# See: http://docs.travis-ci.com/user/build-configuration/#Secure-environment-variables | |
# | |
- secure: "encrypted_email_value_here" | |
# | |
# PPASS environment variable: represents the Pantheon account password for | |
# the above encrypted e-mail address. Run: | |
# | |
# travis encrypt PPASS='my_account_password' --add env.global | |
# | |
- secure: "encrypted_password_value_here" | |
# Generate a random branch / multidev name, prefixed with "ci" followed | |
# by the Travis build number. Note, due to Pantheon multidev environment | |
# name limits, builds will start failing at #100000. | |
- PSITE=$(cat /dev/urandom | tr -cd 'a-z0-9' | head -c 4) | |
- PSITE="ci$TRAVIS_BUILD_NUMBER-$PSITE" | |
# You can use $PHOST as a reference to the resulting multidev hostname. | |
- PHOST="https://$PSITE-$PNAME.gotpantheon.com" | |
install: | |
# Dynamic hosts through Pantheon mean constantly checking interactively | |
# that we mean to connect to an unknown host. We ignore those here. | |
- echo "StrictHostKeyChecking no" > ~/.ssh/config | |
# Install Drush. | |
- composer global require drush/drush:6.2.0 | |
- export PATH="$HOME/.composer/vendor/bin:$PATH" | |
# Install Terminus. | |
- git clone https://github.com/pantheon-systems/terminus.git $HOME/.drush/terminus | |
- cd $HOME/.drush/terminus | |
- composer update --no-dev | |
- drush cc drush | |
# Install additional test dependencies here (like Casper, Behat, etc). | |
before_script: | |
# Authenticate with Pantheon via Terminus. | |
- drush pauth $PEMAIL --password=$PPASS | |
# Add Pantheon as a remote to our repo and force push to it. | |
- cd $TRAVIS_BUILD_DIR | |
- git checkout -b $PSITE | |
- git remote add pantheon ssh://[email protected].$PUUID.drush.in:2222/~/repository.git | |
- git push --force pantheon $PSITE | |
# Create a new Pantheon environment using the above branch. | |
- drush psite-ecreate $PUUID $PSITE --source=$PSOURCE || true | |
# Update our drush aliases file. | |
- drush paliases | |
- drush cc drush | |
# We cannot be in a Drupal directory to run aliased drush commands. | |
- cd $HOME | |
# When new modules are added to the codebase, updb can sometimes fail (thus | |
# causing a failed build) because the system table and modules are out of | |
# sync. We get around this by clearing all caches before attempting anything. | |
# The "|| true" works around issues where Views and Block conflict during | |
# cache clears / block rehashes. | |
- drush @pantheon.$PNAME.$PSITE cc all --strict=0 || true | |
# Run all available updates as if deploying. For now, append the | |
# --strict=0 option for Drush 6.x compatibility on Pantheon. | |
- drush @pantheon.$PNAME.$PSITE updb -y --strict=0 | |
# Enable additional test dependencies here, like SimpleTest. | |
- drush @pantheon.$PNAME.$PSITE en simpletest -y --strict=0 | |
# If you're using SimpleTest, you'll want to disable verbose logging. This | |
# ensures no false build failures from file write errors. | |
- drush @pantheon.$PNAME.$PSITE vset -y simpletest_verbose 0 --strict=0 | |
script: | |
# | |
# This is where you run your tests, be they SimpleTest, Casper, Behat, | |
# or otherwise. Here's a SimpleTest example. I've found that drush | |
# likes to exit with odd codes if you run multiple classes at once. | |
# You may have to run one class at a time. | |
# | |
- drush @pantheon.$PNAME.$PSITE test-run MyTestClass --strict=0 | |
- drush @pantheon.$PNAME.$PSITE test-run MyTestClass2 --strict=0 | |
after_script: | |
# Destroy the Pantheon environment | |
- drush psite-edelete $PUUID $PSITE -y | |
# Delete the git branch we created. | |
- cd $TRAVIS_BUILD_DIR; git push pantheon :$PSITE | |
# Continuous delivery! Handy for advanced QA/UAT workflows. | |
after_success: | |
# If this was a master branch build (as opposed to PR), and the build passed: | |
# Go ahead and push the changes up to the dev environment and "deploy." | |
- if [ $TRAVIS_BRANCH = 'master' ] && [ $TRAVIS_PULL_REQUEST = 'false' ] ; then pushd $TRAVIS_BUILD_DIR && git push pantheon $PSITE:master && popd && drush @pantheon.$PNAME.dev updb -y --strict=0 ; fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment