rpadovani rpadovani - 5 months ago 372
AngularJS Question

Angularjs + grunt + bower + Gitlab CI. Setup for testing

I've a GitLab CI runner that runs every time I push code in my branch.
The problem is: I use npm+bower to have all dependencies I need, but I don't want to download all dependencies for each test: it's a waste of network and time.

So I came up with this script. Does it make any sense?

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


Anyway, a problem I'm facing is it always goes on timeout with 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


Also, it didn't finish once, so I'm not sure, but it seems it re-download all packages every time.

I tried to search on the net, but I didn't find anything. There is a way to achieve what I'm trying to achieve? (Also with a completely different strategy. I also have ssh access to the runner)

Answer

UPDATE 2016

GitLab runners now use .gitlab-ci.yml that has support for cache.

This is our script now:

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/

Now, the interesting thing is key: "$CI_BUILD_REPO" in the cache section - this set the cache to be the same for all the build in the repo. This is why we use npm prune and bower prune - to be sure only modules we really need are in the build at the end

ORIGINAL ANSWER

So, at the end I use this script:

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

Also, to avoid timeout from github I use https instead of git to download code, with the command

git config --global url."https://".insteadOf git://