.gitlab-ci.yml 6.13 KB
Newer Older
Laurent Heirendt's avatar
Laurent Heirendt committed
1
2


Jacek Lebioda's avatar
Jacek Lebioda committed
3
stages:
Laurent Heirendt's avatar
Laurent Heirendt committed
4
  - prepare
Laurent Heirendt's avatar
Laurent Heirendt committed
5
  - save
Jacek Lebioda's avatar
Jacek Lebioda committed
6
  - build
7
  - check
8
  - generate
Jacek Lebioda's avatar
Jacek Lebioda committed
9
  - deploy
Laurent Heirendt's avatar
Laurent Heirendt committed
10
  - trigger
Jacek Lebioda's avatar
Jacek Lebioda committed
11

Laurent Heirendt's avatar
Laurent Heirendt committed
12
13
14
15
16
variables:
    GIT_STRATEGY: clone
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""

Laurent Heirendt's avatar
Laurent Heirendt committed
17
18
19
20
21
22
23
# prepare
# ------------------------------------------------------------------------------------

prepare:index:
  image: python
  stage: prepare
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
24
    - if: $CI_COMMIT_REF_NAME
25
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_MESSAGE !~ /tmpBranch/ && $CI_COMMIT_MESSAGE !~ /Update index/'
Laurent Heirendt's avatar
Laurent Heirendt committed
26
27
  before_script:
    - pip install natsort
Laurent Heirendt's avatar
Laurent Heirendt committed
28
29
30
  script:
    - python .ci/generateIndex.py
    - mkdir .tmp
Laurent Heirendt's avatar
Laurent Heirendt committed
31
    - cp cards.md .tmp/.
32
    - cp .ci/whitelist.txt .tmp/.
Laurent Heirendt's avatar
Laurent Heirendt committed
33
34
35
36
37
  artifacts:
    expire_in: 1 day
    paths:
      - .tmp

Laurent Heirendt's avatar
Laurent Heirendt committed
38
39
40
41
# save
# ------------------------------------------------------------------------------------

save:commitIndex:
42
43
44
  image:
    name: alpine/git:latest
    entrypoint: [""]
Laurent Heirendt's avatar
Laurent Heirendt committed
45
  stage: save
46
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
47
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_MESSAGE !~ /tmpBranch/ && $CI_COMMIT_MESSAGE !~ /Update index/ && $CI_MERGE_REQUEST_SOURCE_PROJECT_PATH == "R3/howto-cards"'
48
  before_script:
Laurent Heirendt's avatar
Laurent Heirendt committed
49
    - apk add git-lfs
50
51
52
53
54
55
    - git fetch --all
    - url_host=`git remote get-url origin | sed -e "s/https:\/\/gitlab-ci-token:.*@//g"`
    - git remote set-url origin "https://$GIT_ACCESS_USER:$GIT_ACCESS_TOKEN@${url_host}"
    - git config user.name $GIT_ACCESS_USER
    - git config user.email $GIT_ACCESS_EMAIL
  script:
Laurent Heirendt's avatar
Laurent Heirendt committed
56
    # copy the index and remove the temporary directory
Laurent Heirendt's avatar
Laurent Heirendt committed
57
    - cp .tmp/cards.md .
Laurent Heirendt's avatar
Laurent Heirendt committed
58
59
60
    - rm -rf .tmp

    # commit
61
    - git branch -D tmpBranch || true
62
63
64
    - git checkout -b tmpBranch || true
    - git add --all || true
    - git commit -m "Update index" || true
Laurent Heirendt's avatar
Laurent Heirendt committed
65
    - git checkout $CI_COMMIT_REF_NAME || true
66
    - git pull origin $CI_COMMIT_REF_NAME
67
    - git merge tmpBranch --ff || true
68
    - git push origin $CI_COMMIT_REF_NAME || true
69
    - git branch -D tmpBranch || true
70

71
72
# build
# ------------------------------------------------------------------------------------
Jacek Lebioda's avatar
Jacek Lebioda committed
73

74
build:pages:
Laurent Heirendt's avatar
Laurent Heirendt committed
75
  image: $CI_REGISTRY/r3/docker/jekyll-lcsb:1.8
Jacek Lebioda's avatar
Jacek Lebioda committed
76
77
78
79
80
81
82
  stage: build
  variables:
    JEKYLL_ENV: production
    BUNDLER_VERSION: 2.0.2
  artifacts:
    expire_in: 1 day
    paths:
83
      - build
84
      - .tmp
85
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
86
    - if: $CI_COMMIT_REF_NAME
87
  before_script:
Laurent Heirendt's avatar
Laurent Heirendt committed
88
89
    - apt-get -qq update
    - apt-get install -y -qq git-lfs
90
    - gem install bundler:$BUNDLER_VERSION && bundle install
91
92
  script:
    # Generate the configuration for forks (will use Gitlab Pages on personal namespaces)
93
94
95
96
97
98
99
100
101
102
103
    - |
      if [ $CI_MERGE_REQUEST_ID ]; then
          export CI_COMMIT_REF_NAME="develop";
      else
          echo "url: https://$CI_PROJECT_NAMESPACE.$CI_PAGES_DOMAIN" >> .ci/_config_gitlab_pages.yml;
          echo "baseurl: /$CI_PROJECT_NAME" >> .ci/_config_gitlab_pages.yml;
          # If there is no config for the current branch, use the one for Gitlab Pages
          if [ ! -f ".ci/_config_$CI_COMMIT_REF_NAME.yml" ]; then
              mv .ci/_config_gitlab_pages.yml .ci/_config_$CI_COMMIT_REF_NAME.yml;
          fi
      fi
