Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup for Circle 2 #4149

Merged
merged 14 commits into from
Aug 8, 2017
111 changes: 111 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
aliases:
- &restore-cache
keys:
- dependencies-{{ .Branch }}-{{ checksum "package.json" }}
# Fallback in case checksum fails
- dependencies-{{ .Branch }}-

- &save-cache
paths:
- node_modules
- website/node_modules
key: dependencies-{{ .Branch }}-{{ checksum "package.json" }}

- &yarn-install
run: |
sudo npm i -g yarn@^0.27.5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Node.js Docker image already has Yarn installed, so you shouldn't need to do this. Also, we discourage installing Yarn via npm 😃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it a super old version of yarn though?
i remember i had to manually install it on travis

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis doesn't use the Node.js Docker image. I think the Node.js image has the latest Yarn.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docker image was using yarn 0.24, that's why I had to install it manually. Will check if that was updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do want to upgrade Yarn, we should do that in a Docker image that's layered on top of another one 😃

We should at least be installing Yarn using the Debian package if the image is Debian, based, too :D

Feel free to reach out to me if you need help with it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would appreciate some help here, I'm not really experienced with Docker images 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's docs on CircleCI's site: https://circleci.com/docs/2.0/custom-images/

I was going to submit a PR for this, but then I realised it's actually using a bunch of Docker images for various Node.js versions 😛 Initially I was going to do something like this:

# Dockerfile for building and testing Jest

FROM markhobson/node-chrome
MAINTAINER Daniel Lo Nigro <[email protected]>

# Yarn repo
ADD https://dl.yarnpkg.com/debian/pubkey.gpg /tmp/yarn-pubkey.gpg
RUN apt-key add /tmp/yarn-pubkey.gpg && rm /tmp/yarn-pubkey.gpg
RUN echo "deb http://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list

# Crowdin repo
ADD https://artifacts.crowdin.com/repo/GPG-KEY-crowdin /tmp/crowdin-pubkey.gpg
RUN apt-key add /tmp/crowdin-pubkey.gpg && rm /tmp/crowdin-pubkey.gpg
RUN echo "deb https://artifacts.crowdin.com/repo/deb/ /" > /etc/apt/sources.list.d/crowdin.list

RUN apt-get -y update && \
  apt-get install -y --no-install-recommends \
    yarn \
    default-jre \
    crowdin \
  && \
  apt-get clean && \
  rm -rf /var/lib/apt/lists/*

yarn --no-progress

- &yarn-install-no-sudo
run: |
npm i -g yarn@^0.27.5
yarn --no-progress

- &deploy
command: |
# Deploy Jest website
git config --global user.email "[email protected]"
git config --global user.name "Website Deployment Script"
echo "machine github.com login jest-bot password $GITHUB_TOKEN" > ~/.netrc
# crowdin install start
sudo apt-get install default-jre
wget https://artifacts.crowdin.com/repo/deb/crowdin.deb -O crowdin.deb
sudo dpkg -i crowdin.deb
Copy link
Contributor

@Daniel15 Daniel15 Aug 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally all required software should be installed in a Docker image so that you don't incur the cost every single time the build runs (instead it's just a once-off cost whenever you build the Docker container). That's one of the main advantages of CircleCI 2.0 :) I might submit a PR to do that, if I get a chance.

Basically, there should be some Jest dev Docker image that extends whichever other Docker images you're using, and has this stuff installed.

# crowdin install end
crowdin --config crowdin.yaml upload sources --auto-update -b master
crowdin --config crowdin.yaml download -b master
cd website && GIT_USER=jest-bot npm run gh-pages

version: 2
jobs:
test-browser:
working_directory: ~/jest
docker:
- image: markhobson/node-chrome
steps:
- checkout
- restore-cache: *restore-cache
- *yarn-install-no-sudo
- save-cache: *save-cache
- run: yarn run test-ci-es5-build-in-browser

test-node-8:
working_directory: ~/jest
docker:
- image: circleci/node:8.1.4
steps:
- checkout
- restore-cache: *restore-cache
- *yarn-install
- save-cache: *save-cache
- run: yarn run test-ci-partial

test-node-6:
working_directory: ~/jest
docker:
- image: circleci/node:6.11.0
steps:
- checkout
- restore-cache: *restore-cache
- *yarn-install
- save-cache: *save-cache
- run: yarn run test-ci

test-node-4:
working_directory: ~/jest
docker:
- image: circleci/node:4.8.4
steps:
- checkout
- restore-cache: *restore-cache
- *yarn-install
- save-cache: *save-cache
- run: npm run test-ci-partial

test-and-deploy-website:
working_directory: ~/jest
docker:
- image: circleci/node:8.1.4
steps:
- checkout
- restore-cache: *restore-cache
- run: sudo npm i -g yarn@^0.27.5
- run: |
cd website
yarn --no-progress
- save-cache: *save-cache
- run: |
cd website
yarn run test
- deploy: *deploy

# Workflows enables us to run multiple jobs in parallel
workflows:
version: 2
build-and-deploy:
jobs:
- test-node-8
- test-node-6
- test-node-4
- test-browser
- test-and-deploy-website
38 changes: 38 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

const path = require('path');
const customImportResolver = path.resolve('./eslint_import_resolver');

module.exports = {
extends: [
'./packages/eslint-config-fb-strict/index.js',
Expand All @@ -19,6 +22,7 @@ module.exports = {
files: ['*.md'],
rules: {
'consistent-return': 0,
'import/no-extraneous-dependencies': 0,
'import/no-unresolved': 0,
'jest/no-focused-tests': 0,
'jest/no-identical-title': 0,
Expand Down Expand Up @@ -76,6 +80,7 @@ module.exports = {
'scripts/**/*',
'integration_tests/*/**/*',
'website/*/**/*',
'eslint_import_resolver.js',
],
rules: {
'prettier/prettier': [
Expand Down Expand Up @@ -108,6 +113,17 @@ module.exports = {
'flowtype/require-valid-file-annotation': [2, 'always'],
},
},
{
files: [
'website/**',
'**/__tests__/**',
'integration_tests/**',
'**/pretty-format/perf/**',
],
rules: {
'import/no-extraneous-dependencies': 0,
},
},
],
parser: 'babel-eslint',
plugins: ['markdown', 'import', 'unicorn', 'prettier'],
Expand All @@ -119,6 +135,19 @@ module.exports = {
'import/default': 0,
'import/named': 0,
'import/no-duplicates': 2,
'import/no-extraneous-dependencies': [
2,
{
devDependencies: [
'**/__tests__/**',
'**/__mocks__/**',
'**/?(*.)(spec|test).js?(x)',
'scripts/**',
'eslint_import_resolver.js',
'test_setup_file.js',
],
},
],
'import/no-unresolved': [2, {ignore: ['^types/']}],
// This has to be disabled until all type and module imports are combined
// https://github.com/benmosher/eslint-plugin-import/issues/645
Expand All @@ -135,4 +164,13 @@ module.exports = {
],
'unicorn/filename-case': [2, {case: 'snakeCase'}],
},
settings: {
'import/resolver': {
[customImportResolver]: {
moduleNameMapper: {
'^types/(.*)': './types/$1',
},
},
},
},
};
50 changes: 0 additions & 50 deletions circle.yml

