.gitlab-ci.yml 1.84 KB
Newer Older
1 2
image: chef/chefdk:3.7.24

3 4 5
variables:
  GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no -i .ssh/id_rsa-gitlab-ci"

6
local-tests:
7 8
  stage: test
  script:
9
  - delivery local verify
10 11
  coverage: '/Touch\s+Coverage:\s+(\d+\.\d+)%/'

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
kitchen-tests:
  services:
  - docker:dind
  stage: test
  image: sbernard/arch-kitchen-docker
  tags:
    - docker
  variables:
    DOCKER_HOST: tcp://docker:2375
  before_script:
  # Taken from https://gitlab.com/chef-platform/test-cookbook/raw/master/.gitlab-ci.yml
  - bundle install
  - mkdir -p /mnt/host
  - mount $(df $CI_PROJECT_DIR --output=source | tail -n 1) /mnt/host
  - ln -s /mnt/host/lib/modules /lib/modules
  - >
    if [ ! -e /var/run/docker.sock ]; then
      if [ ! -d /var/lib/docker ]; then
        mkdir -p $(dirname $CI_PROJECT_DIR)/varlibdocker;
        ln -s $(dirname $CI_PROJECT_DIR)/varlibdocker /var/lib/docker
      fi;
      DOCKER_DRIVER=overlay2 dockerd &
    fi
  - if ! docker network ls | grep -q "kitchen"; then
      docker network create --driver bridge -o "com.docker.network.driver.mtu=1400" kitchen;
    fi
  script:
  - bundle exec kitchen test -d always
  only:
  - master
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

release:
  stage: deploy
  before_script:
  - mkdir -pvm 0700 .ssh
  - echo "${SSH_KEY}" > .ssh/id_rsa-gitlab-ci
  - chmod 0400 .ssh/id_rsa-gitlab-ci
  - git config --global user.email $(git --no-pager show -s --format='%ae' HEAD)
  - git config --global user.name $(git --no-pager show -s --format='%an' HEAD)
  - git remote set-url --push origin $(perl -pe 's#.*@(.+?(\:\d+)?)/#[email protected]\1:#' <<< $CI_REPOSITORY_URL)
  script:
  - export VERSION=$(cat metadata.rb | sed -En "s/^version\s+'(.*)'$/\1/p"); git tag -a ${VERSION} -m "Releasing the cookbook in the ${VERSION} version"
  after_script:
  - git push --tags
  - rm -Rfv .ssh
  only:
58
    variables:
59 60 61
    - $CI_COMMIT_MESSAGE =~ /.*\[RELEASE\].*/
  except:
  - /^(?!master)[email protected]/