/
.gitlab-ci.yml
70 lines (67 loc) · 2.14 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
stages:
- 📄 pages
- 🗑 cleanup
default:
interruptible: true
pages:
stage: 📄 pages
image: docker:20.10.12
cache:
key: gitlab-pages
paths: [public]
services:
- docker:20.10.12-dind
variables:
DOCKER_HOST: tcp://docker:2375 # on gitlab.com shared runners
DOCKER_TLS_CERTDIR: ""
GIT_DEPTH: 0 # all branches are fetched (and known)
before_script:
- mkdir -p public
- ls public
- |
if [ "$CI_COMMIT_REF_SLUG" != "$CI_DEFAULT_BRANCH" ] && [ ! -d public/$CI_DEFAULT_BRANCH ]; then
echo -e "💥\e[91;1m Unable to retrieve $CI_DEFAULT_BRANCH generated files from cache ; please retry or regenerate $CI_DEFAULT_BRANCH files first\e[0m"
exit 1
fi
- rm -rf public/$CI_COMMIT_REF_SLUG || true
script:
- apk add rsync zip tree git
- ./generate.sh
# generate zips only for training needing it
- ./generate.sh devops/kubernetes-user zip || true
- ./generate.sh devops/kubernetes-user-2j zip || true
# clean pages for old branches
- ls build-docs/*/*
- mv --verbose build-docs public/$CI_COMMIT_REF_SLUG
- cd public
- git branch -r
- |
for folder in *; do
exists=$(git rev-parse -q --verify "origin/$folder") || true
if [ -z "$exists" ]; then
rm -rf $folder
echo "removed folder $folder, the branch does not exist anymore"
fi
done
- ls -lart
# generate a root HTML listing all folder branches
- tree -d -H '.' -L 1 --noreport --charset utf-8 -T "Versions" -o index.html
environment:
name: $CI_COMMIT_REF_SLUG
action: start
url: $CI_PAGES_URL/$CI_COMMIT_REF_SLUG
publish: public # (default)
artifacts:
paths: [public]
expire_in: 1h
🗑🦊-pipelines-delete:
stage: 🗑 cleanup
image: python:3.8-alpine
before_script:
- pip install --upgrade python-gitlab click
script:
# deleting older pipelines (by default after 2 pages = 40 pipelines are kept)
- python gitlab-purge-pipelines.py $CI_SERVER_URL $CI_PROJECT_ID $API_TOKEN
allow_failure: true
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH || $CI_COMMIT_BRANCH == "$CI_DEFAULT_BRANCH-test"