-
Notifications
You must be signed in to change notification settings - Fork 12
/
.gitlab-ci.yml
executable file
·235 lines (221 loc) · 7.03 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
# docker image from https://github.com/DavidAnson/markdownlint-cli2
# vscode markdownlint https://marketplace.visualstudio.com/items?itemName=DavidAnson.vscode-markdownlint
# markdownlint-cli2: https://github.com/DavidAnson/markdownlint-cli2
# markdownlint rules: https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
# markdown-link-check: https://github.com/tcort/markdown-link-check
#
variables:
GITLAB_REPO: [email protected]:maix_sw/k230_docs.git
GITHUB_REPO: [email protected]:kendryte/k230_docs.git
GITEE_REPO: [email protected]:kendryte/k230_docs.git
default:
interruptible: true
image: ai.b-bug.org:5000/k230_sdk:latest
tags:
- k230_sdk
stages:
- lint
- build
- sync
- deploy
# MR merged
merge_sync:
stage: sync
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"
extends:
- .setup_env
- .sync_github_gitee
# release
dev_to_main:
stage: sync
rules:
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"
extends:
- .setup_env
- .dev_to_main
# tag push
tag_sync:
stage: sync
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
extends:
- .setup_env
- .sync_github_gitee
# auto sync
schedule_sync:
stage: sync
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
extends:
- .setup_env
- .sync_github_gitee
# manual sync
manual_sync:
stage: sync
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
when: always
extends:
- .setup_env
- .sync_github_gitee
# new MR open
markdown-link-check:
rules:
# MR job
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
stage: lint
timeout: 10m
retry: 2
image: ai.b-bug.org:5000/markdown:latest
script:
- uname -a
- whoami
- pwd
- git fetch
- FILELIST=$(git diff origin/dev --name-only -z --diff-filter=AM | grep "\\.md$" || true)
- echo $FILELIST
- time markdown-link-check -p -q -v $(find . -name \*.md)
# new MR open
markdownlint:
rules:
# MR job
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
stage: lint
timeout: 10m
image: ai.b-bug.org:5000/markdown:latest
script:
- uname -a
- whoami
- pwd
#- find . -name \*.md -print0 | xargs -0 markdownlint-cli2
- git fetch --tags
- FILELIST=$(git diff origin/dev --name-only -z --diff-filter=AM | grep "\\.md$" || true)
- echo $FILELIST
- markdownlint-cli2 $(find . -name \*.md)
.setup_env:
before_script:
- echo '----------Build ENV Prepare----------'
- echo 'Add SSH KEY for Multiple repo'
- "which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )"
- eval $(ssh-agent -s)
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_PRIVATE_KEY" | ssh-add - > ~/.ssh/id_ed25519 || exit 1
- '[[ -f /.dockerenv ]] && echo -e "Host *\n StrictHostKeyChecking no\n" > ~/.ssh/config'
- echo $SHELL
- echo "increate ssh timeout for github"
- echo " ServerAliveInterval 30" >> ~/.ssh/config
- echo " ServerAliveCountMax 60" >> ~/.ssh/config
- echo " TCPKeepAlive yes" >> ~/.ssh/config
- cat ~/.ssh/config
- whoami
- uptime
- pwd
- uname -a
- cat /etc/issue
- echo $CI_PROJECT_DIR
- echo $CI_PROJECT_NAME
- echo '----------set git config ----------'
- echo "${GITLAB_USER_EMAIL}"
- echo "${GITLAB_USER_NAME}"
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global user.name "${GITLAB_USER_NAME}"
- git config --global --add safe.directory $CI_PROJECT_DIR
.sync_github_gitee:
timeout: 30m
script:
- cd $CI_PROJECT_DIR
- ls -alht
- rm -rf ./k230_docs/
- git clone ${GITLAB_REPO} k230_docs || exit 1
- cd k230_docs || exit 1
- pwd
- git checkout main
- git branch -a
- git status
- echo '---pull latest main branch---'
- git pull origin main
- echo '---fetch all tags---'
- git fetch --tags
- git remote add github ${GITHUB_REPO}
- git remote add gitee ${GITEE_REPO}
- git remote -v
- git branch -a
- git status
- echo "---push to gitee---"
- git push --atomic --tags -u -f gitee main || git push --atomic --tags -u -f gitee main
- echo "---push to github---"
- git push --atomic --tags -u -f github main || git push --atomic --tags -u -f github main || git push --atomic --tags -u -f github main
.dev_to_main:
timeout: 30m
script:
- cd $CI_PROJECT_DIR
- ls -alht
- echo "----------Step 1, Check Merge Request Title, k230 sdk docs release v*.* MUST bt exist----------"
- echo "$CI_MERGE_REQUEST_TITLE"
- >
if [[ "$CI_MERGE_REQUEST_TITLE" =~ ^"k230 sdk docs release v[0-9]+\.[0-9]+".*$ ]];
then
echo "Merge Request title check PASS, continue get release version from merge request title";
else
echo "Merge Request title check FAILED, please EDIT title name with release tag";
echo "Title MUST be end with tag like: k230 sdk docs release v1.4";
exit 1;
fi
- RELEASE_TAG=$(echo $CI_MERGE_REQUEST_TITLE |grep -Eo "v[0-9]+\.[0-9]+.*?$")
- >
if [[ "$RELEASE_TAG" =~ ^v[0-9]+\.[0-9]+.*$ ]];
then
echo "Release TAG/version will be " $RELEASE_TAG;
else
echo "Release TAG/version check FAILED, please EDIT title name with release tag";
echo "Title MUST be end with tag like: k230 sdk docs release v1.4";
exit 1;
fi
- echo "----------sync dev branch to main branch for k230 sdk docs release----------"
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/release/k230_docs_release.sh -O ./k230_docs_release.sh
- chmod +x ./k230_docs_release.sh
- ./k230_docs_release.sh $RELEASE_TAG "k230 sdk docs release $RELEASE_TAG" || exit 1
- echo "----------sync dev to main branch pass in k230 sdk docs repos----------"
build web docs:
stage: build
rules:
- if: $CI_PIPELINE_SOURCE == "push" && ($CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "main")
image: ai.b-bug.org:5000/huangziyi/web-docs-builder:3d9c3f0b2be1fe67b3b2f4e5d47504f6c2662b76
environment:
name: dev
url: https://ai.b-bug.org/k230/docs/dev/
script:
- git fetch --tags
- git branch main origin/main
- git checkout main
- python3 preprocess.py
- python3 preprocessEn.py
- git config --global user.email "[email protected]"
- git config --global user.name "GitLab CI"
- git commit "*.md" -m "remove cover"
- git checkout dev
- git tag --list
- git reset --hard origin/dev
- python3 preprocess.py
- python3 preprocessEn.py
- git commit "*.md" -m "remove cover"
- make mhtml
- rm -rf /data1/k230/docs/*
- cp -r _build/* /data1/k230/docs
deploy production:
stage: deploy
image: ai.b-bug.org:5000/huangziyi/deploy:v1
retry: 2
dependencies:
- build web docs
needs:
- build web docs
rules:
- if: $CI_PIPELINE_SOURCE == "push" && ($CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "main")
environment:
name: production
url: https://developer.canaan-creative.com/k230/dev/index.html
script:
- scp -P $AWS_PORT -C -r /data1/k230/docs/* $AWS/data/webapp/k230