-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
120 lines (110 loc) · 2.94 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
variables:
cran_url: https://cran.irsn.fr
set_cran: export CRAN=${cran_url};
set_rcran: options(repos='$cran_url');
DOCKER_IMAGE: w4mrutils
stages:
- build
- check
- test
- deploy
code quality check:
stage:
build
tags:
- ara-unh-sauron-shell
script:
- |
doc_count=$(grep -P "^#'" R/*.R | wc -l) ;
sloc_count=$(grep -P '^\s*[^#]{2,}' R/*.R | wc -l) ;
ratio=$(bc <<< "scale=2;$doc_count/$sloc_count*100" | cut -d. -f1) ;
echo "[documentation / code ratio = $ratio]"
if [ $ratio -lt 70 ];then
echo "Not enough documentation." ;
exit 1 ;
elif [ $ratio -lt 75 ];then
echo "Attention, the [documentation / code] ratio is very low" ;
fi
Build docker image:
stage:
build
tags:
- ara-unh-sauron-shell
script:
- last_image() { docker image ls --format "{{.Tag}}" $DOCKER_IMAGE | grep -Po '\d+'; }
- echo "==================================";
- echo "[info] Building Docker image for $DOCKER_IMAGE ";
- echo "Last image build is $(last_image) - $(($(date +'%Y%m%d') - $(last_image))) days old."
- if [[ "$(last_image)" = "" ]] || [[ $(($(date +'%Y%m%d') - $(last_image))) -ge 30 ]]; then
echo "Rebuilding $DOCKER_IMAGE image..." ;
docker rmi $DOCKER_IMAGE 2>/dev/null || true ;
docker rmi $DOCKER_IMAGE:$(last_image) 2>/dev/null || true ;
docker build -t $DOCKER_IMAGE $CI_PROJECT_DIR ;
docker tag $DOCKER_IMAGE:latest $DOCKER_IMAGE:$(date +'%Y%m%d') ;
else
echo "Already built." ;
fi
checking:
needs: ["Build docker image"]
stage: check
image: $DOCKER_IMAGE
allow_failure: true
script:
- R -q -e "devtools::check('$CI_PROJECT_DIR')"
tags:
- ara-unh-sauron-shell
# To have the coverage percentage appear as a gitlab badge follow these
# instructions:
# https://docs.gitlab.com/ee/user/project/pipelines/settings.html#test-coverage-parsing
# The coverage parsing string is
# Coverage: \d+\.\d+
testing:
needs: [checking]
stage: test
only:
- dev
- main
image: $DOCKER_IMAGE
allow_failure: true
when: on_success
script:
- R -q -e "devtools::test('$CI_PROJECT_DIR')"
- R -q -e "covr::gitlab(quiet = FALSE)"
artifacts:
paths:
- public
tags:
- ara-unh-sauron-docker
coverage:
'/ Coverage: \d+\.\d+/'
# To produce a code coverage report as a GitLab page see
# https://about.gitlab.com/2016/11/03/publish-code-coverage-report-with-gitlab-pages/
pages:
needs: [testing]
stage: deploy
only:
- main
image: $DOCKER_IMAGE
dependencies:
- testing
script:
- ls
artifacts:
paths:
- public
expire_in: 30 days
tags:
- ara-unh-sauron-docker
building conda recipe:
stage:
build
only:
- main
allow_failure:
true
image:
quay.io/condaforge/linux-anvil-cos7-x86_64
script:
- conda-build --override-channels -c conda-forge $CI_PROJECT_DIR/meta.yaml
tags:
- ara-unh-sauron-docker