-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
231 lines (218 loc) · 7.46 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
# 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: git@g.a-bug.org:maix_sw/k230_canmv_docs.git
GITHUB_REPO: git@github.com:kendryte/k230_canmv_docs.git
GITEE_REPO: git@gitee.com:kendryte/k230_canmv_docs.git
default:
image: ai.b-bug.org:5000/k230_sdk:latest
tags:
- k230_sdk
# MR merged
merge_sync:
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"
extends:
- .setup_env
- .sync_github_gitee
# tag push
tag_sync:
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
extends:
- .setup_env
- .sync_github_gitee
# auto sync
schedule_sync:
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
extends:
- .setup_env
- .sync_github_gitee
# manual sync
manual_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" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"
stage: test
timeout: 10m
tags:
- k230
image: ai.b-bug.org:5000/markdown:latest
script:
- uname -a
- whoami
- pwd
- find . -name \*.md -print0 | xargs -0 -n1 markdown-link-check -q
# - git fetch
# - FILELIST=$(git diff origin/dev --name-only -z --diff-filter=AM | grep "\\.md$" || true)
# - echo $FILELIST
# - if [ -n "$FILELIST" ]; then echo $FILELIST | xargs markdown-link-check; fi
# new MR open
markdownlint:
rules:
# MR job
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"
stage: test
timeout: 10m
image: ai.b-bug.org:5000/markdown:latest
tags:
- k230
script:
- uname -a
- whoami
- pwd
#- markdownlint-cli2 *.md **/*.md **/**/*.md **/**/**/*.md **/**/**/**/*.md
- find . -name \*.md -print0 | xargs -0 markdownlint-cli2
# - git fetch
# - FILELIST=$(git diff origin/dev --name-only -z --diff-filter=AM | grep "\\.md$" || true)
# - echo $FILELIST
# - if [ -n "$FILELIST" ]; then echo $FILELIST | xargs markdownlint-cli2; fi
.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:
stage: build
timeout: 45m
image: ai.b-bug.org:5000/k230_sdk:latest
tags:
- k230_sdk
script:
- cd $CI_PROJECT_DIR
- ls -alht
- rm -rf ./k230_canmv_docs/
- git clone ${GITLAB_REPO} k230_canmv_docs || exit 1
- cd k230_canmv_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
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
tags:
- k230
environment:
name: dev
url: https://ai.b-bug.org/k230/k230_canmv_docs/dev/
script:
- git fetch --tags
- git branch main origin/main
- git checkout main
- python3 preprocess.py
- git config --global user.email "auto@canaan-creative.com"
- git config --global user.name "GitLab CI"
- git commit "*.md" -m "remove cover" || true
- git checkout dev
- git reset --hard origin/dev
- python3 preprocess.py
- git config --global user.email "auto@canaan-creative.com"
- git config --global user.name "GitLab CI"
- git commit "*.md" -m "remove cover" || true
- make mhtml
- rm -rf /data1/k230/k230_canmv_docs/*
- cp -r _build/* /data1/k230/k230_canmv_docs
artifacts:
paths:
- _build
deploy production:
stage: deploy
image: ai.b-bug.org:5000/huangziyi/deploy:v1
dependencies:
- build web docs
rules:
- if: $CI_PIPELINE_SOURCE == "push" && ($CI_COMMIT_BRANCH == "dev" || $CI_COMMIT_BRANCH == "main")
tags:
- k230
environment:
name: production
url: https://developer.canaan-creative.com/k230_canmv/dev/index.html
retry: 2
script:
- scp -P $AWS_PORT -C -r _build/* $AWS/data/webapp/k230_canmv/
# sync dev branch to main branch
dev_to_main:
rules:
# MR job to main branch
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"
timeout: 30m
script:
- echo "----------Step 1, Check Merge Request Title, k230 canmv docs release v*.* MUST bt exist----------"
- echo "$CI_MERGE_REQUEST_TITLE"
- >
if [[ "$CI_MERGE_REQUEST_TITLE" =~ "^k230 canmv 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 canmv docs release v0.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 canmv docs release v1.4";
exit 1;
fi
- echo "----------sync dev branch to main branch for canmv dovs repo----------"
- wget -qc https://ai.b-bug.org/k230/test_resources/ci/release/k230_canmv_release.sh -O ./k230_canmv_release
- chmod +x ./k230_canmv_release
- ./k230_canmv_release docs $RELEASE_TAG "k230 canmv docs release $RELEASE_TAG" || exit 1
- echo "----------sync dev to main branch pass for canmv repo----------"