Skip to content
Snippets Groups Projects
.gitlab-ci.yml 6.32 KiB
Newer Older
Jacek Lebioda's avatar
Jacek Lebioda committed
stages:
Laurent Heirendt's avatar
Laurent Heirendt committed
  - prepare
Laurent Heirendt's avatar
Laurent Heirendt committed
  - save
Jacek Lebioda's avatar
Jacek Lebioda committed
  - build
  - check
  - generate
Jacek Lebioda's avatar
Jacek Lebioda committed
  - deploy
Laurent Heirendt's avatar
Laurent Heirendt committed
  - trigger
variables:
    GIT_STRATEGY: clone
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: ""
    GIT_SUBMODULE_STRATEGY: recursive
Laurent Heirendt's avatar
Laurent Heirendt committed
# prepare
# ------------------------------------------------------------------------------------

prepare:index:
  image: python
  stage: prepare
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
    - if: $CI_COMMIT_REF_NAME
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_MESSAGE !~ /tmpBranch/ && $CI_COMMIT_MESSAGE !~ /Update index/'
Laurent Heirendt's avatar
Laurent Heirendt committed
  before_script:
Laurent Heirendt's avatar
Laurent Heirendt committed
    - pip install -r .ci/generator/requirements.txt
Laurent Heirendt's avatar
Laurent Heirendt committed
  script:
    - python .ci/generateIndex.py
    - mkdir .tmp
    - cp cards.md .tmp/.
    - cp .ci/whitelist.txt .tmp/.
Laurent Heirendt's avatar
Laurent Heirendt committed
  artifacts:
    expire_in: 1 day
    paths:
      - .tmp

Laurent Heirendt's avatar
Laurent Heirendt committed
# save
# ------------------------------------------------------------------------------------

save:commitIndex:
  image:
    name: alpine/git:latest
    entrypoint: [""]
Laurent Heirendt's avatar
Laurent Heirendt committed
  stage: save
    - 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"'
Laurent Heirendt's avatar
Laurent Heirendt committed
    - apk add git-lfs
    - 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
    # copy the index and remove the temporary directory
    - cp .tmp/cards.md .
Laurent Heirendt's avatar
Laurent Heirendt committed
    - rm -rf .tmp

    # commit
    - git branch -D tmpBranch || true
    - git checkout -b tmpBranch || true
    - git add --all || true
    - git commit -m "Update index" || true
    - git checkout $CI_COMMIT_REF_NAME || true
    - git pull origin $CI_COMMIT_REF_NAME
    - git merge tmpBranch --ff || true
    - git push origin $CI_COMMIT_REF_NAME || true
    - git branch -D tmpBranch || true
# build
# ------------------------------------------------------------------------------------
build:pages:
Laurent Heirendt's avatar
Laurent Heirendt committed
  image: $CI_REGISTRY/r3/docker/jekyll-lcsb
Jacek Lebioda's avatar
Jacek Lebioda committed
  stage: build
  variables:
    JEKYLL_ENV: production
    BUNDLER_VERSION: 2.1.4
Jacek Lebioda's avatar
Jacek Lebioda committed
  artifacts:
    expire_in: 1 day
    paths:
Laurent Heirendt's avatar
Laurent Heirendt committed
    - if: $CI_COMMIT_REF_NAME
  before_script:
Laurent Heirendt's avatar
Laurent Heirendt committed
    - apt-get -qq update
    - apt-get install -y -qq git-lfs
    - gem install bundler:$BUNDLER_VERSION && bundle install
    # copy the index
    - cp .tmp/cards.md .
    # Generate the configuration for forks (will use Gitlab Pages on personal namespaces)
    - |
      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
    # Display, which configuration is used
    - |
      echo "Configuration: " && cat ".ci/_config_$CI_COMMIT_REF_NAME.yml"
    # Run Jekyll with custom configuration
Kaan Cimir's avatar
Kaan Cimir committed
    - LOGFILE=/dev/stdout .ci/add-timestamp-to-howtocard.sh external
    - bundle exec jekyll build -d build --config "_config.yml,.ci/_config_$CI_COMMIT_REF_NAME.yml"
# check
# ------------------------------------------------------------------------------------

check:links:
   stage: check
   image: $CI_REGISTRY/r3/apps/tailorbird/linkchecker
   rules:
     - if: $CI_COMMIT_REF_NAME
     - if: $CI_MERGE_REQUEST_ID
Laurent Heirendt's avatar
Laurent Heirendt committed
   allow_failure: true
Laurent Heirendt's avatar
Laurent Heirendt committed
   before_script:
     - cp .tmp/whitelist.txt build/.
     - cp -r build /check
Laurent Heirendt's avatar
Laurent Heirendt committed
     - cd /
   script:
     - python link_check.py
# generate
# ------------------------------------------------------------------------------------
generate:searchIndex:
  stage: generate
Jacek Lebioda's avatar
Jacek Lebioda committed
  image: node:13.8.0-slim
  variables:
    LUNR_VERSION: 2.3.8
    DIRECTORY: build
Jacek Lebioda's avatar
Jacek Lebioda committed
  script:
Laurent Heirendt's avatar
Laurent Heirendt committed
    - bash .ci/build_indices.sh
    - mv build processed_build
Jacek Lebioda's avatar
Jacek Lebioda committed
  artifacts:
    expire_in: 1 day
    paths:
      - processed_build
# deploy
# ------------------------------------------------------------------------------------

# Deploy to Gitlab Pages - to be run only by forks
pages:
Jacek Lebioda's avatar
Jacek Lebioda committed
  image: alpine:3.11.3
Jacek Lebioda's avatar
Jacek Lebioda committed
  rules:
    - 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"'
    - mv processed_build public
    expire_in: 1 week

## Deploys the website to a separate VM
deploy:vm:
  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
    - 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"'
Laurent Heirendt's avatar
Laurent Heirendt committed
    - 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 {} +;"
# Trigger pipelines in internal repo
# ------------------------------------------------------------------------------------

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