Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More versatile travis script

  • Loading branch information...
commit 06762814d6841e1e40a3ab9d934423a246afba96 1 parent 232c187
@chillu chillu authored
View
17 .travis.yml
@@ -1,24 +1,23 @@
+# See https://gist.github.com/chillu/5262316 for setup details
+
language: php
php:
- 5.3
- - 5.4
env:
- - TESTDB=MYSQL CORE_RELEASE=3.1
- - TESTDB=MYSQL CORE_RELEASE=master
- - TESTDB=PGSQL CORE_RELEASE=master
+ - DB=MYSQL CORE_RELEASE=3.1
+ - DB=MYSQL CORE_RELEASE=master
+ - DB=PGSQL CORE_RELEASE=master
matrix:
- exclude:
- - php: 5.4
- env: TESTDB=PGSQL CORE_RELEASE=master
+ include:
- php: 5.4
- env: TESTDB=MYSQL CORE_RELEASE=3.1
+ env: DB=MYSQL CORE_RELEASE=master
before_script:
- pear -q install --onlyreqdeps pear/PHP_CodeSniffer
- phpenv rehash
- - ./tests/travis/before_script ~/builds/ss
+ - ./tests/travis/travis_setup.php --target ~/builds/ss
- cd ~/builds/ss
script:
View
8 composer.json
@@ -9,8 +9,7 @@
{
"name": "Ingo Schommer",
"homepage": "http://chillu.com",
- "email" : "ingo@silverstripe.com",
- "role" : "tech-lead"
+ "email" : "ingo@silverstripe.com"
}
],
"require":
@@ -19,6 +18,11 @@
"silverstripe/framework": "~3.1",
"silverstripe/cms": "~3.1"
},
+ "require-dev": {
+ "silverstripe/postgresql": "*",
+ "silverstripe/sqlite3": "*",
+ "silverstripe/mssql": "*"
+ },
"extra":
{
"snapshot" : "http://www.silverstripe.org/assets/Uploads/translatable4-small.png"
View
54 tests/travis/_config.php
@@ -3,20 +3,48 @@
global $project;
$project = 'mysite';
-global $database;
-$database = '';
-
-require_once('conf/ConfigureFromEnv.php');
-
global $databaseConfig;
-$databaseConfig['memory'] = true;
-$databaseConfig['path'] = dirname(dirname(__FILE__)) .'/assets/';
+switch(getenv('DB')) {
+case "PGSQL";
+ $databaseConfig = array(
+ "type" => "PostgreSQLDatabase",
+ "server" => 'localhost',
+ "username" => 'postgres',
+ "password" => '',
+ "database" => 'SS_travis'
+ );
+ break;
+case "MYSQL":
+ $databaseConfig = array(
+ "type" => "MySQLDatabase",
+ "server" => 'localhost',
+ "username" => 'root',
+ "password" => '',
+ "database" => 'SS_travis'
+ );
+ break;
+default:
+ $databaseConfig = array(
+ "type" => "SQLitePDODatabase",
+ "server" => 'localhost',
+ "memory" => true,
+ "database" => 'SS_travis',
+ 'path' => dirname(dirname(__FILE__)) .'/assets/'
+ );
+}
+
+echo $databaseConfig['type'];
-MySQLDatabase::set_connection_charset('utf8');
+Security::setDefaultAdmin('username', 'password');
-// Set the current theme. More themes can be downloaded from
-// http://www.silverstripe.org/themes/
-SSViewer::set_theme('simple');
+// Fake hostname on CLI to stop framework from complaining
+$_SERVER['HTTP_HOST'] = 'http://localhost';
-// Enable nested URLs for this site (e.g. page/sub-page/)
-if(class_exists('SiteTree')) SiteTree::enable_nested_urls();
+// Version-specific configuration
+$version = getenv('CORE_RELEASE');
+if($version != 'master' && version_compare('3.1', $version) == -1) {
+ MySQLDatabase::set_connection_charset('utf8');
+ SSViewer::set_theme('simple');
+} else {
+ Config::inst()->update('SSViewer', 'theme', 'simple');
+}
View
37 tests/travis/_ss_environment.php
@@ -1,37 +0,0 @@
-<?php
-ob_start();
-
-define('SS_ENVIRONMENT_TYPE', 'dev');
-
-/* Database connection */
-$db = getenv('TESTDB');
-switch($db) {
-case "PGSQL";
- define('SS_DATABASE_CLASS', 'PostgreSQLDatabase');
- define('SS_DATABASE_USERNAME', 'postgres');
- define('SS_DATABASE_PASSWORD', '');
- break;
-
-case "MYSQL":
- define('SS_DATABASE_CLASS', 'MySQLDatabase');
- define('SS_DATABASE_USERNAME', 'root');
- define('SS_DATABASE_PASSWORD', '');
- break;
-
-default:
- define('SS_DATABASE_CLASS', 'SQLitePDODatabase');
- define('SS_DATABASE_USERNAME', 'root');
- define('SS_DATABASE_PASSWORD', '');
-}
-
-echo SS_DATABASE_CLASS;
-
-define('SS_DATABASE_SERVER', 'localhost');
-define('SS_DATABASE_CHOOSE_NAME', true);
-
-
-/* Configure a default username and password to access the CMS on all sites in this environment. */
-define('SS_DEFAULT_ADMIN_USERNAME', 'username');
-define('SS_DEFAULT_ADMIN_PASSWORD', 'password');
-
-$_FILE_TO_URL_MAPPING[dirname(__FILE__)] = 'http://localhost';
View
25 tests/travis/before_script
@@ -1,25 +0,0 @@
-### USAGE: before_script <base-folder>
-
-BUILD_DIR=$1
-
-# Fetch all dependencies
-# TODO Replace with different composer.json variations
-echo "Checking out installer@$CORE_RELEASE"
-git clone --depth=100 --quiet --branch $CORE_RELEASE git://github.com/silverstripe/silverstripe-installer.git $BUILD_DIR
-echo "Checking out cms@$CORE_RELEASE"
-git clone --depth=100 --quiet --branch $CORE_RELEASE git://github.com/silverstripe/silverstripe-cms.git $BUILD_DIR/cms
-echo "Checking out framework@$CORE_RELEASE"
-git clone --depth=100 --quiet --branch $CORE_RELEASE git://github.com/silverstripe/sapphire.git $BUILD_DIR/framework
-echo "Checking out sqlite3"
-git clone --depth=100 --quiet git://github.com/silverstripe-labs/silverstripe-sqlite3.git $BUILD_DIR/sqlite3
-echo "Checking out postgresql"
-git clone --depth=100 --quiet git://github.com/silverstripe/silverstripe-postgresql.git $BUILD_DIR/postgresql
-
-# Copy setup files
-cp ./tests/travis/_ss_environment.php $BUILD_DIR
-cp ./tests/travis/_config.php $BUILD_DIR/mysite
-
-# Copy actual project code into build directory (checked out by travis)
-cp -r . $BUILD_DIR/translatable
-
-cd $BUILD_DIR
View
91 tests/travis/travis_setup.php
@@ -0,0 +1,91 @@
+#!/usr/bin/env php
+<?php
+/**
+ * Initialises a test project that can be built by travis.
+ *
+ * Travis downloads the module, but in order to run unit tests it needs
+ * to be part of a SilverStripe "installer" project.
+ * This script generates a custom composer.json with the required dependencies
+ * and installs it into a separate webroot. The originally downloaded module
+ * code is re-installed via composer.
+ */
+
+if (php_sapi_name() != 'cli') {
+ header('HTTP/1.0 404 Not Found');
+ exit;
+}
+
+$opts = getopt('', array(
+ 'target:',
+));
+
+if (!$opts) {
+ echo "Invalid arguments specified\n";
+ exit(1);
+}
+
+extract($opts);
+
+$dir = __DIR__;
+$modulePath = dirname(dirname($dir));
+$moduleName = basename($modulePath);
+$parent = dirname($modulePath);
+
+// Get exact version of downloaded module so we can re-download via composer
+$moduleRevision = getenv('TRAVIS_COMMIT');
+$moduleBranch = getenv('TRAVIS_BRANCH');
+$moduleBranchComposer = (preg_match('/^\d\.\d/', $moduleBranch)) ? $moduleBranch . '.x-dev' : 'dev-' . $moduleBranch;
+$coreBranch = getenv('CORE_RELEASE');
+$coreBranchComposer = (preg_match('/^\d\.\d/', $coreBranch)) ? $coreBranch . '.x-dev' : 'dev-' . $moduleBranch;
+
+// Print out some environment information.
+printf("Environment:\n");
+printf(" * MySQL: %s\n", trim(`mysql --version`));
+printf(" * PostgreSQL: %s\n", trim(`pg_config --version`));
+printf(" * SQLite: %s\n\n", trim(`sqlite3 -version`));
+
+// Extract the package info from the module composer file, and build a
+// custom project composer file with the local package explicitly defined.
+echo "Reading composer information...\n";
+
+$package = json_decode(file_get_contents("$modulePath/composer.json"), true);
+
+// Generate a custom composer file.
+$packageNew = array(
+ 'require' => array_merge(
+ isset($package['require']) ? $package['require'] : array(),
+ array($package['name'] => $moduleBranchComposer . '#' . $moduleRevision,)
+ ),
+ // Always include DBs, allow module specific version dependencies though
+ 'require-dev' => array_merge(
+ array('silverstripe/postgresql' => '*','silverstripe/sqlite3' => '*'),
+ isset($package['require-dev']) ? $package['require-dev'] : array()
+ ),
+ 'minimum-stability' => 'dev'
+);
+// Override module dependencies in order to test with specific core branch.
+// This might be older than the latest permitted version based on the module definition.
+// Its up to the module author to declare compatible CORE_RELEASE values in the .travis.yml.
+if(isset($packageNew['require']['silverstripe/framework'])) {
+ $packageNew['require']['silverstripe/framework'] = $coreBranchComposer;
+}
+if(isset($packageNew['require']['silverstripe/cms'])) {
+ $packageNew['require']['silverstripe/cms'] = $coreBranchComposer;
+}
+$composer = json_encode($packageNew);
+
+echo "Generated composer file:\n";
+echo "$composer\n\n";
+
+echo "Cloning installer@$coreBranch...\n";
+`git clone --depth=100 --quiet -b $coreBranch git://github.com/silverstripe/silverstripe-installer.git $target`;
+
+echo "Setting up project...\n";
+`cp $dir/_config.php $target/mysite`;
+
+echo "Replacing composer file...\n";
+unlink("$target/composer.json");
+file_put_contents("$target/composer.json", $composer);
+
+echo "Running composer...\n";
+passthru("composer install --prefer-dist --dev -d $target");
Please sign in to comment.
Something went wrong with that request. Please try again.