-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
112 lines (107 loc) · 3.96 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
stages:
- build
- test
- documentation
- staging
- production
Build distribution:
stage: build
before_script:
- export PATH=$PATH:$PWD/../miniconda/bin/
- source $PWD/../miniconda/etc/profile.d/conda.sh
- conda update -n base -c defaults conda
- conda env create -f spleaf_env.yml
- conda activate spleaf
script:
- python setup.py sdist
after_script:
- conda deactivate
- conda env remove -n spleaf
artifacts:
paths:
- dist/*.tar.gz
expire_in: 1 day
Run test:
stage: test
before_script:
- export PATH=$PATH:$PWD/../miniconda/bin/
- source $PWD/../miniconda/etc/profile.d/conda.sh
- conda env create -f spleaf_env.yml
- conda activate spleaf
script:
- pip install dist/*.tar.gz
- cd test
- python -m pytest
after_script:
- conda deactivate
- conda env remove -n spleaf
Generate documentation:
stage: documentation
before_script:
- export PATH=$PATH:$PWD/../miniconda/bin/
- source $PWD/../miniconda/etc/profile.d/conda.sh
- conda env create -f spleaf_env.yml
- conda activate spleaf
script:
- pip install dist/*.tar.gz
- cd doc
- make html
after_script:
- conda deactivate
- conda env remove -n spleaf
artifacts:
paths:
- doc/build/html
expire_in: 1 day
Deploy on Staging:
stage: staging
script:
- cp dist/*.tar.gz /www/people/delisle/public/staging/spleaf
- rm -rf /www/people/delisle/public/staging/spleaf/doc/*
- cp -R doc/build/html/* /www/people/delisle/public/staging/spleaf/doc
Release and deploy on Production:
stage: production
before_script:
# According to documentation, gitlab uses detached HEAD and we need to go back to master to release.
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/19421
- git checkout -B master origin/master
- git config --global user.name 'Gitlab CI'
- git config --global user.email ''
- git remote set-url origin "https://gitlab-ci-token:[email protected]/jean-baptiste.delisle/spleaf.git"
- export PATH=$PATH:$PWD/../miniconda/bin/
- source $PWD/../miniconda/etc/profile.d/conda.sh
- conda env create -f spleaf_env.yml
- conda activate spleaf
script:
# Tag
- VERSION=`grep __version__ spleaf/__info__.py | sed 's/.*version__ = "//' | sed 's/"//'`
- TAG_VERSION="v$VERSION"
- git tag -a "$TAG_VERSION" -m "Release spleaf $TAG_VERSION"
- git push origin "$TAG_VERSION" --quiet
- CHANGES=`cat CHANGES.txt`
# Add release on gitlab (via gitlab API)
- curl -X POST -H "PRIVATE-TOKEN:$RELEASE_TOKEN" -F "name=Release spleaf $TAG_VERSION" -F "tag_name=$TAG_VERSION" -F "ref=$TAG_VERSION" -F "description=Changes:$CHANGES" 'https://gitlab.unige.ch/api/v4/projects/1383/releases'
# Deploy on https://obswww.unige.ch/~delisle/
- cp dist/*.tar.gz /www/people/delisle/public/spleaf
- rm -rf /www/people/delisle/public/spleaf/doc/*
- cp -R doc/build/html/* /www/people/delisle/public/spleaf/doc
- rm -rf /www/people/delisle/public/spleaf/doc_hist/${TAG_VERSION}
- cp -R doc/build/html /www/people/delisle/public/spleaf/doc_hist/${TAG_VERSION}
# Deploy on Pypi
- python -m twine upload dist/*.tar.gz
# Upgrade to next version
- MAJOR_DIGIT=`echo $VERSION | awk -F. '{print $1}'`
- MINOR_DIGIT=`echo $VERSION | awk -F. '{print $2}'`
- PATCH_DIGIT=`echo $VERSION | awk -F. '{print $3}'`
- PATCH_DIGIT=$((PATCH_DIGIT + 1))
- NEW_VERSION="$MAJOR_DIGIT.$MINOR_DIGIT.$PATCH_DIGIT"
- echo $NEW_VERSION
# Need to hack sed to work on both mac and unix. See details here : https://stackoverflow.com/questions/5694228/sed-in-place-flag-that-works-both-on-mac-bsd-and-linux
- sed -i.bak s"/version__ = \"$VERSION\"/version__ = \"$NEW_VERSION\"/g" spleaf/__info__.py
- git add spleaf/__info__.py
- git commit -m "Upgrade project to next version $NEW_VERSION"
- git push origin master --quiet
after_script:
- conda deactivate
- conda env remove -n spleaf
when: manual