Angularjs + grunt + bower + Gitlab CI。设置测试

时间:2015-04-10 09:54:58

标签: angularjs gruntjs gitlab-ci

我有一个GitLab CI运行器,每次我在我的分支中推送代码时都会运行它。 问题是:我使用npm + bower来获得我需要的所有依赖项,但我不想为每个测试下载所有依赖项:这是浪费网络和时间。

所以我提出了这个脚本。它有意义吗?

touch ~/.bash_profile
npm config set prefix ~/npm
export PATH="~/npm/bin:$PATH"
source ~/.bash_profile
npm install
rm -f ~/bower/bower.json
cp bower.json ~/bower
pushd ~/bower
bower update
bower install
popd
mkdir bower_components
cp -r ~/bower/bower_components bower_components
grunt test

无论如何,我遇到的一个问题是它总是在播出时超时:

bower angular-cookies#1.2.16                  ECMDERR Failed to execute "git ls-remote --tags --heads git://github.com/angular/bower-angular-cookies.git", exit code of #128 fatal: unable to connect to github.com: github.com[0: 192.30.252.128]: errno=Connection timed out

此外,它没有完成一次,所以我不确定,但它似乎每次重新下载所有包。

我试图在网上搜索,但我没有找到任何东西。有一种方法可以实现我想要实现的目标吗? (还有一个完全不同的策略。我也有ssh访问跑步者)

1 个答案:

答案 0 :(得分:15)

2016年更新

GitLab跑步者现在使用支持缓存的 .gitlab-ci.yml

这是我们的脚本:

image: *****/frontend

stages:
  - test
  - deploy

before_script:
  - npm prune
  - npm install
  - bower prune --allow-root
  - bower install --allow-root

cache:
  paths:
    - node_modules/
    - bower_components/
  key: "$CI_BUILD_REPO"

sample_test:
  stage: test
  script:
    - grunt build
    - grunt test
    - grunt jscs --force
    - grunt jshint --force

sample_deploy:
  stage: deploy
  only:
    - master
    - development
  script:
    - grunt build babel uglify:dist
  artifacts:
    paths:
      - dist/

现在,有趣的是缓存部分中的key: "$CI_BUILD_REPO" - 这使得缓存对于repo中的所有构建都是相同的。这就是我们使用npm prunebower prune的原因 - 确保我们真正需要的模块最终只能在构建中使用

原始回答

所以,最后我使用这个脚本:

rm -f ~/bower/bower.json
rm -f ~/bower/package.json
cp bower.json ~/bower
cp package.json ~/bower
pushd ~/bower
npm install
bower install
popd
cp -r ~/bower/bower_components .
cp -r ~/bower/node_modules .
grunt build
grunt test

另外,为了避免从github超时,我使用https而不是git来下载代码,使用命令

git config --global url."https://".insteadOf git://
相关问题