-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
272 lines (260 loc) · 8.26 KB
/
.gitlab-ci.yml
File metadata and controls
272 lines (260 loc) · 8.26 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
workflow:
# Run if tag is 0.00.00 indicating a release
# or pipeline ist started manually in gitlab
rules:
- if: $CI_COMMIT_TAG =~ /^[0-9]*\.[0-9]*\.[0-9]*$/
- if: $CI_PIPELINE_SOURCE == "web" || $CI_JOB_MANUAL == "true"
variables:
DISTRIBUTIONS: ""
GITHUB_USER: "cdruee"
stages:
- build
- test
- package
- deploy
build_sdist:
image: python:latest
stage: build
before_script:
- pip install setuptools
script:
- python setup.py sdist
- echo 'ls dist/*tar.gz'
- ls dist/*tar.gz
- echo 'cd dist && ls *tar.gz'
- echo "$( cd dist && ls *tar.gz )"
- echo "BUILD_VERSION=$( cd dist && ls *tar.gz )" >> build.env
- echo "BUILD_JOB=${CI_JOB_ID}" >> build.env
artifacts:
paths:
- dist
reports:
dotenv: build.env
build_pages:
image: python:latest
stage: build
rules:
- exists:
- docs/conf.py
script:
- pip install setuptools
- pip install sphinx sphinx-argparse
- pip install numpy pandas
- BUILDING_SPHINX=true sphinx-build -b html docs build/sphinx/html
- mv build/sphinx/html/ public/
artifacts:
paths:
- public
test_latest:
image: python:latest
stage: test
script:
- pip install pytest numpy pandas
- pytest tests
build_deb:
stage: package
image: $PUBLISHER:$DISTRIB
needs:
- job: build_sdist
artifacts: true
- job: test_latest
script:
- export DEBIAN_FRONTEND=noninteractive
- apt update
- apt-get -y install dh-python debhelper dh-make
- apt-get -y install python3-all
- apt-get -y install python3-numpy python3-pandas
- apt-get -y install python3-setuptools python3-all python3-stdeb
- bash -x ./ci_build_deb.sh $BUILD_VERSION
- echo "DEB_${DISTRIB^^}_VERSION=$( cd deb_dist/$DISTRIB && ls *deb )" | tee -a build.env
- echo "DEB_${DISTRIB^^}_JOB=${CI_JOB_ID}" | tee -a build.env
- cat build.env
artifacts:
paths:
- deb_dist
reports:
dotenv: build.env
parallel:
matrix:
- PUBLISHER: ubuntu
DISTRIB:
- focal
- jammy
- noble
- PUBLISHER: debian
DISTRIB:
- bullseye
- bookworm
merge_github:
stage: package
image: alpine
before_script:
# install ssh-agent if not already installed
- command -v ssh-agent >/dev/null || apk add --update openssh-client
# create the .ssh directory and set permissions
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- cp $SSH_PRIVATE_KEY ~/.ssh/id_rsa
- chmod 400 ~/.ssh/id_rsa
- cp $SSH_PUBLIC_KEY ~/.ssh/id_rsa.pub
- chmod 444 ~/.ssh/id_rsa.pub
script:
- apk add --update git
- git config --global user.email "$GITLAB_USER_EMAIL"
- git config --global user.name "$GITLAB_USER_NAME"
- echo remote set-url origin "https://ci_access_token:$CI_ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME.git"
- git remote set-url origin "https://ci_access_token:$CI_ACCESS_TOKEN@$CI_SERVER_HOST/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME.git"
- git branch -avv
- git pull --rebase origin main
# prepare access to github
- ssh-keygen -lf ~/.ssh/id_rsa
- ssh-keygen -lf ~/.ssh/id_rsa.pub
- ssh-keyscan -H github.com >> ~/.ssh/known_hosts
- ssh -T git@github.com || echo "no shell access is OK"
- git remote add -t github github "ssh://git@github.com/$GITHUB_USER/$CI_PROJECT_NAME.git"
- git branch -avv
# first synch repo and from github.com branches
- git fetch --refetch -f github github
- git branch -avv
- git checkout github
- git branch -avv
- git pull --rebase origin github
- git branch -avv
# puch synched branches
- git push origin github
- git push github github
- git branch -avv
# then merge repo main branch into local working dir (github branch)
- git merge --squash origin/main -X theirs --allow-unrelated-histories | 2>&1 tee git.out
- git branch -avv
# if there was nothing new, exit graceful
- if grep -q "Already up to date" git.out ; then exit 0 ; else rm git.out; fi
# check if something is to commit (diff-index non-zero exit), commit if there is
- git diff-index --quiet --cached HEAD || git commit -a -m "Squash merge main into github"
- git branch -avv
# push working dir back into repo github branch
- git push origin github
# push working dir also to github.com
- git push github github
- if ! [[ "x$CI_COMMIT_TAG" == "x" ]]; then git push origin $CI_COMMIT_TAG; fi
deploy_pages:
image: python:latest
stage: deploy
needs:
- job: build_pages
artifacts: true
- job: build_deb
script:
- touch public
artifacts:
paths:
- public
release:
image: ubuntu:latest
stage: deploy
needs:
- job: build_sdist
artifacts: true
- job: build_deb
artifacts: true
- job: test_latest
before_script:
- echo "Running the release job."
- apt update
- apt -y install curl jq
- curl --location --output /usr/local/bin/release-cli "https://gitlab.com/api/v4/projects/gitlab-org%2Frelease-cli/packages/generic/release-cli/latest/release-cli-linux-amd64"
- chmod +x /usr/local/bin/release-cli
script:
- echo "Running the release job.1"
- export SDIST_NAME="Python install package - ${BUILD_VERSION}"
- echo SDIST_NAME $SDIST_NAME
- 'export SDIST_URL=${CI_PROJECT_URL}/-/jobs/${BUILD_JOB}/artifacts/raw/dist/${BUILD_VERSION}'
- echo SDIST_URL $SDIST_URL
- export ASSET_ARGS='[{"name":"'$SDIST_NAME'","url":"'$SDIST_URL'"}'
- echo ASSET_ARGS $ASSET_ARGS
- DISTRIBUTIONS=$( ls deb_dist | tr "\n" " ")
- |
for DISTRIB in $DISTRIBUTIONS; do
echo distrib $DISTRIB
echo DISTRIB ${DISTRIB^^}
VERNAM=DEB_${DISTRIB^^}_VERSION
echo VERNAM $VERNAM
JOBNAM=DEB_${DISTRIB^^}_JOB
echo JOBNAM $JOBNAM
name="binary install package for $DISTRIB - ${!VERNAM}"
echo name $name
url="${CI_PROJECT_URL}/-/jobs/${!JOBNAM}/artifacts/raw/deb_dist/${DISTRIB}/${!VERNAM}"
echo url $url
asset_info='{"name":"'$name'","url":"'$url'"}'
echo asset_info $asset_info
ASSET_ARGS="$ASSET_ARGS, $asset_info"
done
ASSET_ARGS=$ASSET_ARGS']'
- echo "..."
- 'jq . <<< $ASSET_ARGS'
- echo "..."
- if [[ "$CI_COMMIT_TAG" == "" ]]; then echo "CI_COMMIT_TAG is empty"; exit 0; fi
- echo "..."
- 'echo release-cli create --name "$CI_COMMIT_TAG" --tag-name "$CI_COMMIT_TAG" --description "$CI_COMMIT_MESSAGE" --ref "$CI_COMMIT_TAG" --assets-link "$( jq -c . <<< $ASSET_ARGS )"'
- 'release-cli create --name "$CI_COMMIT_TAG" --tag-name "$CI_COMMIT_TAG" --description "$CI_COMMIT_MESSAGE" --ref "$CI_COMMIT_TAG" --assets-link "$( jq -c . <<< $ASSET_ARGS )"'
deploy_deb:
image: ubuntu:latest
stage: deploy
needs:
- job: build_sdist
artifacts: true
- job: build_deb
artifacts: true
before_script:
- 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- cp $SSH_PRIVATE_KEY ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- eval $(ssh-agent -s)
- ssh-add ~/.ssh/id_rsa
- apt install -y curl dupload
- curl ifconfig.me
- ssh-keyscan -H 'uwmhub.uni-trier.de' >> ~/.ssh/known_hosts
script:
- ls -l
- export RESDIR="deb_dist"
- ls -l $RESDIR
- |
cat > ~/.dupload.conf << EOF
package config;
\$default_host = "uwmhub";
\$cfg{'uwmhub'} = {
fqdn => "uwmhub.uni-trier.de",
method => "scp",
login => "reprepro",
incoming => "/home/reprepro/incoming/",
# files pass on to dinstall which sends emails itself
dinstall_runs => 1,
};
EOF
- cat ~/.dupload.conf
- |
for X in $( ls $RESDIR ); do
pushd $RESDIR/$X
ls -l
for Y in *.changes; do
sed -i s/Distribution:\ .\*/Distribution:\ "${X}"/ $Y
cat $Y
dupload -f --nomail -t uwmhub $Y
sleep 60
done
popd
done
- echo "Ende"
deploy_pypi:
image: python:latest
stage: deploy
needs:
- job: build_deb
- job: build_sdist
artifacts: true
script:
- pip install twine
- twine check dist/*tar.gz
- twine upload --repository-url https://upload.pypi.org/legacy/ --username __token__ --password $PYPI_ID_TOKEN dist/*tar.gz