104
    # Display, which configuration is used
105
106
    - |
      echo "Configuration: " && cat ".ci/_config_$CI_COMMIT_REF_NAME.yml"
107
    # Run Jekyll with custom configuration
108
    - bundle exec jekyll build -d build --config "_config.yml,.ci/_config_$CI_COMMIT_REF_NAME.yml"
109

110
111
112
113
114
# check
# ------------------------------------------------------------------------------------

check:links:
   stage: check
115
   image: $CI_REGISTRY/r3/apps/tailorbird/linkchecker
116
117
118
   rules:
     - if: $CI_COMMIT_REF_NAME
     - if: $CI_MERGE_REQUEST_ID
Laurent Heirendt's avatar
Laurent Heirendt committed
119
   allow_failure: true
Laurent Heirendt's avatar
Laurent Heirendt committed
120
   before_script:
121
     - cp .tmp/whitelist.txt build/.
122
     - cp -r "$(pwd)"/build /check
123
   script:
124
     - python link_check.py
125

126
127
# generate
# ------------------------------------------------------------------------------------
Jacek Lebioda's avatar
Jacek Lebioda committed
128

129
130
generate:searchIndex:
  stage: generate
Jacek Lebioda's avatar
Jacek Lebioda committed
131
  image: node:13.8.0-slim
132
133
  variables:
    LUNR_VERSION: 2.3.8
134
    DIRECTORY: build
Jacek Lebioda's avatar
Jacek Lebioda committed
135
  script:
Laurent Heirendt's avatar
Laurent Heirendt committed
136
    - bash .ci/build_indices.sh
137
    - mv build processed_build
Jacek Lebioda's avatar
Jacek Lebioda committed
138
139
140
  artifacts:
    expire_in: 1 day
    paths:
141
      - processed_build
142

143
144
145
146
147
# deploy
# ------------------------------------------------------------------------------------

# Deploy to Gitlab Pages - to be run only by forks
pages:
Jacek Lebioda's avatar
Jacek Lebioda committed
148
  image: alpine:3.11.3
149
  stage: deploy
Jacek Lebioda's avatar
Jacek Lebioda committed
150
  rules:
151
152
    - if: '$CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_REF_NAME == "develop" && $CI_PROJECT_PATH == "R3/howto-cards"'
    - if: '$CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_REF_NAME == "master" && $CI_PROJECT_PATH == "R3/howto-cards"'
153
  script:
154
    - mv processed_build public
155
  artifacts:
156
    expire_in: 1 week
157
    paths:
158
      - public
Jacek Lebioda's avatar
Jacek Lebioda committed
159
160

## Deploys the website to a separate VM
161
deploy:vm:
Jacek Lebioda's avatar
Jacek Lebioda committed
162
163
164
165
166
167
168
169
170
171
172
  stage: deploy
  image: alpine:3.1
  before_script:
    - 'which ssh-agent || ( apk add --update openssh )'
    - eval $(ssh-agent -s)
    - echo "$B64SSHPRIVKEY" | base64 -d | tr -d '\r' | ssh-add - > /dev/null
    - mkdir -p ~/.ssh && chmod 700 ~/.ssh
    - 'echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    - echo "$KNOWNHOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
173
174
    - if: '$CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_REF_NAME == "develop" && $CI_PROJECT_PATH == "R3/howto-cards"'
    - if: '$CI_PIPELINE_SOURCE != "merge_request_event" && $CI_COMMIT_REF_NAME == "master" && $CI_PROJECT_PATH == "R3/howto-cards"'
Jacek Lebioda's avatar
Jacek Lebioda committed
175
  script:
Laurent Heirendt's avatar
Laurent Heirendt committed
176
177
178
    - ssh -p $SSHPORT $SSHCONNECT "mkdir -p ~/$CI_COMMIT_REF_NAME/sources/public/$CI_JOB_ID ~/$CI_COMMIT_REF_NAME/public"
    - scp -P $SSHPORT -r processed_build/* $SSHCONNECT:~/$CI_COMMIT_REF_NAME/sources/public/$CI_JOB_ID
    - ssh -p $SSHPORT $SSHCONNECT "cd ~/$CI_COMMIT_REF_NAME/public && ln -fs ../sources/public/$CI_JOB_ID/* . && cd ~/$CI_COMMIT_REF_NAME/sources/public/ && find . -type d -not -newermt '-1 minutes' -exec rm -rf {} +;"
Jacek Lebioda's avatar
Jacek Lebioda committed
179

Laurent Heirendt's avatar
Laurent Heirendt committed
180
181
182
183
# Trigger pipelines in internal repo
# ------------------------------------------------------------------------------------

trigger:
Laurent Heirendt's avatar
Laurent Heirendt committed
184
  stage: trigger
Laurent Heirendt's avatar
Laurent Heirendt committed
185
  image: curlimages/curl
Laurent Heirendt's avatar
Laurent Heirendt committed
186
187
188
189
190
  rules:
    - if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "develop"'
  tags:
    - privileged
  script:
191
    - curl --silent --output /dev/null -X POST -F token=$INTERNAL_TRIGGER_TOKEN -F ref=$CI_COMMIT_BRANCH $INTERNAL_REPO