Skip to content

Commit 153fe38

Browse files
tomocchinosophiebits
authored andcommitted
Add circle.yml / CircleCI support (#8486)
1 parent 33198b7 commit 153fe38

File tree

10 files changed

+163
-5
lines changed

10 files changed

+163
-5
lines changed

circle.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
general:
3+
branches:
4+
ignore:
5+
- gh-pages
6+
7+
machine:
8+
timezone: America/Los_Angeles
9+
node:
10+
version: 6
11+
ruby:
12+
version: 2.2.3
13+
environment:
14+
TRAVIS_REPO_SLUG: facebook/react
15+
16+
dependencies:
17+
pre:
18+
# This is equivalent to $TRAVIS_COMMIT_RANGE
19+
# Need to figure out how to bail early if this is a "docs only" build
20+
- echo $CIRCLE_COMPARE_URL | cut -d/ -f7
21+
# install yarn
22+
- sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
23+
- echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
24+
- sudo apt-get update -qq
25+
- sudo apt-get install -y -qq yarn
26+
override:
27+
- bundle install --gemfile=docs/Gemfile --deployment --path=vendor/bundle --jobs=3 --retry=3
28+
- yarn install
29+
- scripts/circleci/set_up_github_keys.sh
30+
post:
31+
# - npm ls --depth=0
32+
cache_directories:
33+
- docs/vendor/bundle
34+
- .grunt # Show size comparisons between builds
35+
- ~/react-gh-pages # docs checkout
36+
- ~/.yarn-cache
37+
38+
test:
39+
override:
40+
- ./node_modules/.bin/gulp lint
41+
- ./node_modules/.bin/gulp flow
42+
- ./scripts/circleci/test_coverage.sh
43+
- ./scripts/circleci/test_fiber.sh
44+
- ./scripts/circleci/test_html_generation.sh
45+
- ./scripts/circleci/track_stats.sh
46+
- ./node_modules/.bin/grunt build
47+
- ./node_modules/.bin/gulp react:extract-errors
48+
49+
deployment:
50+
staging:
51+
branch: /.*/
52+
commands:
53+
- ./scripts/circleci/upload_build.sh
54+
- ./scripts/circleci/build_gh_pages.sh

grunt/tasks/jest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function run(done, coverage) {
88

99
var args = [
1010
path.join('node_modules', 'jest-cli', 'bin', 'jest'),
11+
'--runInBand',
1112
];
1213
if (coverage) {
1314
args.push('--coverage');

scripts/circleci/build_gh_pages.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [ -z $CI_PULL_REQUEST ] && [ "$CIRCLE_BRANCH" = "$REACT_WEBSITE_BRANCH" ]; then
6+
7+
GH_PAGES_DIR=`pwd`/../react-gh-pages
8+
9+
# check if directory exists (restored from cache)
10+
if [ -d $GH_PAGES_DIR ]; then
11+
pushd $GH_PAGES_DIR
12+
git pull origin gh-pages
13+
popd
14+
else
15+
git clone --branch gh-pages --depth=1 \
16+
https://[email protected]/facebook/react.git \
17+
$GH_PAGES_DIR
18+
fi
19+
20+
pushd docs
21+
bundle exec rake release
22+
cd $GH_PAGES_DIR
23+
git status
24+
git --no-pager diff
25+
if ! git diff-index --quiet HEAD --; then
26+
git add -A .
27+
git commit -m "Rebuild website"
28+
git push origin gh-pages
29+
fi
30+
popd
31+
else
32+
echo "Not building website"
33+
fi
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [ -n $GITHUB_TOKEN ]; then
6+
7+
GH_PAGES_DIR=`pwd`/../react-gh-pages
8+
echo "machine github.com login reactjs-bot password $GITHUB_TOKEN" >~/.netrc
9+
git config --global user.name "Circle CI"
10+
git config --global user.email "[email protected]"
11+
12+
fi

scripts/circleci/test_coverage.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
./node_modules/.bin/grunt jest:coverage
6+
cat ./coverage/lcov.info | ./node_modules/.bin/coveralls

scripts/circleci/test_fiber.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo 'Testing in fiber mode...'
6+
./scripts/fiber/record-tests --track-facts --max-workers 1
7+
git --no-pager diff scripts/fiber
8+
FIBER_TESTS_STATUS=$(git status --porcelain scripts/fiber)
9+
test -z "$FIBER_TESTS_STATUS"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo 'Testing in server-render (HTML generation) mode...'
6+
printf '\nmodule.exports.useCreateElement = false;\n' \
7+
>> src/renderers/dom/shared/ReactDOMFeatureFlags.js
8+
./node_modules/.bin/grunt jest:normal
9+
git checkout -- src/renderers/dom/shared/ReactDOMFeatureFlags.js

scripts/circleci/track_stats.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
ALL_FILES=`find src -name '*.js' | grep -v umd/ | grep -v __tests__ | grep -v __mocks__`
6+
COUNT_ALL_FILES=`echo "$ALL_FILES" | wc -l`
7+
COUNT_WITH_FLOW=`grep '@flow' $ALL_FILES | perl -pe 's/:.+//' | wc -l`
8+
node scripts/facts-tracker/index.js "flow-files" "$COUNT_WITH_FLOW/$COUNT_ALL_FILES"

scripts/circleci/upload_build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [ -z $CI_PULL_REQUEST ]; then
6+
curl \
7+
-F "react=@build/react.js" \
8+
-F "react.min=@build/react.min.js" \
9+
-F "react-with-addons=@build/react-with-addons.js" \
10+
-F "react-with-addons.min=@build/react-with-addons.min.js" \
11+
-F "react-dom=@build/react-dom.js" \
12+
-F "react-dom.min=@build/react-dom.min.js" \
13+
-F "react-dom-server=@build/react-dom-server.js" \
14+
-F "react-dom-server.min=@build/react-dom-server.min.js" \
15+
-F "npm-react=@build/packages/react.tgz" \
16+
-F "npm-react-dom=@build/packages/react-dom.tgz" \
17+
-F "commit=$CIRCLE_SHA1" \
18+
-F "date=`git log --format='%ct' -1`" \
19+
-F "pull_request=false" \
20+
-F "token=$BUILD_SERVER_TOKEN" \
21+
-F "branch=$CIRCLE_BRANCH" \
22+
$BUILD_SERVER_ENDPOINT
23+
fi

scripts/fiber/record-tests

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function wrapRunner(originalPath) {
7878
};
7979
}
8080

81-
function runJest() {
81+
function runJest(maxWorkers) {
8282
return readConfig(argv, root)
8383
.then((config) => {
8484
config = Object.assign({}, config, {
@@ -92,7 +92,7 @@ function runJest() {
9292
hasteMap,
9393
config,
9494
{
95-
maxWorkers: Math.max(os.cpus().length - 1, 1),
95+
maxWorkers: maxWorkers,
9696
getTestSummary: () => 'You did it!'
9797
}
9898
);
@@ -119,9 +119,9 @@ function formatResults(runResults, predicate) {
119119
return formatted.join('\n\n');
120120
}
121121

122-
function recordTests(trackFacts) {
122+
function recordTests(maxWorkers, trackFacts) {
123123
process.env.REACT_DOM_JEST_USE_FIBER = true;
124-
runJest()
124+
runJest(maxWorkers)
125125
.then((runResults) => {
126126
const passing = formatResults(
127127
runResults,
@@ -169,12 +169,15 @@ function recordTests(trackFacts) {
169169
if (require.main === module) {
170170
const argv = require('yargs')
171171
.demand(0, 0)
172+
.number('max-workers')
173+
.describe('max-workers', 'Number of workers to use for jest.')
174+
.default('max-workers', Math.max(os.cpus().length - 1, 1))
172175
.boolean('track-facts')
173176
.describe('track-facts', 'Use facts-tracker to record passing tests.')
174177
.strict()
175178
.help()
176179
.argv;
177-
recordTests(argv.trackFacts);
180+
recordTests(argv.maxWorkers, argv.trackFacts);
178181
}
179182

180183
module.exports = {

0 commit comments

Comments
 (0)