Integrate composer in the Travis build process

Creates a package definition from the framework version being built,
and uses composer to install it into an installer project, as well
as the required modules for testing.
This commit is contained in:
ajshort 2013-02-27 00:38:40 +11:00
parent accbd7f1e2
commit 34d524c09f
3 changed files with 84 additions and 35 deletions

View File

@ -26,7 +26,7 @@ matrix:
before_script:
- pear install pear/PHP_CodeSniffer
- phpenv rehash
- ./tests/travis/before_script ~/builds/ss
- ./tests/travis/before.php --target ~/builds/ss --version="2.5.x-dev" --installer="post-2.4"
- cd ~/builds/ss
script:

83
tests/travis/before.php Executable file
View File

@ -0,0 +1,83 @@
#!/usr/bin/env php
<?php
/**
* Initialises a test project that can be built by travis.
*
* The local framework checkout's composer file is parsed and used to built a
* custom local framework archive which is then installed into an installer
* base project.
*/
if (php_sapi_name() != 'cli') {
header('HTTP/1.0 404 Not Found');
exit;
}
$opts = getopt('', array(
'target:',
'version:',
'installer:'
));
if (!$opts) {
echo "Invalid arguments specified\n";
exit(1);
}
extract($opts);
$dir = __DIR__;
$framework = dirname(dirname($dir));
$parent = dirname($framework);
// Print out some environment information.
printf("Database versions:\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 framework 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("$framework/composer.json"), true);
// Override the default framework requirement with the one being built.
$package += array(
'version' => $version,
'dist' => array(
'type' => 'tar',
'url' => "file://$parent/framework.tar"
)
);
// Generate a custom composer file.
$composer = json_encode(array(
'repositories' => array(array('type' => 'package', 'package' => $package)),
'require' => array(
'silverstripe/framework' => $version,
'silverstripe/postgresql' => '*',
'silverstripe/sqlite3' => '*'
),
'minimum-stability' => 'dev'
));
echo "Generated composer file:\n";
echo "$composer\n\n";
echo "Archiving framework...\n";
`cd $framework`;
`tar -cf $parent/framework.tar .`;
echo "Cloning installer@$installer...\n";
`git clone --depth=100 --quiet -b $installer git://github.com/silverstripe/silverstripe-installer.git $target`;
echo "Setting up project...\n";
`cp $dir/_ss_environment.php $target`;
`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";
`composer install --dev -d $target`;

View File

@ -1,34 +0,0 @@
#!/bin/sh
### USAGE: before_script <base-folder> <travis-branch>
BUILD_DIR=$1
# Environment info
echo "# Environment info"
echo " - `php --version`"
echo " - `mysql --version`"
echo " - `pg_config --version`"
echo " - SQLite3 `sqlite3 -version`"
echo ""
# Fetch all dependencies
# TODO Replace with different composer.json variations
echo "Checking out installer@$TRAVIS_BRANCH"
git clone --depth=100 --quiet -b $TRAVIS_BRANCH git://github.com/silverstripe/silverstripe-installer.git $BUILD_DIR
echo "Checking out sqlite3@master"
git clone --depth=100 --quiet git://github.com/silverstripe-labs/silverstripe-sqlite3.git $BUILD_DIR/sqlite3
echo "Checking out postgresql@master"
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/framework
cd $BUILD_DIR