问题
In my .travis.yml
I have this.
script:
- yarn lint
- yarn flow
- yarn test --runInBand
I was wondering is there a way to get them to run in parallel?
回答1:
There's few suggestions in Travis docs you could use, i.e. split your build into multiple jobs: https://docs.travis-ci.com/user/speeding-up-the-build/
Another thing you could do is to employ GNU parallel:
addons:
apt_packages:
- parallel
script:
- parallel --gnu --keep-order ::: 'yarn lint' 'yarn flow' 'yarn test --runInBand'
The GNU parallel command has lots of options you might want to tweak to your needs. Read more about the tool on their website https://www.gnu.org/software/parallel/
回答2:
To split Travis into several jobs you can either use stages or add the option env
This would run each script sequentially:
script:
- yarn lint
- yarn flow
- yarn test --runInBand
- yarn build
- yarn cypress
To get them to run in parallel jobs. You can update it to the code below (Though keep in mind this is limited by the number of concurrent jobs available. https://travis-ci.com/plans)
Using Build Stages
language: node_js
node_js:
- '9'
install:
- travis_retry yarn install
jobs:
include:
- stage: test
name: "Flow/Lint/Test"
script:
- yarn lint
- yarn flow
- yarn test
-
name: "Cypress"
script:
- yarn cypress
Using env
env:
- TEST_SUITE="yarn lint"
- TEST_SUITE="yarn flow"
- TEST_SUITE="yarn test --runInBand"
- TEST_SUITE="yarn build"
- TEST_SUITE="yarn cypress"
script: $TEST_SUITE
Another option would be to just have two concurrent builds.
env:
- TEST_SUITE="yarn lint && yarn flow && yarn test --runInBand && yarn build"
- TEST_SUITE="yarn cypress"
script: $TEST_SUITE
This might or might not improve the overall build times. For me majority of my build time was in cypress while lint + flow + test took a few minutes. So by separating cypress to be in its own job, I sped up my overall build time by a few minutes.
来源:https://stackoverflow.com/questions/50110360/how-to-make-travisci-run-flow-test-lint-in-parallel