diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000000000..0c81a0fd91beb --- /dev/null +++ b/circle.yml @@ -0,0 +1,54 @@ +--- +general: + branches: + ignore: + - gh-pages + +machine: + timezone: America/Los_Angeles + node: + version: 6 + ruby: + version: 2.2.3 + environment: + TRAVIS_REPO_SLUG: facebook/react + +dependencies: + pre: + # This is equivalent to $TRAVIS_COMMIT_RANGE + # Need to figure out how to bail early if this is a "docs only" build + - echo $CIRCLE_COMPARE_URL | cut -d/ -f7 + # install yarn + - sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg + - echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list + - sudo apt-get update -qq + - sudo apt-get install -y -qq yarn + override: + - bundle install --gemfile=docs/Gemfile --deployment --path=vendor/bundle --jobs=3 --retry=3 + - yarn install + - scripts/circleci/set_up_github_keys.sh + post: + # - npm ls --depth=0 + cache_directories: + - docs/vendor/bundle + - .grunt # Show size comparisons between builds + - ~/react-gh-pages # docs checkout + - ~/.yarn-cache + +test: + override: + - ./node_modules/.bin/gulp lint + - ./node_modules/.bin/gulp flow + - ./scripts/circleci/test_coverage.sh + - ./scripts/circleci/test_fiber.sh + - ./scripts/circleci/test_html_generation.sh + - ./scripts/circleci/track_stats.sh + - ./node_modules/.bin/grunt build + - ./node_modules/.bin/gulp react:extract-errors + +deployment: + staging: + branch: /.*/ + commands: + - ./scripts/circleci/upload_build.sh + - ./scripts/circleci/build_gh_pages.sh diff --git a/grunt/tasks/jest.js b/grunt/tasks/jest.js index 8cc2c47193ddf..c95dfb992cd83 100644 --- a/grunt/tasks/jest.js +++ b/grunt/tasks/jest.js @@ -8,6 +8,7 @@ function run(done, coverage) { var args = [ path.join('node_modules', 'jest-cli', 'bin', 'jest'), + '--runInBand', ]; if (coverage) { args.push('--coverage'); diff --git a/scripts/circleci/build_gh_pages.sh b/scripts/circleci/build_gh_pages.sh new file mode 100755 index 0000000000000..fcf49f2af95d8 --- /dev/null +++ b/scripts/circleci/build_gh_pages.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e + +if [ -z $CI_PULL_REQUEST ] && [ "$CIRCLE_BRANCH" = "$REACT_WEBSITE_BRANCH" ]; then + + GH_PAGES_DIR=`pwd`/../react-gh-pages + + # check if directory exists (restored from cache) + if [ -d $GH_PAGES_DIR ]; then + pushd $GH_PAGES_DIR + git pull origin gh-pages + popd + else + git clone --branch gh-pages --depth=1 \ + https://reactjs-bot@github.com/facebook/react.git \ + $GH_PAGES_DIR + fi + + pushd docs + bundle exec rake release + cd $GH_PAGES_DIR + git status + git --no-pager diff + if ! git diff-index --quiet HEAD --; then + git add -A . + git commit -m "Rebuild website" + git push origin gh-pages + fi + popd +else + echo "Not building website" +fi diff --git a/scripts/circleci/set_up_github_keys.sh b/scripts/circleci/set_up_github_keys.sh new file mode 100755 index 0000000000000..302c40eef0e2f --- /dev/null +++ b/scripts/circleci/set_up_github_keys.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +if [ -n $GITHUB_TOKEN ]; then + + GH_PAGES_DIR=`pwd`/../react-gh-pages + echo "machine github.com login reactjs-bot password $GITHUB_TOKEN" >~/.netrc + git config --global user.name "Circle CI" + git config --global user.email "circle@reactjs.org" + +fi diff --git a/scripts/circleci/test_coverage.sh b/scripts/circleci/test_coverage.sh new file mode 100755 index 0000000000000..efeb4dab4a603 --- /dev/null +++ b/scripts/circleci/test_coverage.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -e + +./node_modules/.bin/grunt jest:coverage +cat ./coverage/lcov.info | ./node_modules/.bin/coveralls diff --git a/scripts/circleci/test_fiber.sh b/scripts/circleci/test_fiber.sh new file mode 100755 index 0000000000000..47fbf9cbe9906 --- /dev/null +++ b/scripts/circleci/test_fiber.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +echo 'Testing in fiber mode...' +./scripts/fiber/record-tests --track-facts --max-workers 1 +git --no-pager diff scripts/fiber +FIBER_TESTS_STATUS=$(git status --porcelain scripts/fiber) +test -z "$FIBER_TESTS_STATUS" diff --git a/scripts/circleci/test_html_generation.sh b/scripts/circleci/test_html_generation.sh new file mode 100755 index 0000000000000..0bedb26aea4ea --- /dev/null +++ b/scripts/circleci/test_html_generation.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +echo 'Testing in server-render (HTML generation) mode...' +printf '\nmodule.exports.useCreateElement = false;\n' \ + >> src/renderers/dom/shared/ReactDOMFeatureFlags.js +./node_modules/.bin/grunt jest:normal +git checkout -- src/renderers/dom/shared/ReactDOMFeatureFlags.js diff --git a/scripts/circleci/track_stats.sh b/scripts/circleci/track_stats.sh new file mode 100755 index 0000000000000..a8a3eae1fad21 --- /dev/null +++ b/scripts/circleci/track_stats.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +ALL_FILES=`find src -name '*.js' | grep -v umd/ | grep -v __tests__ | grep -v __mocks__` +COUNT_ALL_FILES=`echo "$ALL_FILES" | wc -l` +COUNT_WITH_FLOW=`grep '@flow' $ALL_FILES | perl -pe 's/:.+//' | wc -l` +node scripts/facts-tracker/index.js "flow-files" "$COUNT_WITH_FLOW/$COUNT_ALL_FILES" diff --git a/scripts/circleci/upload_build.sh b/scripts/circleci/upload_build.sh new file mode 100755 index 0000000000000..540afb69b81fd --- /dev/null +++ b/scripts/circleci/upload_build.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +if [ -z $CI_PULL_REQUEST ]; then + curl \ + -F "react=@build/react.js" \ + -F "react.min=@build/react.min.js" \ + -F "react-with-addons=@build/react-with-addons.js" \ + -F "react-with-addons.min=@build/react-with-addons.min.js" \ + -F "react-dom=@build/react-dom.js" \ + -F "react-dom.min=@build/react-dom.min.js" \ + -F "react-dom-server=@build/react-dom-server.js" \ + -F "react-dom-server.min=@build/react-dom-server.min.js" \ + -F "npm-react=@build/packages/react.tgz" \ + -F "npm-react-dom=@build/packages/react-dom.tgz" \ + -F "commit=$CIRCLE_SHA1" \ + -F "date=`git log --format='%ct' -1`" \ + -F "pull_request=false" \ + -F "token=$BUILD_SERVER_TOKEN" \ + -F "branch=$CIRCLE_BRANCH" \ + $BUILD_SERVER_ENDPOINT +fi diff --git a/scripts/fiber/record-tests b/scripts/fiber/record-tests index 7b0f5df09e8a2..8be131cca7980 100755 --- a/scripts/fiber/record-tests +++ b/scripts/fiber/record-tests @@ -78,7 +78,7 @@ function wrapRunner(originalPath) { }; } -function runJest() { +function runJest(maxWorkers) { return readConfig(argv, root) .then((config) => { config = Object.assign({}, config, { @@ -92,7 +92,7 @@ function runJest() { hasteMap, config, { - maxWorkers: Math.max(os.cpus().length - 1, 1), + maxWorkers: maxWorkers, getTestSummary: () => 'You did it!' } ); @@ -119,9 +119,9 @@ function formatResults(runResults, predicate) { return formatted.join('\n\n'); } -function recordTests(trackFacts) { +function recordTests(maxWorkers, trackFacts) { process.env.REACT_DOM_JEST_USE_FIBER = true; - runJest() + runJest(maxWorkers) .then((runResults) => { const passing = formatResults( runResults, @@ -169,12 +169,15 @@ function recordTests(trackFacts) { if (require.main === module) { const argv = require('yargs') .demand(0, 0) + .number('max-workers') + .describe('max-workers', 'Number of workers to use for jest.') + .default('max-workers', Math.max(os.cpus().length - 1, 1)) .boolean('track-facts') .describe('track-facts', 'Use facts-tracker to record passing tests.') .strict() .help() .argv; - recordTests(argv.trackFacts); + recordTests(argv.maxWorkers, argv.trackFacts); } module.exports = {