-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
365 lines (350 loc) · 14.5 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
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# Copyright 2018-2025 The University of Birmingham
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
default:
before_script:
- export REPO=`echo $CI_PROJECT_URL | sed -e s#https://##`
- git remote set-url origin https://hog_user:${HOG_PUSH_TOKEN}@$REPO
- git config --global user.email "[email protected]"
- git config --global user.name "hog_user"
- git fetch
- git fetch origin $CI_COMMIT_REF_NAME
- git checkout $CI_COMMIT_REF_NAME --
- git status
- source ./Other/CommonFunctions.sh
- print_hog .
stages: [mirrors, merge_checks, tag, build_doc]
launch_github:
stage: merge_checks
image: gitlab-registry.cern.ch/hog/hog-docker:master
only:
refs: [merge_requests]
variables: [$CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(master|develop)$/]
except:
variables: [$CI_COMMIT_REF_NAME =~ /^test\/.*$/i]
script:
- glab auth login -t $HOG_PUSH_TOKEN -h $CI_SERVER_HOST
- gh auth status
- git clone https://hog-user:${GITHUB_TOKEN}@github.com/hog-CERN/TestFirmware.git
- cd TestFirmware/
# Let's wait 60s for the mirror to update
- sleep 60
- git submodule init Hog
- git submodule update Hog
- if git branch -a | grep -q "auto/$CI_COMMIT_REF_NAME"; then
git checkout auto/$CI_COMMIT_REF_NAME;
git branch --set-upstream-to=origin/auto/$CI_COMMIT_REF_NAME auto/$CI_COMMIT_REF_NAME;
git pull;
else
git checkout -b auto/$CI_COMMIT_REF_NAME;
fi
- cd Hog
- git checkout $CI_COMMIT_SHA
- cd ..
- perl -pi -e 's/^\s*uses:.*$/ uses:\ hog-CERN\/Hog\/.github\/workflows\/Hog-main.yml\@'"$CI_COMMIT_SHA"'/' .github/workflows/main.yml
- perl -pi -e 's/^\s*uses:.*$/ uses:\ hog-CERN\/Hog\/.github\/workflows\/Hog-pull.yml\@'"$CI_COMMIT_SHA"'/' .github/workflows/pull.yml
- perl -pi -e 's/^\s*uses:.*$/ uses:\ hog-CERN\/Hog\/.github\/workflows\/Hog-tag.yml\@'"$CI_COMMIT_SHA"'/' .github/workflows/tag.yml
- git diff-index --quiet HEAD || git commit -am "Updating Hog to $CI_COMMIT_SHA"
- git push -u https://hog-user:${GITHUB_TOKEN}@github.com/hog-CERN/TestFirmware.git auto/$CI_COMMIT_REF_NAME
# Check if there is already a MR open with the current branch, if not open it
- PR_NR=$(gh pr list -R hog-CERN/TestFirmware -H auto/${CI_COMMIT_REF_NAME} -B develop --json number -q '.[0].number')
- if [[ "$PR_NR" == "" ]]; then
echo "There are no open pull requests with source branch 'auto/$CI_COMMIT_REF_NAME'. I will open one...";
gh pr create -H auto/$CI_COMMIT_REF_NAME -B develop -f -R hog-CERN/TestFirmware;
PR_NR=$(gh pr list -R hog-CERN/TestFirmware -H apptainer --json number -q '.[0].number');
else
gh pr view $PR_NR;
fi;
- sleep 10s
- gh pr checks $PR_NR --watch
interruptible: true
allow_failure: true
launch_testfirmware:
stage: merge_checks
image: gitlab-registry.cern.ch/hog/hog-docker:master
variables:
GITLAB_TOKEN: $TF_TOKEN
only:
refs: [merge_requests]
variables: [$CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(master|develop)$/]
except:
variables: [$CI_COMMIT_REF_NAME =~ /^test\/.*$/i]
script:
# Clone TestFirmware
- git clone --recursive https://hog_user:${HOG_PUSH_TOKEN}@gitlab.com/hog-cern/test/TestFirmware.git
- cd TestFirmware/
# Check if auto-generated Hog branch exists
- if git branch -a | grep -q "auto/$CI_COMMIT_REF_NAME"; then
git checkout auto/$CI_COMMIT_REF_NAME;
git branch --set-upstream-to=origin/auto/$CI_COMMIT_REF_NAME auto/$CI_COMMIT_REF_NAME;
git pull;
else
git checkout -b auto/$CI_COMMIT_REF_NAME;
fi
- cd Hog
- git checkout $CI_COMMIT_SHA
- cd ..
- sed -i '/ref:/s#.*# ref:\ '"$CI_COMMIT_SHA"'#' .gitlab-ci.yml
- git diff-index --quiet HEAD || git commit -am "Updating Hog to $CI_COMMIT_SHA"
- git push origin auto/$CI_COMMIT_REF_NAME
# Check if there is already a MR open with the current branch, if not open it
- response=$(glab mr list -F json -R hog-cern/test/TestFirmware --source-branch=auto/$CI_COMMIT_REF_NAME --target-branch=develop)
- if [ $? -eq 0 ]; then
if [ $(echo "$response" | jq length) -gt 0 ]; then
MR_ID=$(echo "$response" | jq .[0].iid);
MR_URL=$(echo "$response" | jq .[0].web_url);
echo "There is already an open merge request with source branch 'auto/$CI_COMMIT_REF_NAME'.";
echo "$MR_URL";
else
echo "There are no open merge requests with source branch 'auto/$CI_COMMIT_REF_NAME'. I will open one...";
glab mr create -s auto/$CI_COMMIT_REF_NAME -b develop -t "Automatic MR with Hog branch $CI_COMMIT_REF_NAME" -R hog-cern/test/TestFirmware --remove-source-branch -y -f;
response=$(glab mr list -F json -R hog-cern/test/TestFirmware --source-branch=auto/$CI_COMMIT_REF_NAME --target-branch=develop)
MR_ID=$(echo "$response" | jq .[0].iid);
MR_URL=$(echo "$response" | jq .[0].web_url);
fi;
else
echo "Failed to retrieve merge requests. Please check your GitLab API endpoint and token.";
exit 1;
fi;
- sleep 10s
- i=0
- while true; do
mr_response=$(glab mr view $MR_ID -R hog-cern/test/TestFirmware -F json)
pipeline_status=$(echo "$mr_response" | jq -r '.pipeline.status');
pipeline_url=$(echo "$mr_response" | jq -r '.pipeline.web_url');
if [ $i = 0 ]; then
echo "Waiting for TestFirmware pipeline to finish...";
echo "Pipeline Status $pipeline_status";
echo "Pipeline URL $pipeline_url";
i=1;
fi;
if [ "$pipeline_status" == "failed" ]; then
echo "TestFirmware pipeline failed. $pipeline_url";
exit 1;
elif [ "$pipeline_status" == "success" ]; then
echo "TestFirmware pipeline was successful!";
break;
fi;
sleep 5;
done
interruptible: true
allow_failure: true
build-doxygen-test:
stage: merge_checks
image: gitlab-registry.cern.ch/hog/hog-docker:master
only:
refs: [merge_requests]
variables: [$CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(master|develop)$/]
except:
variables: [$CI_COMMIT_REF_NAME =~ /^test\/.*$/i]
before_script: [echo ""]
script:
- git clone https://hog:${CERN_PUSH_TOKEN}@gitlab.cern.ch/hog/hog-doxygen.git
doxygen
- chmod +x ./doxygen/scripts/build-and-deploy.sh
- ./doxygen/scripts/build-and-deploy.sh /eos/user/h/hog/www/doxy-test
artifacts:
name: doxygen
paths:
- DOXY_DOCS/
interruptible: true
build-doxygen-develop:
stage: build_doc
image: gitlab-registry.cern.ch/hog/hog-docker:master
only:
refs: [tags]
variables: [$CI_COMMIT_TAG =~ /^(v.*)$/]
before_script: [echo ""]
script:
- git clone https://hog:${CERN_PUSH_TOKEN}@gitlab.cern.ch/hog/hog-doxygen.git
doxygen
- chmod +x ./doxygen/scripts/build-and-deploy.sh
- ./doxygen/scripts/build-and-deploy.sh /eos/user/h/hog/www/doxy-develop
build-doxygen-official:
stage: build_doc
image: gitlab-registry.cern.ch/hog/hog-docker:master
only:
refs: [tags]
variables: [$CI_COMMIT_TAG =~ /^(Hog.*)$/]
before_script: [echo ""]
script:
- git clone https://hog:${CERN_PUSH_TOKEN}@gitlab.cern.ch/hog/hog-doxygen.git
doxygen
- chmod +x ./doxygen/scripts/build-and-deploy.sh
- ./doxygen/scripts/build-and-deploy.sh /eos/user/h/hog/www/doxy-master
changelog:
stage: merge_checks
image: gitlab-registry.cern.ch/hog/hog-docker:master
rules:
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master" && $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME != "develop"
when: on_success
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"
when: on_success
script:
- glab auth login -t $HOG_PUSH_TOKEN -h $CI_SERVER_HOST
- if [[ $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ "master" ]] ; then
if [[ $CI_COMMIT_REF_NAME != hotfix* ]]; then
echo "[ERROR] The target of this MR is $CI_MERGE_REQUEST_TARGET_BRANCH_NAME, but the source is not a hotfix branch ($CI_COMMIT_REF_NAME). Please, change the name of source branch or direct the MR to develop.";
echo "[Hog::INFO] A hotfix branch name should start with hotfix/.";
exit 1;
fi;
fi;
- git fetch origin refs/notes/*:refs/notes/*
- "NEW_TAG=`echo \"source Tcl/hog.tcl; puts v[HexVersionToString [GetVer . 1]]\" | tclsh`"
- echo "New tag is $NEW_TAG"
- git notes add -fm "$CI_MERGE_REQUEST_IID $CI_COMMIT_REF_NAME $NEW_TAG"
- git push origin refs/notes/*
- "printf \"## Repository info\n- Merge request number: $CI_MERGE_REQUEST_IID\n\
- Branch name: $CI_COMMIT_REF_NAME\n\n\" > changelog.md"
- ./Other/Changelog.sh -t $CI_MERGE_REQUEST_TARGET_BRANCH_NAME -n $CI_MERGE_REQUEST_IID >> changelog.md
artifacts:
name: changelog
paths: [changelog.md]
expire_in: 1 month
interruptible: true
tagging:
stage: tag
image: gitlab-registry.cern.ch/hog/hog-docker:master
rules:
- if: '$CI_COMMIT_REF_NAME == "master" && $CI_PIPELINE_SOURCE == "push"'
when: always
- if: '$CI_COMMIT_REF_NAME == "develop" && $CI_PIPELINE_SOURCE == "push"'
when: always
- when: never
script:
- glab auth login -t $HOG_PUSH_TOKEN -h $CI_SERVER_HOST
- git fetch origin refs/notes/*:refs/notes/*
- note=(`git notes show`) || {
echo "No note found, probably you pushed to a branch that should protected (e.g. master, develop)";
exit 1;
}
- new_tag=${note[2]}
- present_tag=(`git describe`)
- if [ $present_tag != $new_tag ]; then
if [ "$(git tag --list ${new_tag}*)" != "" ]; then
latest_tag=(`git tag -l ${new_tag}* --sort=-v:refname --merged`);
if [[ $latest_tag =~ .*-(.*) ]]; then
nr="${BASH_REMATCH[1]}";
new_tag="$new_tag-$(($nr+1))";
else
new_tag="$new_tag-0";
fi;
fi;
git tag $new_tag -m "Official_version_${new_tag}";
git push --tags;
else
echo "Tagging is not necessary because the present commit is already tagged as $new_tag.";
fi;
- mr=${note[0]}
- desc=$(glab mr view ${mr} -F json | jq -r ".description")
- if [[ $desc =~ Closes\ \#([0-9]+) ]]; then
issue_number="${BASH_REMATCH[1]}";
echo "Closing issue $issue_number...";
glab issue close $issue_number;
fi
- branch=${note[1]}
- git clone --recursive https://hog_user:${HOG_PUSH_TOKEN}@gitlab.com/hog-cern/test/TestFirmware.git
- cd TestFirmware/
# Check if there is still a branch connected to the merged MR
- if git branch -a | grep -q "auto/$branch"; then
git checkout auto/$branch;
git branch --set-upstream-to=origin/auto/$branch auto/$branch;
set +e; MERGE_STATUS=$(git merge --no-commit origin/develop); set -e;
if [ "$MERGE_STATUS" == "Already up to date." ]; then
response=$(glab mr list -F json -R hog-cern/test/TestFirmware --source-branch=auto/$branch --target-branch=develop);
if [ $? -eq 0 ]; then
if [ $(echo "$response" | jq length) -gt 0 ]; then
MR_ID=$(echo "$response" | jq .[0].iid);
MR_URL=$(echo "$response" | jq .[0].web_url);
echo "Merging MR on TestFirmware.";
glab mr merge $MR_ID -d;
fi;
else
git push origin --delete auto/$branch;
fi;
else
echo "Branch is outdated with respect to develop. Deleting it...";
git push origin --delete auto/$branch;
fi;
fi;
shellcheck:
stage: merge_checks
image: gitlab-registry.cern.ch/hog/hog-docker:master
only:
refs: [merge_requests]
variables: [$CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(master|develop)$/]
except:
variables: [$CI_COMMIT_REF_NAME =~ /^test\/.*$/i]
script:
- shellcheck -x -S error Other/*.sh *.sh
interruptible: true
yamllint:
stage: merge_checks
image: gitlab-registry.cern.ch/hog/hog-docker:master
only:
refs: [merge_requests]
variables: [$CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(master|develop)$/]
except:
variables: [$CI_COMMIT_REF_NAME =~ /^test\/.*$/i]
script:
- yamllint -c /scripts/hog-yaml.yaml YAML/*.yml *.yml .gitlab-ci.yml .github/workflows/*.yml
Templates/*.yml
interruptible: true
nagelfar:
stage: merge_checks
image: gitlab-registry.cern.ch/hog/hog-docker:master
only:
refs: [merge_requests]
variables: [$CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(master|develop)$/]
except:
variables: [$CI_COMMIT_REF_NAME =~ /^test\/.*$/i]
script:
- /scripts/nagelfar133/nagelfar.tcl -Wunusedvar -filter "*Unknown command*" -filter "*Found constant*which is also a variable*" Tcl/*.tcl
Tcl/*/*.tcl
interruptible: true
update_mirrors:
stage: mirrors
image: gitlab-registry.cern.ch/hog/hog-docker:master
script:
- glab auth login -t $HOG_PUSH_TOKEN -h $CI_SERVER_HOST
# Update Mirror
- glab api /projects/37942198/remote_mirrors/517789/sync --method POST
- glab api /projects/37942198/remote_mirrors/1748198/sync --method POST
interruptible: true
create_release_note:
stage: tag
image: gitlab-registry.cern.ch/hog/hog-docker:master
only:
refs: [tags]
variables: [$CI_COMMIT_TAG =~ /^(v.*)|(Hog.*)$/]
script:
- glab auth login -t $HOG_PUSH_TOKEN -h $CI_SERVER_HOST
- git fetch origin refs/notes/*:refs/notes/*
- MR=( `git notes show` )
- ref=refs/merge-requests%2F$MR%2Fhead
- glab job artifact $ref changelog
- if [[ $CI_COMMIT_TAG =~ ^v.*$ ]]; then
glab release create $CI_COMMIT_TAG -F changelog.md -n "Beta version $CI_COMMIT_TAG";
fi
- if [[ $CI_COMMIT_TAG =~ ^Hog.*$ ]]; then
glab release create $CI_COMMIT_TAG -F changelog.md -n "Official version $CI_COMMIT_TAG";
fi
# launch_validation:
# image: gitlab-registry.cern.ch/hog/hog-docker:master
# only: [develop]
# script:
# - 'if [[ $CI_COMMIT_REF_NAME == "develop" ]]; then curl --request POST --header
# "PRIVATE-TOKEN: ${HOG_PUSH_TOKEN}" "$CI_API_V4_URL/projects/40979880/pipeline_schedules/311873/play";
# fi;'
# stage: tag