-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path.gitlab-ci.yml
74 lines (71 loc) · 2.59 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
stages:
- 📄 pages
- 🗑 cleanup
default:
interruptible: true
pages:
stage: 📄 pages
image: docker:27.0
cache:
key: gitlab-pages
paths: [public]
services: [docker:27.0-dind]
resource_group: avoid-cache-racing-conditions
variables:
DOCKER_HOST: tcp://docker:2375 # on gitlab.com instance 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; triggering a $CI_DEFAULT_BRANCH pipeline first and retrying...\e[0m"
apk add curl
curl -fsSL --request POST --header "PRIVATE-TOKEN: $API_TOKEN" "https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/pipeline?ref=$CI_DEFAULT_BRANCH"
sleep 30 # avoid getting resource lock before triggered $CI_DEFAULT_BRANCH pipeline
exit 1
fi
- rm -rf public/$CI_COMMIT_REF_SLUG || true
script:
- apk add rsync zip tree git
- ./generate.sh
# 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 multi-branches index.html
- tree -d -H '.' -L 1 --noreport --charset utf-8 -T "Versions" -o index.html
# add a favicon and css to the multi-branches index.html
- sed -i -e 's|<head>|<head><link rel="icon" type="image/png" href="main/framework/themes/favicon.png"><link rel="stylesheet" href="main/framework/themes/css/html-zenika.css">|g' index.html
- echo -e "\e[93;1mPages will be available at $CI_PAGES_URL\e[0m"
environment:
name: $CI_COMMIT_REF_SLUG
action: start
url: $CI_PAGES_URL/$CI_COMMIT_REF_SLUG
publish: public # (default)
retry: 1
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 == "main-test"