.gitlab-ci.yml 7.06 KB
Newer Older
Andreas Böttger's avatar
Andreas Böttger committed
1 2 3 4 5 6 7
image: docker.rz.tu-harburg.de:5000/rzt/images/gitbook:node

# https://docs.gitlab.com/ee/ci/yaml/README.html#exclude-jobs-with-rules-from-certain-pipelines
workflow:
  rules:
    - if: $CI_COMMIT_TAG
    - if: $CI_COMMIT_BRANCH
Andreas Böttger's avatar
Andreas Böttger committed
8

Andreas Böttger's avatar
Andreas Böttger committed
9
stages:
Andreas Böttger's avatar
Andreas Böttger committed
10 11 12
    - setup
    - test
    - build
Andreas Böttger's avatar
Andreas Böttger committed
13 14
    - review
    - deploy
Andreas Böttger's avatar
Andreas Böttger committed
15
    - clean
Andreas Böttger's avatar
Andreas Böttger committed
16
    - linkchecker
Andreas Böttger's avatar
Andreas Böttger committed
17 18 19 20 21 22 23 24 25 26

before_script:
    # https://docs.gitlab.com/ee/ci/ssh_keys/README.html
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh

setup:
    stage: setup
    cache:
        key: "$CI_COMMIT_REF_SLUG"
Andreas Böttger's avatar
Andreas Böttger committed
27
        paths:
Andreas Böttger's avatar
Andreas Böttger committed
28
            - node_modules
Andreas Böttger's avatar
Andreas Böttger committed
29
    script:
Andreas Böttger's avatar
Andreas Böttger committed
30
        - gitbook install
Andreas Böttger's avatar
Andreas Böttger committed
31

Andreas Böttger's avatar
Andreas Böttger committed
32 33 34 35

test:
  stage: test
  script:
Andreas Böttger's avatar
Andreas Böttger committed
36 37 38
    #- if [ -f book.json ]; then jq -r --arg base_path "/${CI_PROJECT_PATH}/~${CI_COMMIT_REF_NAME}/" '.base_path |= $base_path' book.json | sponge book.json; fi
    #- if [ -f book.json ]; then jq -r --arg pluginsConfig__downloadpdf_base "/${CI_PROJECT_PATH}/~${CI_COMMIT_REF_NAME}/book_pdf/book.pdf?/" '.pluginsConfig.downloadpdf.base |= $pluginsConfig__downloadpdf_base' book.json | sponge book.json; fi
    #- if [ -f book.json ]; then cat book.json; fi
Andreas Böttger's avatar
Andreas Böttger committed
39

Andreas Böttger's avatar
Andreas Böttger committed
40 41 42 43
    #- if [ -f book.json ]; then jq -r --arg base_path "/${CI_PROJECT_PATH}/" '.base_path |= $base_path' book.json | sponge book.json; fi
    #- if [ -f book.json ]; then jq -r --arg pluginsConfig__downloadpdf_base "/${CI_PROJECT_PATH}/book_pdf/book.pdf?/" '.pluginsConfig.downloadpdf.base |= $pluginsConfig__downloadpdf_base' book.json | sponge book.json; fi
    #- if [ -f book.json ]; then cat book.json; fi
    
Andreas Böttger's avatar
Andreas Böttger committed
44 45 46 47 48 49
    - exit 0
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - node_modules
    policy: pull
Andreas Böttger's avatar
Andreas Böttger committed
50 51
  rules:
    - if: '$CI_COMMIT_REF_NAME != "master"'
Andreas Böttger's avatar
Andreas Böttger committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

pdf:
  stage: build
  script:
    - gitbook install
    - mkdir -p book_pdf
    - gitbook pdf ./ ./book_pdf/book.pdf
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - node_modules
      - book_pdf
  artifacts:
      name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}"
      paths:
          - book_pdf

pages:branches:
  stage: build
  script:
Andreas Böttger's avatar
Andreas Böttger committed
72 73
    - if [ -f book.json ]; then jq -r --arg base_path "${REVIEW_BASE_DIR}~${CI_COMMIT_REF_NAME}/" '.base_path |= $base_path' book.json | sponge book.json; fi
    - if [ -f book.json ]; then jq -r --arg pluginsConfig__downloadpdf_base "${REVIEW_BASE_DIR}~${CI_COMMIT_REF_NAME}/book_pdf/book.pdf?/" '.pluginsConfig.downloadpdf.base |= $pluginsConfig__downloadpdf_base' book.json | sponge book.json; fi
