【问题标题】:Angularjs + grunt + bower + Gitlab CI. Setup for testingAngularjs + grunt + bower + Gitlab CI。测试设置
【发布时间】:2015-04-10 09:54:58
【问题描述】:

我有一个 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 总是超时:

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 访问跑步者)

【问题讨论】:

  • 嘿,我正在尝试做同样的事情,我也在使用 bower、npm 和 grunt。但对我来说,“npm install”甚至没有运行。它在 30 分钟后取消,告诉我命令的执行时间太长。 “npm install”对你有用吗?
  • @error1337 是的,它有效。最后我修改了我刚刚发布的脚本作为回复,希望这可以帮助

标签: angularjs gruntjs gitlab-ci


【解决方案1】:

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://

【讨论】:

  • 你能分享完整的脚本吗(scipt.sh & .gitlab-ci.yml)?它是一个 .sh 的,对吧?另外我很好奇你是如何设置跑步者的(你使用了什么命令。
  • 嗨 @el.severo,这是旧版本 gitlab 的旧配置,当时还没有 .gitlab-ci.yml - 我们还没有将该服务器转换为新版本
  • @el.severo 我用我们的 .gitlab-ci.yml 更新了答案
  • 感谢您更新答案
  • 我收到了这个错误:npm: command not found。每次下载npm都需要指定吗?
猜你喜欢
  • 2018-05-12
  • 2021-05-10
  • 1970-01-01
  • 2021-12-26
  • 2018-06-05
  • 2022-06-24
  • 2019-08-07
  • 2022-11-10
  • 2019-05-03
相关资源
最近更新 更多