This file was deleted.

83 changes: 83 additions & 0 deletions eslint_import_resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Copyright (c) 2014, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* Adapted from node resolver: https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers/node
*
*/

'use strict';

const resolve = require('resolve');
const path = require('path');

const log = require('debug')('eslint-plugin-import:resolver:node');

module.exports.interfaceVersion = 2;

module.exports.resolve = function(source, file, config) {
log('Resolving:', source, 'from:', file);
let resolvedPath;

if (resolve.isCore(source)) {
log('resolved to core');
return {found: true, path: null};
}

source = applyModuleNameMapper(source, config);

try {
resolvedPath = resolve.sync(source, opts(file, config));
log('Resolved to:', resolvedPath);
return {found: true, path: resolvedPath};
} catch (err) {
log('resolve threw error:', err);
return {found: false};
}
};

function opts(file, config) {
return Object.assign(
{
// more closely matches Node (#333)
extensions: ['.js', '.json'],
},
config,
{
// path.resolve will handle paths relative to CWD
basedir: path.dirname(path.resolve(file)),
packageFilter,
}
);
}

function packageFilter(pkg) {
if (pkg['jsnext:main']) {
pkg['main'] = pkg['jsnext:main'];
}
return pkg;
}

function applyModuleNameMapper(source, config) {
Object.keys(config.moduleNameMapper).forEach(regex => {
const mappedModuleName = config.moduleNameMapper[regex];

if (source.match(regex)) {
const matches = source.match(regex);
if (!matches) {
source = mappedModuleName;
} else {
source = mappedModuleName.replace(
/\$([0-9]+)/g,
(_, index) => matches[parseInt(index, 10)]
);
}
source = path.resolve(source);
}
});

return source;
}
6 changes: 3 additions & 3 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"dependencies": {
"react": "15.4.2",
"react-dom": "15.4.2"
"react-dom": "15.4.2",
"typescript": "*"
},
"devDependencies": {
"@types/jest": "^19.2.4",
"jest": "*",
"react-addons-test-utils": "15.4.2",
"typescript": "*"
"react-addons-test-utils": "15.4.2"
},
"scripts": {
"test": "jest"
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
"chalk": "^2.0.1",
"codecov": "^1.0.1",
"cross-spawn": "^5.1.0",
"debug": "^2.6.8",
"enzyme": "^2.8.2",
"eslint": "^4.2.0",
"eslint-config-prettier": "^2.3.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-flowtype": "^2.35.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-import": "^2.6.0",
"eslint-plugin-jest": "^20.0.3",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-markdown": "^1.0.0-beta.6",
"eslint-plugin-prettier": "^2.1.2",
"eslint-plugin-react": "^7.1.0",
Expand Down Expand Up @@ -59,6 +60,7 @@
"react-dom": "15.4.2",
"react-test-renderer": "15.4.2",
"regenerator-runtime": "^0.10.3",
"resolve": "^1.4.0",
"rimraf": "^2.5.4",
"rollup": "^0.41.6",
"rollup-plugin-babel": "^2.7.1",
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-circus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"license": "BSD-3-Clause",
"main": "build/index.js",
"dependencies": {
"chalk": "^2.0.1",
"jest-snapshot": "^20.0.3",
"jest-matchers": "^20.0.3",
"jest-matcher-utils": "^20.0.3",
"jest-message-util": "^20.0.3",
"jest-diff": "^20.0.3"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import type {Environment} from 'types/Environment';
import type {GlobalConfig, ProjectConfig} from 'types/Config';
import type {TestResult} from 'types/TestResult';
// eslint-disable-next-line import/no-extraneous-dependencies
import type Runtime from 'jest-runtime';

const FRAMEWORK_INITIALIZER = require.resolve('./jest-adapter-init');
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"jest-matcher-utils": "^20.0.3",
"jest-regex-util": "^20.0.3",
"jest-resolve": "^20.0.4",
"jest-util": "^20.0.3",
"jest-validate": "^20.0.3",
"pretty-format": "^20.0.3"
}
Expand Down
Loading