.gitlab-ci.yml 4.92 KB
Newer Older
1
# In case something goes horribly wrong, you can fall back to `image: ruby:2.5`
Laurent Heirendt's avatar
Laurent Heirendt committed
2
image: git-r3lab.uni.lu:4567/r3/docker/jekyll-lcsb:1.6
3

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

Laurent Heirendt's avatar
Laurent Heirendt committed
11 12 13 14 15 16 17
# prepare
# ------------------------------------------------------------------------------------

prepare:index:
  image: python
  stage: prepare
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
18
    - if: $CI_COMMIT_REF_NAME
19
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_MESSAGE !~ /tmpBranch/ && $CI_COMMIT_MESSAGE !~ /Update index/'
Laurent Heirendt's avatar
Laurent Heirendt committed
20 21
  before_script:
    - pip install natsort
Laurent Heirendt's avatar
Laurent Heirendt committed
22 23 24 25 26 27 28 29 30
  script:
    - python .ci/generateIndex.py
    - mkdir .tmp
    - cp index.md .tmp/.
  artifacts:
    expire_in: 1 day
    paths:
      - .tmp

Laurent Heirendt's avatar
Laurent Heirendt committed
31 32 33 34
# save
# ------------------------------------------------------------------------------------

save:commitIndex:
35 36 37
  image:
    name: alpine/git:latest
    entrypoint: [""]
Laurent Heirendt's avatar
Laurent Heirendt committed
38
  stage: save
39 40 41
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_COMMIT_MESSAGE !~ /tmpBranch/ && $CI_COMMIT_MESSAGE !~ /Update index/'
  before_script:
Laurent Heirendt's avatar
Laurent Heirendt committed
42
    - apk add git-lfs
43 44 45 46 47 48
    - 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
49
    # copy the index and remove the temporary directory
50
    - cp .tmp/index.md .
Laurent Heirendt's avatar
Laurent Heirendt committed
51 52 53
    - rm -rf .tmp

    # commit
54
    - git branch -D tmpBranch || true
55 56 57 58
    - git checkout -b tmpBranch || true
    - git add --all || true
    - git commit -m "Update index" || true
    - git checkout $CI_COMMIT_REF_NAME || true
59
    - git pull origin $CI_COMMIT_REF_NAME
60
    - git merge tmpBranch --ff || true
61
    - git push origin $CI_COMMIT_REF_NAME || true
62
    - git branch -D tmpBranch || true
63

64 65
# build
# ------------------------------------------------------------------------------------
Jacek Lebioda's avatar
Jacek Lebioda committed
66

67
build:pages:
Jacek Lebioda's avatar
Jacek Lebioda committed
68 69 70 71 72 73 74
  stage: build
  variables:
    JEKYLL_ENV: production
    BUNDLER_VERSION: 2.0.2
  artifacts:
    expire_in: 1 day
    paths:
75
      - build
76
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
77
    - if: $CI_COMMIT_REF_NAME
78
    - if: $CI_MERGE_REQUEST_ID
79
  before_script:
Laurent Heirendt's avatar
Laurent Heirendt committed
80 81
    - apt-get -qq update
    - apt-get install -y -qq git-lfs
82
    - gem install bundler:$BUNDLER_VERSION && bundle install
83 84
  script:
    # Generate the configuration for forks (will use Gitlab Pages on personal namespaces)
85 86
    - 'echo "url: https://$CI_PROJECT_NAMESPACE.$CI_PAGES_DOMAIN" >> .ci/_config_gitlab_pages.yml'
    - 'echo "baseurl: /$CI_PROJECT_NAME" >> .ci/_config_gitlab_pages.yml'
87 88

    # If there is no config for the current branch, use the one for Gitlab Pages
89
    - 'if [ ! -f ".ci/_config_$CI_COMMIT_REF_NAME.yml" ]; then mv .ci/_config_gitlab_pages.yml .ci/_config_$CI_COMMIT_REF_NAME.yml; fi'
90 91

    # Display, which configuration is used
92
    - 'echo "Configuration: " && cat ".ci/_config_$CI_COMMIT_REF_NAME.yml"'
93 94

    # Run Jekyll with custom configuration
95
    - bundle exec jekyll build -d build --config "_config.yml,.ci/_config_$CI_COMMIT_REF_NAME.yml"
96

97 98
# generate
# ------------------------------------------------------------------------------------
Jacek Lebioda's avatar
Jacek Lebioda committed
99

100 101
generate:searchIndex:
  stage: generate
Jacek Lebioda's avatar
Jacek Lebioda committed
102
  image: node:13.8.0-slim
103 104
  variables:
    LUNR_VERSION: 2.3.8
105
    DIRECTORY: build
Jacek Lebioda's avatar
Jacek Lebioda committed
106
  script:
Laurent Heirendt's avatar
Laurent Heirendt committed
107
    - bash .ci/build_indices.sh
108
    - mv build processed_build
Jacek Lebioda's avatar
Jacek Lebioda committed
109 110 111
  artifacts:
    expire_in: 1 day
    paths:
112
      - processed_build
113

114 115 116 117 118
# deploy
# ------------------------------------------------------------------------------------

# Deploy to Gitlab Pages - to be run only by forks
pages:
Jacek Lebioda's avatar
Jacek Lebioda committed
119
  image: alpine:3.11.3
120
  stage: deploy
Jacek Lebioda's avatar
Jacek Lebioda committed
121
  rules:
Laurent Heirendt's avatar
Laurent Heirendt committed
122
    - if: '$CI_MERGE_REQUEST_ID && $CI_PROJECT_NAMESPACE != "R3" && $CI_PROJECT_NAMESPACE != "R3-core"'
123
  script:
124
    - mv processed_build public
125
  artifacts:
126
    expire_in: 1 week
127
    paths:
128
      - public
Jacek Lebioda's avatar
Jacek Lebioda committed
129 130

## Deploys the website to a separate VM
131
deploy:vm:
Jacek Lebioda's avatar
Jacek Lebioda committed
132 133 134 135 136 137 138 139 140 141 142
  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
143 144
    - 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
145
  script:
Laurent Heirendt's avatar
Laurent Heirendt committed
146 147 148
    - 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
149