forked from riscv-collab/riscv-gnu-toolchain
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path.gitlab-ci.yml
269 lines (261 loc) · 8.97 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
variables:
SHARELOC: /home/share/devtools/toolchain/nuclei_gnu
# https://docs.gitlab.com/ee/ci/runners/configure_runners.html#git-strategy
# fetch strategy will met a lot of strange issues when using with submodule such as
# fatal: not a git repository: dejagnu/../.git/modules/dejagnu
# so just do a fresh clone without update submodule
GIT_STRATEGY: clone
# don't clone submodule
GIT_SUBMODULE_STRATEGY: none
# clone depth set to a small number
GIT_DEPTH: "3"
IMGSVR: rego.corp.nucleisys.com/software
LINBUILDIMG: "gnutoolchain-centos6"
WINBUILDIMG: "gnutoolchain-ubuntu20.04"
IMGTAG: "latest"
JOBS: 32
workflow:
rules:
- if: $CI_COMMIT_MESSAGE =~ /draft|wip|stash/i
when: never
- if: $CI_COMMIT_BRANCH =~ /nuclei|feature/
- if: $CI_COMMIT_TAG =~ /nuclei-/
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /nuclei|feature/ && $CI_PIPELINE_SOURCE == "merge_request_event"
stages:
- prepare
- build
- test
- deploy
prepare_source:
stage: prepare
interruptible: true
# https://docs.gitlab.com/ee/ci/yaml/#timeout
# clone takes about 10min, upload artifacts need more time
timeout: 30m
retry:
max: 2
when:
# ERROR: Job failed (system failure): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (docker.go:534:120s)
# https://docs.gitlab.com/ee/ci/yaml/#retrywhen
- runner_system_failure
image: $IMGSVR/$LINBUILDIMG:$IMGTAG
variables:
# develop branch is used to track latest working version
# master branch is used to track latest release version
libncrtbranch: develop
script:
- free -g
- command -v ssh-agent >/dev/null
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
# ssh-add - doesn't work in centos6. error with No such file or directory
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
# important: need to avoid git ssh asking yes/no when clone
# https://serverfault.com/questions/469052/ssh-failing-from-script-working-on-command-line-git
- ssh-keyscan gito > ~/.ssh/known_hosts
- ssh-keyscan gito.corp.nucleisys.com >> ~/.ssh/known_hosts
- pwd
- git remote -v
- echo $CI_REPOSITORY_URL
- git remote set-url origin git@gito.corp.nucleisys.com:software/devtools/riscv-gnu-toolchain.git
# https://stackoverflow.com/questions/6842687/the-remote-end-hung-up-unexpectedly-while-git-cloning
- git config --global http.postBuffer 256M
- git config --global http.maxRequestBuffer 256M
# sync url using ssh url, clean repo and its submodule
- git submodule init || true
- git submodule sync || true
- git submodule || true
- git clean -fdx
- git submodule foreach --recursive git clean -xfdf || true
- git reset --hard || true
# enable git trace
#- export GIT_TRACE=1
# reset repo and its submodule repo
#- git reset --hard --recurse-submodules || true
# prepare toolchain source code
- FORCE_SUBMODULE=1 CLONE_DEPTH=1 ./scripts/toolchain/prepsrc.sh ${libncrtbranch}
# Download gcc prerequisites
- |
cd gcc
downscript=contrib/download_prerequisites
if [ ! -f $downscript ] ; then
echo "ERROR: gcc repo maybe not complete!"
exit 1
fi
echo "INFO: Download gcc prerequisites..."
./$downscript
cd ..
artifacts:
name: "rvtoolchain_source-${CI_COMMIT_SHA::8}"
paths:
- ./*
tags:
- env::docker
- build::toolchain
- host::whss4
## Job template
.build_job_template: &build_job_template_default
stage: build
timeout: 6h
interruptible: true
# https://docs.gitlab.com/ee/ci/yaml/index.html#retrywhen
retry:
max: 2
when:
# ERROR: Job failed (system failure): Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running? (docker.go:534:120s)
- runner_system_failure
needs:
- job: prepare_source
artifacts: true
variables:
GIT_STRATEGY: none
artifacts:
name: "${CI_JOB_NAME}-${citooltype}_${CI_COMMIT_SHA::8}"
when: always
paths:
- "*.log"
- "*.env"
- cigen
before_script:
# check toolchain repo status
- |
echo "INFO: Show current repo status"
git status --ignored=matching || true
git submodule || true
# show also untracked files
git submodule foreach git status --ignored=matching || true
# force reset repo and its submodule source code
echo "INFO: Hard reset repo and its submodule source code"
git reset --hard || true
git submodule foreach git reset --hard || true
# remove glibc/newlibc untracked files
for cddir in newlib glibc; do git -C $cddir clean -fdx ; done || true
echo "INFO: Show repo status after reset"
git status || true
git submodule || true
echo "INFO: toolchain repo is ready!"
# check libncrt repo status
- |
if [ ! -d libncrt ] ; then
echo "ERROR: libncrt repo doesn't exist, exit now!"
exit 1
fi
pushd libncrt
git reset --hard || true
git submodule foreach git reset --hard || true
git submodule || true
popd
echo "INFO: libncrt repo is ready!"
# set the toolver to branch name or tag name, see https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
- if [ ${CI_COMMIT_TAG} ] ; then export citoolver=${CI_COMMIT_TAG/nuclei-/} ; else export citoolver=${CI_COMMIT_REF_SLUG}${CI_MERGE_REQUEST_PROJECT_ID} ; fi
- echo "Build for toolchain version $citoolver, toolchain type $citooltype"
- mkdir -p cigen
- export CIARCLOC=$(pwd)/cigen
- echo "CI Artifacts will be generated into $CIARCLOC"
tags:
- env::docker
- build::toolchain
- host::whss4
## Job for build linux host toolchain
build_linux:
<<: *build_job_template_default
image: $IMGSVR/$LINBUILDIMG:$IMGTAG
parallel:
matrix:
- citooltype: ["newlibc", "glibc"]
script:
# copy the template
- cp -f scripts/toolchain/buildenv.sample build.env
# source scl environment https://listman.redhat.com/archives/sclorg/2020-October/msg00000.html
- source scl_source enable devtoolset-8 rh-python36 || true
- which gcc python3
- BUILDENV=build.env source scripts/toolchain/setup_env.sh
- export TOOLVER=${citoolver}
- export TOOLTYPE=${citooltype}
- export TOOLHOST=linux64
# clean existing toolchain install prefix directory
- export DOCLEANPREFIX=1
- ./scripts/toolchain/save_env.sh build.env
- ./scripts/toolchain/build.sh 2>&1 | tee build.log
- buildsts=${PIPESTATUS[0]}
- exit $buildsts
## Job for build windows host toolchain
build_windows:
<<: *build_job_template_default
image: $IMGSVR/$WINBUILDIMG:$IMGTAG
when: manual
needs:
- job: build_linux
artifacts: false
- job: prepare_source
artifacts: true
parallel:
matrix:
- citooltype: ["newlibc", "glibc"]
script:
# copy the template
- cp -f scripts/toolchain/buildenv.sample build.env
- BUILDENV=build.env source scripts/toolchain/setup_env.sh
- export TOOLVER=${citoolver}
- export TOOLTYPE=${citooltype}
- export TOOLHOST=win32
# clean existing toolchain install prefix directory
- export DOCLEANPREFIX=1
- ./scripts/toolchain/save_env.sh build.env
- ./scripts/toolchain/build.sh 2>&1 | tee build.log
- buildsts=${PIPESTATUS[0]}
- exit $buildsts
# clean up build directories and build installed toolchains
cleanbuild:
# don't need full toolchain source code
# still need to run in docker to clean builds, need root permission in docker
image: $IMGSVR/ubuntu:20.04
needs:
- job: prepare_source
artifacts: false
parallel:
matrix:
- citooltype: ["newlibc", "glibc"]
citoolhost: ["win32", "linux64"]
stage: build
when: manual
allow_failure: true
script:
- if [ ${CI_COMMIT_TAG} ] ; then export citoolver=${CI_COMMIT_TAG/nuclei-/} ; else export citoolver=${CI_COMMIT_REF_SLUG}${CI_MERGE_REQUEST_PROJECT_ID} ; fi
- export TOOLVER=${citoolver}
- export TOOLTYPE=${citooltype}
- export TOOLHOST=${citoolhost}
- CLEANINSTALL=1 ./scripts/toolchain/cleanup.sh
tags:
- env::docker
- host::whss4
## Job for deploy document to internal server
release:
stage: deploy
# https://docs.gitlab.com/ee/ci/yaml/index.html#needsartifacts
# don't need full toolchain source code
needs:
- job: prepare_source
artifacts: false
- job: build_linux
artifacts: false
when: on_success
interruptible: true
only:
refs:
- branches
- tags
parallel:
matrix:
- citooltype: ["newlibc", "glibc"]
script:
- if [ ${CI_COMMIT_TAG} ] ; then export citoolver=${CI_COMMIT_TAG/nuclei-/} ; else export citoolver=${CI_COMMIT_REF_SLUG}${CI_MERGE_REQUEST_PROJECT_ID} ; fi
- export TOOLVER=${citoolver}
- export TOOLTYPE=${citooltype}
- export TOOLHOST=linux64
- ./scripts/toolchain/release.sh
tags:
- env::shell
- host::whss4