Skip to content

Commit

Permalink
Add circle.yml / CircleCI support (facebook#8486)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomocchino authored and sophiebits committed Dec 2, 2016
1 parent 33198b7 commit 153fe38
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 5 deletions.
54 changes: 54 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions grunt/tasks/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function run(done, coverage) {

var args = [
path.join('node_modules', 'jest-cli', 'bin', 'jest'),
'--runInBand',
];
if (coverage) {
args.push('--coverage');
Expand Down
33 changes: 33 additions & 0 deletions scripts/circleci/build_gh_pages.sh
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions scripts/circleci/set_up_github_keys.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions scripts/circleci/test_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -e

./node_modules/.bin/grunt jest:coverage
cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
9 changes: 9 additions & 0 deletions scripts/circleci/test_fiber.sh
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 9 additions & 0 deletions scripts/circleci/test_html_generation.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions scripts/circleci/track_stats.sh
Original file line number Diff line number Diff line change
@@ -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"
23 changes: 23 additions & 0 deletions scripts/circleci/upload_build.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 8 additions & 5 deletions scripts/fiber/record-tests
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function wrapRunner(originalPath) {
};
}

function runJest() {
function runJest(maxWorkers) {
return readConfig(argv, root)
.then((config) => {
config = Object.assign({}, config, {
Expand All @@ -92,7 +92,7 @@ function runJest() {
hasteMap,
config,
{
maxWorkers: Math.max(os.cpus().length - 1, 1),
maxWorkers: maxWorkers,
getTestSummary: () => 'You did it!'
}
);
Expand All @@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 153fe38

Please sign in to comment.