From 85b5543f6285856b5e6eb875563ec48f70a8b5f9 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Mon, 29 Sep 2014 14:20:23 -0700 Subject: [PATCH] feat: travis-ci integration --- .travis.yml | 20 ++++++++ README.md | 2 + gulpfile.js | 33 ++++++++---- karma-dart.conf.js | 7 ++- karma-js.conf.js | 7 ++- package.json | 2 +- scripts/env.sh | 97 ++++++++++++++++++++++++++++++++++++ scripts/travis/build.sh | 20 ++++++++ scripts/travis/install.sh | 35 +++++++++++++ scripts/travis/print-logs.sh | 11 ++++ 10 files changed, 220 insertions(+), 14 deletions(-) create mode 100644 .travis.yml create mode 100644 scripts/env.sh create mode 100755 scripts/travis/build.sh create mode 100755 scripts/travis/install.sh create mode 100755 scripts/travis/print-logs.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000000..f7afedc32c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +language: node_js +node_js: +- '0.10' +env: + stable: + - CHANNEL=stable + - BROWSERS=DartiumWithWebPlatform + - LOGS_DIR=/tmp/angular-build/logs + +before_install: +- export DISPLAY=:99.0 +- ./scripts/travis/install.sh +- sh -e /etc/init.d/xvfb start +- if [[ -e SKIP_TRAVIS_TESTS ]]; then { cat SKIP_TRAVIS_TESTS ; exit 0; } fi +before_script: +- mkdir -p $LOGS_DIR +script: +- ./scripts/travis/build.sh +after_script: +- ./scripts/travis/print-logs.sh \ No newline at end of file diff --git a/README.md b/README.md index f0f470f7e5..131c78fcd1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/angular/angular.svg?branch=master)](https://travis-ci.org/angular/angular) + ## Build ### Prerequisites: diff --git a/gulpfile.js b/gulpfile.js index 68017bae83..02911f7ec6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,7 +1,6 @@ var gulp = require('gulp'); var rename = require('gulp-rename'); var watch = require('gulp-watch'); -var shell = require('gulp-shell'); var mergeStreams = require('event-stream').merge; var connect = require('gulp-connect'); var clean = require('gulp-rimraf'); @@ -11,6 +10,8 @@ var ejs = require('gulp-ejs'); var path = require('path'); var through2 = require('through2'); var file2moduleName = require('./file2modulename'); +var exec = require('child_process').exec; +var Q = require('q'); var js2es5Options = { annotations: true, // parse annotations @@ -30,6 +31,14 @@ var js2dartOptions = { var gulpTraceur = require('./tools/transpiler/gulp-traceur'); +function execWithLog(command, options, done) { + exec(command, options, function (err, stdout, stderr) { + stdout && console.log(stdout); + stderr && console.log(stderr); + done(err); + }); +} + // --------- // traceur runtime @@ -52,10 +61,10 @@ var sourceTypeConfigs = { mimeType: 'application/dart', postProcess: function(file, done) { if (file.path.match(/pubspec\.yaml/)) { - console.log(file.path); - shell.task(['pub get'], { + console.log('pub get ' + file.path); + execWithLog('pub get', { cwd: path.dirname(file.path) - })().on('end', done); + }, done); } else { done(); } @@ -68,9 +77,7 @@ var sourceTypeConfigs = { copySrc: ['modules/**/*.es5'], outputDir: 'build/js', outputExt: 'js', - postProcess: function() { - - } + postProcess: null } }; @@ -92,10 +99,11 @@ gulp.task('modules/build.dart/analyzer', function() { files = files.filter(function(fileName) { return fileName.match(/(\w+)\/lib\/\1/); }); - var commands = files.map(function(fileName) { - return 'dartanalyzer '+baseDir+'/'+fileName - }); - return shell.task(commands)(); + return Q.all(files.map(function(fileName) { + var deferred = Q.defer(); + execWithLog('dartanalyzer '+baseDir+'/'+fileName, {}, deferred.makeNodeResolver()); + return deferred.promise; + })); }); gulp.task('modules/build.dart', function(done) { @@ -129,6 +137,9 @@ function createModuleTask(sourceTypeConfig) { .pipe(gulp.dest(sourceTypeConfig.outputDir)); var s = mergeStreams(transpile, copy, html); + if (!sourceTypeConfig.postProcess) { + return s; + } return s.pipe(through2.obj(function(file, enc, done) { sourceTypeConfig.postProcess(file, done); })); diff --git a/karma-dart.conf.js b/karma-dart.conf.js index 1bbf76a101..a9a66bfdd5 100644 --- a/karma-dart.conf.js +++ b/karma-dart.conf.js @@ -40,7 +40,12 @@ module.exports = function(config) { } }, - browsers: ['Dartium'] + customLaunchers: { + DartiumWithWebPlatform: { + base: 'Dartium', + flags: ['--enable-experimental-web-platform-features'] } + }, + browsers: ['DartiumWithWebPlatform'], }); diff --git a/karma-js.conf.js b/karma-js.conf.js index 796512198c..4ce0512ebb 100644 --- a/karma-js.conf.js +++ b/karma-js.conf.js @@ -41,7 +41,12 @@ module.exports = function(config) { } }, - browsers: ['Chrome'] + customLaunchers: { + DartiumWithWebPlatform: { + base: 'Dartium', + flags: ['--enable-experimental-web-platform-features'] } + }, + browsers: ['DartiumWithWebPlatform'], }); config.plugins.push(require('./tools/transpiler/karma-traceur-preprocessor')); diff --git a/package.json b/package.json index 3fb7d97630..4fe1b0df33 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "dependencies": { "gulp": "^3.8.8", "gulp-rename": "^1.2.0", - "gulp-shell": "^0.2.9", "gulp-watch": "^1.0.3", + "karma-cli": "^0.0.4", "karma": "^0.12.23", "karma-chrome-launcher": "^0.1.4", "karma-dart": "^0.2.8", diff --git a/scripts/env.sh b/scripts/env.sh new file mode 100644 index 0000000000..0626b1e8a1 --- /dev/null +++ b/scripts/env.sh @@ -0,0 +1,97 @@ +#!/bin/false +set -e -o pipefail + +if [[ -z $ENV_SET ]]; then + export ENV_SET=1 + + # Map DART_SDK and DARTSDK to each other if only one is specified. + # + # TODO(chirayu): Remove this legacy DARTSDK variable support. Check with Misko + # to see if he's using it on this Mac. + if [[ -z "$DART_SDK" ]]; then + : "${DARTSDK:=$DART_SDK}" + else + : "${DART_SDK:=$DARTSDK}" + fi + + unset DART + PLATFORM="$(uname -s)" + + case "$PLATFORM" in + (Darwin) + path=$(readlink ${BASH_SOURCE[0]}||echo './scripts/env.sh') + export NGDART_SCRIPT_DIR=$(dirname $path) + ;; + (Linux) + export NGDART_SCRIPT_DIR=$(dirname $(readlink -f ${BASH_SOURCE[0]})) + ;; + (*) + echo Unsupported platform $PLATFORM. Exiting ... >&2 + exit 3 + ;; + esac + + export NGDART_BASE_DIR=$(dirname $NGDART_SCRIPT_DIR) + + # Try to find the SDK alongside the dart command first. + if [[ -z "$DART_SDK" ]]; then + DART=$(which dart) || true + if [[ -x "$DART" ]]; then + DART_SDK="${DART/dart-sdk\/*/dart-sdk}" + if [[ ! -e "$DART_SDK" ]]; then + unset DART DART_SDK + fi + fi + fi + # Fallback: Assume it's alongside the current directory (e.g. Travis). + if [[ -z "$DART_SDK" ]]; then + DART_SDK="$(pwd)/dart-sdk" + fi + + : "${DART:=$DART_SDK/bin/dart}" + + if [[ ! -x "$DART" ]]; then + echo Unable to locate the dart binary / SDK. Exiting >&2 + exit 3 + fi + + if [[ -z "$DARTIUM" ]]; then + dartiumRoot="$DART_SDK/../chromium" + if [[ -e "$dartiumRoot" ]]; then + case "$PLATFORM" in + (Linux) export DARTIUM="$dartiumRoot/chrome" ;; + (Darwin) export DARTIUM="$dartiumRoot/Chromium.app/Contents/MacOS/Chromium" ;; + (*) echo Unsupported platform $PLATFORM. Exiting ... >&2 ; exit 3 ;; + esac + fi + fi + + export DART_SDK + export DARTSDK + export DART + export PUB=${PUB:-"$DART_SDK/bin/pub"} + export DARTANALYZER=${DARTANALYZER:-"$DART_SDK/bin/dartanalyzer"} + export DARTDOC=${DARTDOC:-"$DART_SDK/bin/dartdoc"} + export DART_DOCGEN=${DART_DOCGEN:-"$DART_SDK/bin/docgen"} + export DART_VM_OPTIONS="--old_gen_heap_size=2048" + export DARTIUM_BIN=${DARTIUM_BIN:-"$DARTIUM"} + export CHROME_BIN=${CHROME_BIN:-"google-chrome"} + export PATH=$PATH:$DART_SDK/bin + + echo '*********' + echo '** ENV **' + echo '*********' + echo DART_SDK=$DART_SDK + echo DART=$DART + echo PUB=$PUB + echo DARTANALYZER=$DARTANALYZER + echo DARTDOC=$DARTDOC + echo DART_DOCGEN=$DART_DOCGEN + echo DARTIUM_BIN=$DARTIUM_BIN + echo CHROME_BIN=$CHROME_BIN + echo PATH=$PATH + echo NGDART_BASE_DIR=$NGDART_BASE_DIR + echo NGDART_SCRIPT_DIR=$NGDART_SCRIPT_DIR + $DART --version 2>&1 + +fi \ No newline at end of file diff --git a/scripts/travis/build.sh b/scripts/travis/build.sh new file mode 100755 index 0000000000..95e817aed3 --- /dev/null +++ b/scripts/travis/build.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e + +echo ============================================================================= +# go to project dir +SCRIPT_DIR=$(dirname $0) +cd $SCRIPT_DIR/../.. +source ./scripts/env.sh + +./node_modules/.bin/gulp build + +pub install + +./node_modules/karma/bin/karma start karma-js.conf \ + --reporters=dots \ + --browsers=$BROWSERS --single-run +./node_modules/karma/bin/karma start karma-dart.conf \ + --reporters=dots \ + --browsers=$BROWSERS --single-run \ No newline at end of file diff --git a/scripts/travis/install.sh b/scripts/travis/install.sh new file mode 100755 index 0000000000..e81d6293ff --- /dev/null +++ b/scripts/travis/install.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -e + +AVAILABLE_DART_VERSION=$(curl "https://storage.googleapis.com/dart-archive/channels/$CHANNEL/release/latest/VERSION" | python -c \ + 'import sys, json; print(json.loads(sys.stdin.read())["version"])') + +echo Fetch Dart channel: $CHANNEL + +SVN_REVISION=latest +# TODO(chirayu): Remove this once issue 20896 is fixed. +# Dart 1.7.0-dev.1.0 and 1.7.0-dev.2.0 are both broken so use version +# 1.7.0-dev.0.1 instead. +if [[ "$AVAILABLE_DART_VERSION" == "1.7.0-dev.2.0" ]]; then + SVN_REVISION=39661 # Use version 1.7.0-dev.0.1 +fi + +URL_PREFIX=https://storage.googleapis.com/dart-archive/channels/$CHANNEL/release/$SVN_REVISION +DART_SDK_URL=$URL_PREFIX/sdk/dartsdk-linux-x64-release.zip +DARTIUM_URL=$URL_PREFIX/dartium/dartium-linux-x64-release.zip + +download_and_unzip() { + ZIPFILE=${1/*\//} + curl -O -L $1 && unzip -q $ZIPFILE && rm $ZIPFILE +} + +# TODO: do these downloads in parallel +download_and_unzip $DART_SDK_URL +download_and_unzip $DARTIUM_URL + +echo Fetched new dart version $(