Skip to content

Commit

Permalink
Merge branch 'deviate/jenkins' into feature/exposures_crs
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuel-schmid committed May 22, 2024
2 parents 36bee6f + b3b6b87 commit e162bc5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 22 deletions.
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# test, coverage and lint
###

# Default pytest command
PYTEST_CMD := pytest

PYTEST_JUNIT_ARGS = --junitxml=tests_xml/tests.xml

PYTEST_COV_ARGS = \
Expand All @@ -16,15 +19,15 @@ help: ## Use one of the following instructions:

.PHONY : lint
lint : ## Static code analysis with Pylint
pylint -ry climada_petals > pylint.log || true
pylint -ry climada_petals > pylint.log

.PHONY : unit_test
unit_test : ## Unit tests execution with coverage and xml reports
pytest $(PYTEST_ARGS) --ignore=climada_petals/test climada_petals/
$(PYTEST_CMD) $(PYTEST_ARGS) --ignore=climada_petals/test climada_petals/

.PHONY : install_test
install_test : ## Test installation was successful
pytest $(PYTEST_JUNIT_ARGS) --pyargs climada.engine.test.test_cost_benefit \
$(PYTEST_CMD) $(PYTEST_JUNIT_ARGS) --pyargs climada.engine.test.test_cost_benefit \
climada.engine.test.test_impact

.PHONY : data_test
Expand All @@ -37,11 +40,11 @@ notebook_test : ## Test notebooks in doc/tutorial

.PHONY : integ_test
integ_test : ## Integration tests execution with xml reports
pytest $(PYTEST_ARGS) climada_petals/test/
$(PYTEST_CMD) $(PYTEST_ARGS) climada_petals/test/

.PHONY : test
test : ## Unit and integration tests execution with coverage and xml reports
pytest $(PYTEST_ARGS) climada_petals/
$(PYTEST_CMD) $(PYTEST_ARGS) climada_petals/

.PHONY : ci-clean
ci-clean :
Expand Down
29 changes: 12 additions & 17 deletions script/jenkins/branches/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
pipeline {
agent any

environment {
FULL_PATH_BRANCH = "${sh(script:'git name-rev --name-only HEAD', returnStdout: true)}"
GIT_BRANCH = FULL_PATH_BRANCH.substring(FULL_PATH_BRANCH.lastIndexOf('/') + 1, FULL_PATH_BRANCH.length())
}

stages {
stage('setup-environment') {
steps {
sh "bash script/jenkins/branches/run_unittest.sh ${env.GIT_BRANCH}"
}
}
stage('ci') {
parallel {

stage('lint') {
steps {
sh '''#!/bin/bash
export PATH=$PATH:$CONDAPATH
source activate petals_env
rm -f pylint.log
pylint -ry climada_petals | tee pylint.log'''

sh "bash script/jenkins/branches/make_in_venv.sh ${env.GIT_BRANCH} lint"
discoverGitReferenceBuild referenceJob: 'petals_branches/develop'
recordIssues tools: [pyLint(pattern: 'pylint.log')]
}
}

stage('unit_test') {
steps {
sh '''#!/bin/bash
export PATH=$PATH:$CONDAPATH
source activate
# first install xemsf, then activate environment, so .../envs/.../etc/conda/activate.d/esmpy.sh is executed
# otherwise the environment varibalbe ESMFMKFILE is not initialized
mamba install -n petals_env -c conda-forge -y xesmf ruamel.yaml cdsapi
conda activate petals_env
rm -rf tests_xml/
rm -rf coverage/
make unit_test'''
sh "bash script/jenkins/branches/make_in_venv.sh ${env.GIT_BRANCH} unit_test PYTEST_COMMAND=\"python -m pytest\""
}
}

Expand Down
21 changes: 21 additions & 0 deletions script/jenkins/branches/make_in_venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
export PATH=$PATH:$CONDAPATH

source activate petals_env
rm -rf tests_xml/
rm -rf coverage/

BRANCH=$1
shift
CORENV=~/jobs/petals_branches/core_env
if [ -f $CORENV/$BRANCH ]; then
source tvenv/bin/activate
fi

make $@

if [ -f $CORENV/$BRANCH ]; then
deactivate
fi

conda deactivate
24 changes: 24 additions & 0 deletions script/jenkins/branches/setup_venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -e

export PATH=$PATH:$CONDAPATH

BRANCH=$1
CORENV=~/jobs/petals_branches/core_env

echo $CORENV/$BRANCH

if [ -f $CORENV/$BRANCH ]; then
echo file exists
cat $CORENV/$BRANCH

source activate petals_env

python -m venv --system-site-packages tvenv
source tvenv/bin/activate

pip install -e `cat $CORENV/$BRANCH`

deactivate
conda deactivate
fi

0 comments on commit e162bc5

Please sign in to comment.