BUG Restore travis artifacts (#6277)

Fixes #6046
This commit is contained in:
Damian Mooyman 2016-11-03 12:17:15 +13:00 committed by Sam Minnée
parent 019e99dd4d
commit 4ee78fc29d
2 changed files with 97 additions and 1 deletions

View File

@ -64,7 +64,7 @@ script:
- "if [ \"$PHPUNIT_COVERAGE_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi"
after_failure:
- php ~/travis-support/travis_upload_artifacts.php --if-env BEHAT_TEST,ARTIFACTS_BUCKET,ARTIFACTS_KEY,ARTIFACTS_SECRET --target-path $TRAVIS_REPO_SLUG/$TRAVIS_BUILD_ID/$TRAVIS_JOB_ID --artifacts-base-url https://s3.amazonaws.com/$ARTIFACTS_BUCKET/
- php ./tests/behat/travis-upload-artifacts.php --if-env BEHAT_TEST,ARTIFACTS_BUCKET,ARTIFACTS_KEY,ARTIFACTS_SECRET --target-path $TRAVIS_REPO_SLUG/$TRAVIS_BUILD_ID/$TRAVIS_JOB_ID --artifacts-base-url https://s3.amazonaws.com/$ARTIFACTS_BUCKET/
branches:
except:

View File

@ -0,0 +1,96 @@
#!/usr/bin/env php
<?php
/**
* Creates an index.html with links to all files in a given directory structure, recursively.
* This is useful for Amazon S3 uploads with static file hosting, since it doesn't list files by default.
*
* Assumes to run in a SilverStripe webroot
*/
/**
* Run a command
*
* @param string $cmd
* @param bool $echo
*/
function run($cmd, $echo = true) {
if($echo) echo "+ $cmd\n";
passthru($cmd, $returnVar);
if($returnVar > 0) die($returnVar);
}
/**
* Check if an env variable is set
*
* @param $envs
* @return bool
*/
function checkenv($envs) {
if($envs) {
foreach(explode(',',$envs) as $env) {
if(!getenv($env)) {
return false;
}
}
}
return true;
}
$opts = getopt('', array(
'artifacts-path:',
'target-path:',
'if-env:',
'artifacts-base-url:',
));
// --if-env=BEHAT_TEST means that this script will only be executed if the given environment var is set
if (empty($opts['if-env'])) {
echo "--if-env option is mandatory";
exit(0);
}
if(!checkenv($opts['if-env'])) {
echo "Apache skipped; {$opts['if-env']} wasn't set.\n";
exit(0);
}
if (isset($opts['artifacts-path'])) {
$artifactsPath = $opts['artifacts-path'];
} elseif(is_dir(__DIR__ . '/artifacts/')) {
$artifactsPath = __DIR__ . '/artifacts/';
} elseif(is_dir('~/artifacts/')) {
$artifactsPath = '~/artifacts/';
} else {
$artifactsPath = null;
}
$targetPath = $opts['target-path'];
$baseUrl = $opts['artifacts-base-url'];
if(!$artifactsPath || !is_dir($artifactsPath)) {
echo "No artifacts found, skipped\n";
exit(0);
}
echo "Installing artifacts script to ~/bin/artifacts\n";
run("curl -sL https://raw.githubusercontent.com/travis-ci/artifacts/master/install | bash");
echo "Creating {$artifactsPath}index.html...\n";
$html = '<html><head></head><body><ul>';
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(realpath($artifactsPath)), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object){
if($object->isDir()) {
continue;
}
$relativePath = trim(str_replace(realpath($artifactsPath) . '/', '', $object->getPathName()), '/');
$html .= sprintf('<li><a href="%s">%s</a></li>', $relativePath, $relativePath);
}
$html .= '</ul></body></html>';
file_put_contents("{$artifactsPath}index.html", $html);
run("~/bin/artifacts upload --permissions public-read --target-paths $targetPath $artifactsPath");
$fullPath = str_replace('//', '/', "$baseUrl/$targetPath/artifacts/index.html");
$fullPath = str_replace('https:/s3','https://s3', $fullPath);
echo "Uploaded artifacts to $fullPath\n";