-
Notifications
You must be signed in to change notification settings - Fork 86
/
.gitlab-ci.yml
88 lines (78 loc) · 2.7 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
include:
- template: Jobs/SAST.latest.gitlab-ci.yml
- template: Jobs/Secret-Detection.latest.gitlab-ci.yml
##
## TESTS
##
sast:
needs: []
secret_detection:
needs: []
##
## GITLAB PAGES SETUP
##
pages:
needs: []
image: python:3.10-buster
stage: deploy
environment:
name: production
url: https://${CI_PROJECT_ROOT_NAMESPACE}.gitlab.io/docs-team/docs/
action: start
variables:
GIT_DEPTH: 0
REPO_NAME: ${CI_PROJECT_PATH}
REPO_URL: ${CI_PROJECT_URL}
EDIT_URL: https://gitlab.com/-/ide/project/${CI_PROJECT_PATH}/tree/${CI_COMMIT_REF_NAME}/-/docs/
cache:
key:
files:
- requirements.txt
paths:
- .cache
before_script:
- if [ -d "public" ]; then echo "Directory ./public exists while it should not as it is used for docs artifacts" && exit 1; fi
- pip install -q -r requirements.txt 1> /dev/null
- |
# install for sponge
apt-get update 1> /dev/null
apt-get install moreutils -qqy curl 1> /dev/null
# like jq, but for yml - https://github.com/mikefarah/yq
wget --quiet https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq
- |
# modify link in navbar according to current git branch (ref)
cat mkdocs.yml | /usr/bin/yq '.repo_url = strenv(REPO_URL)' | sponge mkdocs.yml
cat mkdocs.yml | /usr/bin/yq '.edit_uri = strenv(EDIT_URL)' | sponge mkdocs.yml
cat mkdocs.yml | /usr/bin/yq '.repo_name = strenv(REPO_NAME)' | sponge mkdocs.yml
cat mkdocs.yml | /usr/bin/yq '.site_url = strenv(CI_ENVIRONMENT_URL)' | sponge mkdocs.yml
script:
- |
set -o pipefail
mkdocs build --verbose --strict 2>&1 | tee -a /tmp/mkdocs.build.log || { cat /tmp/mkdocs.build.log | grep "WARNING"; exit 1; }
test -f public/index.html && echo "View the generated docs at $CI_ENVIRONMENT_URL"
artifacts:
expire_in: 3 days
paths:
- public
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
mkdocs-preview:
extends: pages
stage: build
environment:
name: review/$CI_COMMIT_REF_SLUG
url: https://${CI_PROJECT_ROOT_NAMESPACE}.gitlab.io/-/docs-team/docs/-/jobs/$CI_JOB_ID/artifacts/public/index.html
before_script:
- !reference [pages, before_script]
- cat mkdocs.yml | /usr/bin/yq '.use_directory_urls = false' | sponge mkdocs.yml
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
when: never
- if: $CI_MERGE_REQUEST_IID == null
variables:
REPO_URL: ${CI_PROJECT_URL}/-/tree/${CI_COMMIT_REF_NAME}
REPO_NAME: ${CI_PROJECT_PATH}:${CI_COMMIT_REF_NAME}
- if: $CI_MERGE_REQUEST_IID != null
variables:
REPO_NAME: ${CI_PROJECT_PATH}!${CI_MERGE_REQUEST_IID}
REPO_URL: ${CI_PROJECT_URL}/-/merge_requests/${CI_MERGE_REQUEST_IID}