From 4ee78fc29d93793bbe3d16f7aeea602d7394809c Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Thu, 3 Nov 2016 12:17:15 +1300 Subject: [PATCH] BUG Restore travis artifacts (#6277) Fixes #6046 --- .travis.yml | 2 +- tests/behat/travis-upload-artifacts.php | 96 +++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 tests/behat/travis-upload-artifacts.php diff --git a/.travis.yml b/.travis.yml index 62541d457..6b3c09f6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/tests/behat/travis-upload-artifacts.php b/tests/behat/travis-upload-artifacts.php new file mode 100644 index 000000000..9cbd7f1a9 --- /dev/null +++ b/tests/behat/travis-upload-artifacts.php @@ -0,0 +1,96 @@ +#!/usr/bin/env php + 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 = ''; + +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";