-
Notifications
You must be signed in to change notification settings - Fork 12
/
.gitlab-ci.yml
196 lines (188 loc) · 7.67 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
stages:
- prepare-pipeline
- build-gcc
- run-tests
- build-clang
- release-validation
variables:
# GitLab CI variables
GIT_STRATEGY: clone
GIT_DEPTH: 0
# GitLab specific variables
GITLAB_BELLE2_TOOLS_B2SETUP: "/cvmfs/belle.cern.ch/tools/b2setup"
GITLAB_IS_FIRST_STAGE: "no"
GITLAB_FORCE_RUNNING_PIPELINE: "no"
GITLAB_RUNNER: "none"
# Define cvmfs as source for conditions metadata
BELLE2_CONDB_METADATA: "/cvmfs/belle.cern.ch/conditions/database.sqlite"
# The other BELLE2_ variables are defined in the "Variables" section of the CI/CD settings
workflow:
rules:
# We run the pipeline only if:
# - it is a merge request event
# - it is a merge commit in the main, release or upgrade branch
# - we force the pipeline
# Moreover, the pipelines are redirected to the runners extagent4 or extagent8
# according to some rules defined below
- &merge_request_rules
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_IID =~ /[02468]$/ # merge request event and even merge request ID
variables:
GITLAB_RUNNER: "extagent4"
- if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_IID =~ /[13579]$/ # merge request event and odd merge request ID
variables:
GITLAB_RUNNER: "extagent8"
- &push_rules
- if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_BRANCH == 'main' && $CI_COMMIT_TITLE =~ /Merge branch.*/ # merge commit in main branch
variables:
GITLAB_RUNNER: "extagent4"
- if: $CI_PIPELINE_SOURCE == 'push' && ($CI_COMMIT_BRANCH =~ /^release/ || $CI_COMMIT_BRANCH == 'upgrade') && $CI_COMMIT_TITLE =~ /Merge branch.*/ # merge commit in release or upgrade branch
variables:
GITLAB_RUNNER: "extagent8"
- &force_rules
- if: $GITLAB_FORCE_RUNNING_PIPELINE == 'yes' # forced pipeline
variables:
GITLAB_RUNNER: "extagent4"
default:
image: belle2/belle2-base-ubuntu2004:latest
tags:
- $GITLAB_RUNNER # The runner is dynamically assigned by the workflow rules
cache:
key: $CI_COMMIT_REF_SLUG
paths:
- .sconf_temp/
- .sconsign.dblite
- bin/
- build/
- config.log
- data/
- include/
- lib/
- modules/
- target_head_hash.txt
before_script:
# Preliminary operations with Git
- git config user.email "[email protected]"
- git config user.name "someone"
- git config --global --add safe.directory $(dirname ${GITLAB_BELLE2_TOOLS_B2SETUP})
# Clean the current directory by stashing the remaining modified files from previous builds
- git stash && git stash clear
# If this is not the first stage: merge the HEAD of the target branch
- |
if [ "${CI_PIPELINE_SOURCE}" == "merge_request_event" ]; then
if [ "${GITLAB_IS_FIRST_STAGE}" != "yes" ]; then
echo "Merging the branch ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} up to commit $(< target_head_hash.txt) into this branch"
git fetch --all && git merge $(< target_head_hash.txt) --strategy-option ours --no-commit --allow-unrelated-histories
fi
fi
# Preliminary operations necessary for basf2
- unset DISPLAY
- if [ ! -f .release ]; then echo "head" > .release; fi
- rm -rf .git/hooks && ln -sf $(dirname ${GITLAB_BELLE2_TOOLS_B2SETUP})/hooks .git/hooks
- ln -fs site_scons/SConstruct
- source ${GITLAB_BELLE2_TOOLS_B2SETUP}
interruptible: true # All the jobs can be interrupted by newer pipelines
prepare-pipeline:
stage: prepare-pipeline
needs: []
variables:
GITLAB_IS_FIRST_STAGE: "yes"
script:
- echo "stage start time -> $(date +%H:%M:%S)"
# Identify the current HEAD of the target branch and cache it
- |
if [ "${CI_PIPELINE_SOURCE}" == "merge_request_event" ]; then
git rev-parse origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} > target_head_hash.txt
echo "The current HEAD of the branch ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} is $(< target_head_hash.txt)"
fi
- echo "stage stop time -> $(date +%H:%M:%S)"
build-gcc:
stage: build-gcc
needs: [prepare-pipeline]
script:
- echo "stage start time -> $(date +%H:%M:%S)"
- b2code-option opt
- scons --no-debuginfo
- basf2 --info
- echo "stage stop time -> $(date +%H:%M:%S)"
run-tests:
stage: run-tests
needs: [build-gcc]
artifacts:
when: always
reports:
junit:
- output_tests_reports/tests-google.xml
- output_tests_reports/tests-framework.xml
- output_tests_reports/tests-non-framework.xml
expose_as: 'sphinx documentation'
paths:
- build_doc/html/
script:
- echo "stage start time -> $(date +%H:%M:%S)"
- mkdir -p input_tests_reports output_tests_reports
# Download the tests reports from the main branch
- |
PACKAGE="tests-reports"
VERSION="main"
FILES=("tests-google.xml" "tests-framework.xml" "tests-non-framework.xml")
for FILE in "${FILES[@]}"; do
curl -L --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --output "input_tests_reports/${FILE}" \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${PACKAGE}/${VERSION}/${FILE}"
done
# Run the "google" tests and the "scripts" tests
- b2code-option opt
- export BELLE2_SPHINX_OUTPUTDIR=${BELLE2_LOCAL_DIR}/build_doc/
- b2test-units --gtest_output=xml:${BELLE2_LOCAL_DIR}/output_tests_reports/tests-google.xml
- b2test-scripts -j $(nproc) --filter "^framework/tests/(?!(foreach.py))" --xml-input=${BELLE2_LOCAL_DIR}/input_tests_reports/tests-framework.xml --xml=${BELLE2_LOCAL_DIR}/output_tests_reports/tests-framework.xml --timeout 1200
- b2test-scripts -j $(nproc) --filter "^(?!framework/tests/.*)" --xml-input=${BELLE2_LOCAL_DIR}/input_tests_reports/tests-non-framework.xml --xml=${BELLE2_LOCAL_DIR}/output_tests_reports/tests-non-framework.xml --timeout 1200
# Upload the tests reports (only if this is the main branch)
- |
if [[ "$CI_COMMIT_BRANCH" == "main" ]]; then
for FILE in "${FILES[@]}"; do
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file "output_tests_reports/${FILE}" \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${PACKAGE}/${VERSION}/${FILE}"
done
fi
- echo "stage stop time -> $(date +%H:%M:%S)"
build-clang:
stage: build-clang
needs: [run-tests]
rules:
- *push_rules
- *force_rules
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
when: never
script:
- echo "stage start time -> $(date +%H:%M:%S)"
- b2code-option clang
- scons --no-debuginfo
- basf2 --info
- echo "stage stop time -> $(date +%H:%M:%S)"
release-validation:
stage: release-validation
needs: [run-tests]
artifacts:
when: on_success
paths:
- automated_validation_*
expire_in: 60 days
rules:
- *force_rules
- if: $CI_PIPELINE_SOURCE == 'push' && $CI_COMMIT_BRANCH == $GITLAB_BRANCH_FOR_RELEASE_VALIDATION && $CI_COMMIT_TITLE =~ /Merge branch.*/
variables:
GITLAB_RUNNER: "extagent8"
script:
- echo "stage start time -> $(date +%H:%M:%S)"
# Set release to branch name but replace / with -
- export BELLE2_RELEASE=${CI_COMMIT_BRANCH//\//-}
# In case this pipeline is manually triggered, let's check if the user passed a staging globaltag
- |
if [ "${GITLAB_FORCE_RUNNING_PIPELINE}" == "yes" ]; then
if [ "${GITLAB_STAGING_GLOBALTAG}" != "none" ]; then
export VALIDATION_GLOBALTAG=${GITLAB_STAGING_GLOBALTAG}
fi
fi
- b2code-option opt
- basf2 --info
- hlt/tests/release_validation/run.sh automatic automated_validation_${CI_COMMIT_BRANCH//\//-}_$(date +%Y-%m-%d_%H-%M-%S)
- echo "stage stop time -> $(date +%H:%M:%S)"