-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
executable file
·193 lines (174 loc) · 5.32 KB
/
.gitlab-ci.yml
File metadata and controls
executable file
·193 lines (174 loc) · 5.32 KB
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
# 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:
GIT_DEPTH: "0"
GITHUB_REPO: git@github.com:kendryte/k230_rtos_docs.git
MARKDOWN_IMAGE: ai.b-bug.org:5000/markdown:latest
DOCS_BUILDER_IMAGE: ai.b-bug.org:5000/huangziyi/web-docs-builder:3d9c3f0b2be1fe67b3b2f4e5d47504f6c2662b76
DEPLOY_IMAGE: ai.b-bug.org:5000/huangziyi/deploy:v1
stages:
- test
- build
- deploy
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(main|dev)$/
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH =~ /^(main|dev)$/
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG =~ /^v\d+\.\d+.*$/
- if: $CI_PIPELINE_SOURCE == "schedule"
- if: $CI_PIPELINE_SOURCE == "web"
- when: never
default:
image: ai.b-bug.org:5000/k230_sdk:latest
tags:
- k230_sdk
interruptible: true
.markdown_mr_job:
stage: test
timeout: 10m
image: $MARKDOWN_IMAGE
tags:
- k230
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(main|dev)$/
before_script:
- git fetch origin "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
.docs_build_job:
stage: build
image: $DOCS_BUILDER_IMAGE
tags:
- k230
script:
- git fetch origin "$DOCS_BRANCH" --tags
- git checkout -B "$DOCS_BRANCH" "origin/$DOCS_BRANCH"
- make clean
- make mhtml
- mkdir -p "$DOCS_LOCAL_DIR"
- rm -rf "${DOCS_LOCAL_DIR:?}"/*
- cp -r _build/. "$DOCS_LOCAL_DIR/"
artifacts:
paths:
- _build
expire_in: 1 week
.deploy_job:
stage: deploy
image: $DEPLOY_IMAGE
tags:
- k230
retry: 2
# 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:
extends: .markdown_mr_job
script:
- git diff --name-only -z --diff-filter=AM "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME...HEAD" -- '*.md' | xargs -0 -r -n1 markdown-link-check -q
# new MR open
markdownlint:
extends: .markdown_mr_job
script:
- git diff --name-only -z --diff-filter=AM "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME...HEAD" -- '*.md' | xargs -0 -r markdownlint-cli2
.setup_env:
before_script:
- test -n "$SSH_PRIVATE_KEY"
- test -n "$GITLAB_USER_EMAIL"
- test -n "$GITLAB_USER_NAME"
- command -v ssh-agent >/dev/null || (apt-get update -y && apt-get install -y openssh-client)
- eval "$(ssh-agent -s)"
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- printf '%s\n' "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- ssh-keyscan -H github.com g.a-bug.org >> ~/.ssh/known_hosts 2>/dev/null
- chmod 600 ~/.ssh/known_hosts
- 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"
- git remote remove github || true
- git remote add github "${GITHUB_REPO}"
- git fetch origin main --tags
- git checkout -B main origin/main
- |
for attempt in 1 2 3; do
git push --atomic --tags -u -f github main && exit 0
sleep 5
done
exit 1
build docs for production:
extends: .docs_build_job
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"
variables:
DOCS_BRANCH: main
DOCS_LOCAL_DIR: /data1/k230/k230_rtos_sdk_docs
deploy docs for production:
extends: .deploy_job
needs:
- job: build docs for production
artifacts: true
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "main"
environment:
name: production
url: https://developer.canaan-creative.com/k230_rtos/zh/$CI_COMMIT_BRANCH/index.html
script:
- test -n "$AWS"
- test -n "$AWS_PORT"
- scp -P "$AWS_PORT" -C -r _build/* "$AWS/data/webapp/k230_rtos"
build docs for development:
extends: .docs_build_job
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "dev"
variables:
DOCS_BRANCH: dev
DOCS_LOCAL_DIR: /data1/k230/k230_rtos_sdk_docs
deploy docs for development:
extends: .deploy_job
needs:
- job: build docs for development
artifacts: true
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "dev"
environment:
name: development
url: https://$DEV_SERVER/k230_rtos/zh/$CI_COMMIT_BRANCH/index.html
script:
- mkdir -p /data/webapp/k230_rtos
- cp -r _build/. /data/webapp/k230_rtos/