Andreas Böttger's avatar
Andreas Böttger committed
74 75 76 77 78 79 80 81 82 83 84
    - 'if [ -f book.json ]; then cat book.json; fi'
    - gitbook install
    - gitbook build
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - node_modules
      - _book
  artifacts:
    paths:
    - _book
Andreas Böttger's avatar
Andreas Böttger committed
85 86
  rules:
    - if: '$CI_COMMIT_REF_NAME != "master"'
Andreas Böttger's avatar
Andreas Böttger committed
87 88 89 90

pages:master:
  stage: build
  script:
Andreas Böttger's avatar
Andreas Böttger committed
91 92
    - if [ -f book.json ]; then jq -r --arg base_path "${BASE_DIR}" '.base_path |= $base_path' book.json | sponge book.json; fi
    - if [ -f book.json ]; then jq -r --arg pluginsConfig__downloadpdf_base "${BASE_DIR}book_pdf/book.pdf?/" '.pluginsConfig.downloadpdf.base |= $pluginsConfig__downloadpdf_base' book.json | sponge book.json; fi
Andreas Böttger's avatar
Andreas Böttger committed
93 94 95 96 97 98 99 100 101 102 103
    - 'if [ -f book.json ]; then cat book.json; fi'
    - gitbook install
    - gitbook build
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - node_modules
      - _book
  artifacts:
    paths:
    - _book
Andreas Böttger's avatar
Andreas Böttger committed
104 105
  rules:
    - if: '$CI_COMMIT_REF_NAME == "master"'
Andreas Böttger's avatar
Andreas Böttger committed
106 107 108 109 110 111 112 113 114 115

