.gitlab-ci.yml 2.79 KB
Newer Older
Jacek Lebioda's avatar
Jacek Lebioda committed
1
# In case something goes horribly wrong, you can fall back to `image: ruby:latest`
2
image: git-r3lab.uni.lu:4567/r3/docker/jekyll-lcsb:1.4
Christophe Trefois's avatar
Christophe Trefois committed
3

4
5
6
7
8
stages:
  - test
  - deploy
  - release

9
# This will try to build the web site, and store the result in "build" directory
10
build the web site:
Christophe Trefois's avatar
Christophe Trefois committed
11
  stage: test
12
13
  variables:
    JEKYLL_ENV: production
Christophe Trefois's avatar
Christophe Trefois committed
14
  artifacts:
15
    expire_in: 3 days
Christophe Trefois's avatar
Christophe Trefois committed
16
    paths:
17
18
19
20
21
22
23
    - build  
  before_script:
  - bundle install
  script:  
  - 'echo "baseurl: /$CI_PROJECT_NAME" >> _config_ci.yml'
  - 'echo "url: https://$CI_PROJECT_NAMESPACE.$CI_PAGES_DOMAIN" >> _config_ci.yml'
  - bundle exec jekyll build -d build --config "_config.yml,_config_ci.yml"
Christophe Trefois's avatar
Christophe Trefois committed
24

25
# This will actually deploy the web site when pushing to master
Christophe Trefois's avatar
Christophe Trefois committed
26
27
pages:
  stage: deploy
28
29
30
  rules:
    # Run only on branch named "latest"
    - if: $CI_COMMIT_BRANCH == "latest"
Christophe Trefois's avatar
Christophe Trefois committed
31
  script:
32
33
  - mv build public
  - echo "Your website is available at $CI_PAGES_URL"
Christophe Trefois's avatar
Christophe Trefois committed
34
  artifacts:
35
    expire_in: 3 days
Christophe Trefois's avatar
Christophe Trefois committed
36
37
38
    paths:
    - public

39
# This will tag the repository when the version-file changes and the theme successfully builds
40
auto-tag:
41
  stage: deploy
42
  image: alpine:3.1
43
44
45
  only:
    changes:
      - "lib/jekyll-theme-lcsb-default.rb"  
46
47
  before_script:
    - 'which ssh-agent || ( apk add --update openssh )'
Jacek Lebioda's avatar
Jacek Lebioda committed
48
    - apk add --update git
49
50
51
52
53
54
55
56
57
    - eval $(ssh-agent -s)
    - echo "$SSHPRIVKEY" | 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
  variables:
    VERSION_FILE: "lib/jekyll-theme-lcsb-default.rb"
    TARGET_BRANCH: latest  
58
  script:
59
    # Make sure that it is on latest, otherwise exit. THIS IS A WORKAROUND, AS HAVING BOTH ONLY AND RULES IS NOT POSSIBLE
Jacek Lebioda's avatar
Jacek Lebioda committed
60
    - '[[ "${CI_COMMIT_BRANCH:-1}" == "$TARGET_BRANCH" ]] && echo "On correct branch ($CI_COMMIT_BRANCH)" || exit 0'
61

62
63
64
65
    # Set correct git user and email
    - git config user.name $GIT_USER
    - git config user.email $GIT_EMAIL

66
67
68
    # Make sure that the version exists and is correct, and put it in envvar
    - cat $VERSION_FILE | grep "VERSION" | tr -d A-z\"\= | tr -d ' '
    - VERSION=`cat $VERSION_FILE | grep "VERSION" | tr -d A-z\"\= | tr -d ' '`
69
70
71
    - '[[ -z $VERSION ]] && exit -1 || echo "OK, version appears to be correct -> $VERSION"'

    # Create the tag
72
    - git tag -a $VERSION -m $VERSION
73
74
75
76
77

    # Publish the tag
    - git push origin $VERSION

# This will push the gem to ruby-gems when the repository has been tagged
78
79
80
release:
  stage: release
  script:
81
82
    - mkdir -p ~/.gem && echo "$API_KEY_BASE64" | base64 --decode > ~/.gem/credentials && chmod 0600 ~/.gem/credentials
    - gem build jekyll-theme-lcsb-default.gemspec && gem push jekyll-theme-lcsb-default*.gem
83
  rules:
84
    # Run only when there is a new tag
85
86
    - if: $CI_COMMIT_TAG