I am working on a python project and using miniconda to manage my environment. I am using GitLab for CI with the following runner configuration
stages:
- build
- test
build:
stage: build
script:
- if hash $HOME/miniconda/bin/conda 2>/dev/null;
then
export PATH="$HOME/miniconda/bin:$PATH";
else
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b -p $HOME/miniconda;
export PATH="$HOME/miniconda/bin:$PATH";
fi
- conda update --yes conda
test:
stage: test
script:
- conda env create --quiet --force --file environment.yml
- source activate myenv
- nosetests --with-coverage --cover-erase --cover-package=mypackage --cover-html
- pylint --reports=n tests/test_final.py
- pep8 tests/test_final.py
- grep pc_cov cover/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered " $1;}'
I assumed (incorrectly) that my build
stage would setup the correct environment in which I could run my test
stage. Looking at this question and this GitLab issue I see that
each job defined in .gitlab-ci.yml is run as separate build (where we assume that there's no history)
But the alternative of lumping everything together in one stage isn't appealing
stages:
- test
test:
stage: test
script:
- if hash $HOME/miniconda/bin/conda 2>/dev/null;
then
export PATH="$HOME/miniconda/bin:$PATH";
else
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
bash miniconda.sh -b -p $HOME/miniconda;
export PATH="$HOME/miniconda/bin:$PATH";
fi
- conda update --yes conda
- conda env create --quiet --force --file environment.yml
- source activate myenv
- nosetests --with-coverage --cover-erase --cover-package=mypackage --cover-html
- pylint --reports=n tests/test_final.py
- pep8 tests/test_final.py
- grep pc_cov cover/index.html | egrep -o "[0-9]+\%" | awk '{ print "covered " $1;}'
The only other option I can think of is to put the environment creation steps in a before_script stage, but it seems redundant to continuously recreate the same environment before each stage.