.gitlab-ci.yml 2.29 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
42
43
  stage: deploy
  variables:
    VERSION_FILE: "lib/jekyll-theme-lcsb-default.rb"
44
    TARGET_BRANCH: latest
45
46
47
  only:
    changes:
      - "lib/jekyll-theme-lcsb-default.rb"  
48
  script:
49
    # 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
50
    - '[[ "${CI_COMMIT_BRANCH:-1}" == "$TARGET_BRANCH" ]] && echo "On correct branch ($CI_COMMIT_BRANCH)" || exit 0'
51

52
53
54
    # 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 ' '`
55
56
57
    - '[[ -z $VERSION ]] && exit -1 || echo "OK, version appears to be correct -> $VERSION"'

    # Create the tag
58
    - git tag -a $VERSION -m $VERSION
59
60
61
62
63

    # Publish the tag
    - git push origin $VERSION

# This will push the gem to ruby-gems when the repository has been tagged
64
65
66
release:
  stage: release
  script:
67
68
    - 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
69
  rules:
70
    # Run only when there is a new tag
71
72
    - if: $CI_COMMIT_TAG