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

标签 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 访问运行器)

最佳答案

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" - 这将存储库中所有构建的缓存设置为相同。这就是我们使用 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://

关于Angularjs + grunt + Bower + Gitlab CI。测试设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29558444/

相关文章:

angularjs - 如何使用 gitlab-ci-multi-runner 在 GitLab CI 中自动运行测试

docker - 无法使用 “only/except : changes”创建CI管道

javascript - Angular 工厂函数总是返回 null

jquery - fullcalendar 选择回调未在移动设备中触发

javascript - Angularjs 获取 json 在谷歌地图中不起作用

javascript - 从一个指令访问另一指令的 ng-model

javascript - 咕噜声 : Automatically adding script tags

javascript - jquery-ui 分发文件

javascript - grunt-contrib-jasmine ReferenceError : Can't find variable: jQuery

node.js - GitLab 依赖扫描需要源代码中的 package-lock.json 才能执行