review:start:
  stage: review
  script:
    - echo "$REVIEW_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - eval $(ssh-agent -s)
    - echo "$REVIEW_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - ssh -p "${REVIEW_SSH_PORT}" "${REVIEW_SSH_USER}"@"${REVIEW_HOST_NAME}" "mkdir -p /usr/share/nginx/html/~${CI_COMMIT_REF_NAME}"
    - scp -P "${REVIEW_SSH_PORT}" -r _book/* "${REVIEW_SSH_USER}"@"${REVIEW_HOST_NAME}":"/usr/share/nginx/html/~${CI_COMMIT_REF_NAME}"
Andreas Böttger's avatar
Andreas Böttger committed
116 117
    - if [ -d book_pdf ]; then ssh -p "${REVIEW_SSH_PORT}" "${REVIEW_SSH_USER}"@"${REVIEW_HOST_NAME}" "mkdir -p /usr/share/nginx/html/~${CI_COMMIT_REF_NAME}/book_pdf"; fi
    - if [ -d book_pdf ]; then scp -P "${REVIEW_SSH_PORT}" -r book_pdf/* "${REVIEW_SSH_USER}"@"${REVIEW_HOST_NAME}":"/usr/share/nginx/html/~${CI_COMMIT_REF_NAME}/book_pdf"; fi
Andreas Böttger's avatar
Andreas Böttger committed
118 119 120 121 122 123
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - _book
      - book_pdf
    policy: pull
Andreas Böttger's avatar
Andreas Böttger committed
124 125
  rules:
    - if: '$CI_COMMIT_REF_NAME != "master"'
Andreas Böttger's avatar
Andreas Böttger committed
126 127
  environment:
    name: $CI_COMMIT_REF_NAME
Andreas Böttger's avatar
Andreas Böttger committed
128
    url: https://${REVIEW_PROXY_HOST_NAME}${REVIEW_BASE_DIR}~${CI_COMMIT_REF_NAME}/
Andreas Böttger's avatar
Andreas Böttger committed
129 130
    on_stop: review:stop
  
Andreas Böttger's avatar
Andreas Böttger committed
131
review:stop:
Andreas Böttger's avatar
Andreas Böttger committed
132 133 134 135 136 137 138
  stage: review
  script:
  - echo "$REVIEW_SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
  - chmod 644 ~/.ssh/known_hosts
  - eval $(ssh-agent -s)
  - echo "$REVIEW_SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
  - ssh -p "${REVIEW_SSH_PORT}" "${REVIEW_SSH_USER}"@"${REVIEW_HOST_NAME}" "rm -rf /usr/share/nginx/html/~${CI_COMMIT_REF_NAME}"
Andreas Böttger's avatar
Andreas Böttger committed
139 140 141 142
  rules:
    - if: '$CI_COMMIT_REF_NAME != "master"'
      when: manual
  allow_failure: true
Andreas Böttger's avatar
Andreas Böttger committed
143 144 145
  environment:
    name: $CI_COMMIT_REF_NAME
    action: stop
Andreas Böttger's avatar
Andreas Böttger committed
146
    
Andreas Böttger's avatar
Andreas Böttger committed
147
deploy:
Andreas Böttger's avatar
Andreas Böttger committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
  stage: deploy
  rules:
    - if: '$CI_COMMIT_REF_NAME == "master"'
  script:
    - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - ssh -p "${SSH_PORT}" "${SSH_USER}"@"${HOST_NAME}" "mkdir -p /usr/share/nginx/html"
    - scp -P "${SSH_PORT}" -r _book/* "${SSH_USER}"@"${HOST_NAME}":"/usr/share/nginx/html"
    - if [ -d book_pdf ]; then ssh -p "${SSH_PORT}" "${SSH_USER}"@"${HOST_NAME}" "mkdir -p /usr/share/nginx/html/book_pdf"; fi
    - if [ -d book_pdf ]; then scp -P "${SSH_PORT}" -r book_pdf/* "${SSH_USER}"@"${HOST_NAME}":"/usr/share/nginx/html/book_pdf"; fi
  cache:
    key: "$CI_COMMIT_REF_SLUG"
    paths:
      - _book
      - book_pdf
    policy: pull   
  environment:
    name: $CI_COMMIT_REF_NAME
    url: https://$PROXY_HOST_NAME${BASE_DIR}
Andreas Böttger's avatar
Andreas Böttger committed
169 170 171 172 173 174 175 176 177
        
clean:
  stage: clean
  script:
    - echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - eval $(ssh-agent -s)
    - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - ssh -p "${SSH_PORT}" "${SSH_USER}"@"${HOST_NAME}" "rm -rf /usr/share/nginx/html/*"
Andreas Böttger's avatar
Andreas Böttger committed
178 179 180 181 182
  rules:
    - if: '$CI_COMMIT_REF_NAME == "master"'
      when: manual
  allow_failure: true

Andreas Böttger's avatar
Andreas Böttger committed
183 184 185
  environment:
    name: $CI_COMMIT_REF_NAME
    action: stop
Andreas Böttger's avatar
Andreas Böttger committed
186 187 188
    
linkchecker:intern:
  stage: linkchecker
Andreas Böttger's avatar
Andreas Böttger committed
189 190 191 192
  rules:
    - if: '$CI_COMMIT_REF_NAME != "master"'
      when: manual
  allow_failure: true
Andreas Böttger's avatar
Andreas Böttger committed
193 194 195 196
  image:
    name: linkchecker/linkchecker
    entrypoint: [""]
  script:
Andreas Böttger's avatar
Andreas Böttger committed
197
    - linkchecker --recursion-level 10 --threads 10 --no-status --no-robots --no-warnings --ignore-url 'https://fonts.gstatic.com/{0,1}$' https://${REVIEW_PROXY_HOST_NAME}${REVIEW_BASE_DIR}~${CI_COMMIT_REF_NAME}/
Andreas Böttger's avatar
Andreas Böttger committed
198 199 200
    
linkchecker:all:
  stage: linkchecker
Andreas Böttger's avatar
Andreas Böttger committed
201 202 203 204
  rules:
    - if: '$CI_COMMIT_REF_NAME != "master"'
      when: manual
  allow_failure: true
Andreas Böttger's avatar
Andreas Böttger committed
205 206 207 208
  image:
    name: linkchecker/linkchecker
    entrypoint: [""]
  script:
Andreas Böttger's avatar
Andreas Böttger committed
209
    - linkchecker --recursion-level 10 --threads 10 --no-status --no-robots --no-warnings --check-extern --ignore-url 'https://fonts.gstatic.com/{0,1}$' https://${REVIEW_PROXY_HOST_NAME}${REVIEW_BASE_DIR}~${CI_COMMIT_REF_NAME}/
Andreas Böttger's avatar
Andreas Böttger committed
210