.gitlab-ci.yml 4 KB
Newer Older
1 2

stages:
3
  - preflight
Rob Connolly's avatar
Rob Connolly committed
4
  - homeassistant
5
  - deploy
6 7
  - docker-deploy
  - postflight
8

9 10 11
variables:
  GIT_SUBMODULE_STRATEGY: recursive

12 13 14 15 16 17
# Generic preflight template
.preflight: &preflight
  stage: preflight
  tags:
    - hass

18 19 20
# Generic Home Assistant template
.ha: &ha
  stage: homeassistant
Rob Connolly's avatar
Rob Connolly committed
21 22 23 24 25
  variables:
    PYTHONPATH: "/usr/src/app:$PYTHONPATH"
  before_script:
    - python -m homeassistant --version
    - mv fake_secrets.yaml secrets.yaml
26
    - rm packages/rubbish.yaml
Rob Connolly's avatar
Rob Connolly committed
27 28 29 30 31 32 33 34
  script:
    - |
      python -m homeassistant \
        --config $CI_PROJECT_DIR \
        --script check_config \
        --info all
  tags:
    - hass
35

Rob Connolly's avatar
Rob Connolly committed
36
#before_script:
Rob Connolly's avatar
Rob Connolly committed
37 38
#  - apt-get update
#  - apt-get install -y mosquitto-clients
39

40 41 42 43 44 45 46
# Preflight jobs
shellcheck:
  <<: *preflight
  image:
    name: koalaman/shellcheck-alpine:stable
    entrypoint: [""]
  before_script:
Rob Connolly's avatar
Rob Connolly committed
47
    - ln -s $CI_PROJECT_DIR /config
48
    - mv shell_commands/fake_secrets.sh shell_commands/secrets.sh
49 50 51 52
    - shellcheck --version
    - apk --no-cache add grep
  script:
    - |
Rob Connolly's avatar
Rob Connolly committed
53
      for file in $(grep -IRl "#\!\(/usr/bin/env \|/bin/\)" --exclude-dir ".git" .); do
54
        if ! shellcheck -x $file; then
55 56 57 58 59 60 61 62 63 64 65 66 67 68
          export FAILED=1
        else
          echo "$file OK"
        fi
      done
      if [ "${FAILED}" = "1" ]; then
        exit 1
      fi

yamllint:
  <<: *preflight
  image: sdesbure/yamllint
  before_script:
    - yamllint --version
69
    - mv fake_secrets.yaml secrets.yaml
70
    - rm known_devices.yaml appdaemon.yaml apps/apps.yaml
71 72
  script:
    - yamllint .
73
  allow_failure: true
74 75 76 77 78 79 80 81

jsonlint:
  <<: *preflight
  image: sahsu/docker-jsonlint
  before_script:
    - jsonlint --version || true
  script:
    - |
82
      for file in $(find . -type f -name "*.json" -path "mysensors.json" -prune); do
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
        if ! jsonlint -q $file; then
          export FAILED=1
        else
          echo "$file OK"
        fi
      done
      if [ "${FAILED}" = "1" ]; then
        exit 1
      fi

markdownlint:
  <<: *preflight
  image:
    name: ruby:alpine
    entrypoint: [""]
  before_script:
Rob Connolly's avatar
Rob Connolly committed
99
    - apk --no-cache add git
100 101 102
    - gem install mdl
    - mdl --version
  script:
103
    - mdl --style all --warnings --git-recurse .
104

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
# Home Assistant test jobs
ha-latest:
  <<: *ha
  image:
    name: homeassistant/home-assistant:latest
    entrypoint: [""]

ha-rc:
  <<: *ha
  image:
    name: homeassistant/home-assistant:rc
    entrypoint: [""]
  allow_failure: true

ha-dev:
  <<: *ha
  image:
    name: homeassistant/home-assistant:dev
    entrypoint: [""]
  allow_failure: true
Rob Connolly's avatar
Rob Connolly committed
125 126 127 128 129 130 131 132 133

deploy:
  stage: deploy
  image:
    name: alpine:latest
    entrypoint: [""]
  environment:
    name: home-assistant
  before_script:
134
    - apk --no-cache add openssh-client
Rob Connolly's avatar
Rob Connolly committed
135
    - echo "$DEPLOYMENT_SSH_KEY" > id_rsa
136
    - chmod 600 id_rsa
Rob Connolly's avatar
Rob Connolly committed
137
  script:
138
    - ssh -i id_rsa -o "StrictHostKeyChecking=no" $DEPLOYMENT_SSH_LOGIN "cd /mnt/docker-data/home-assistant && git fetch && git checkout $CI_COMMIT_SHA && git submodule sync --recursive && git submodule update --init --recursive"
Rob Connolly's avatar
Rob Connolly committed
139 140
  after_script:
    - rm id_rsa
141 142 143
  only:
    refs:
      - master
Rob Connolly's avatar
Rob Connolly committed
144 145
  tags:
    - hass
146

147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
docker-deploy:
  stage: docker-deploy
  image:
    name: alpine:latest
    entrypoint: [""]
  environment:
    name: home-assistant
  before_script:
    - apk --no-cache add openssh-client
    - echo "$DEPLOYMENT_SSH_KEY" > id_rsa
    - chmod 600 id_rsa
  script:
    - ssh -i id_rsa -o "StrictHostKeyChecking=no" $DEPLOYMENT_SSH_LOGIN "cd /mnt/docker-data/home-assistant && ./update.sh"
  after_script:
    - rm id_rsa
  only:
    refs:
      - master
    changes:
      - docker-compose.yml
167
      - update.sh
168 169 170
  tags:
    - hass

171 172 173 174 175 176 177 178 179 180 181 182 183 184
restart-hass:
  stage: postflight
  image:
    name: alpine:latest
    entrypoint: [""]
  environment:
    name: home-assistant
  before_script:
    - apk --no-cache add curl
  script:
    - "curl -X POST -H \"Authorization: Bearer $DEPLOYMENT_HASS_TOKEN\" -H \"Content-Type: application/json\" $DEPLOYMENT_HASS_URL/api/services/homeassistant/restart"
  only:
    refs:
      - master
185 186 187
  except:
    changes:
      - docker-compose.yml
188
      - update.sh
189 190
  tags:
    - hass