variables:
  GIT_SUBMODULE_STRATEGY: recursive


stages:
  - docker-build
  - lint_build_test
  - deploy

lint:
  stage: lint_build_test
  image: 
    name: docker/compose:1.24.1
    entrypoint:
      - /bin/sh
      - "-c"
  services:
    - docker:dind
  variables:
    DOCKER_HOST: "tcp://docker:2375/"
    DOCKER_DRIVER: overlay2
    GIT_SUBMODULE_STRATEGY: none
  script:
    - docker-compose pull
    - docker-compose run xo-js-lint
    - docker-compose run xo-html-lint
    - docker-compose run sass-lint
build:
  stage: lint_build_test
  image:
    name: klakegg/hugo:0.55.6-ext-alpine
    entrypoint:
      - /bin/sh
      - "-c"
  script:
    - hugo --minify
  artifacts:
    paths:
      - public
    expire_in: 3 months
  only:
    - production

test:
  stage: lint_build_test
  image:
    name: klakegg/hugo:0.55.6-ext-alpine
    entrypoint:
      - /bin/sh
      - "-c"
  script:
    - hugo_output=$(hugo --path-warnings --i18n-warnings)
    - echo "$hugo_output"
    - if echo "$hugo_output" | grep -q 'i18n|MISSING_TRANSLATION'; then false; else true; fi
    - if echo "$hugo_output" | grep -q 'WARN.*Duplicate target paths'; then false; else true; fi
  artifacts:
    paths:
      - public
    expire_in: 1 month
firebase-deploy:
  stage: deploy
  image: andreysenov/firebase-tools
  dependencies: 
    - build
  script:
    - firebase deploy --only hosting
  only:
    - production
docker-build:
  stage: docker-build
  image:
    name: docker/compose:1.24.1
    entrypoint:
      - /bin/sh
      - "-c"
  services:
    - docker:dind
  variables:
    DOCKER_HOST: "tcp://docker:2375/"
    DOCKER_DRIVER: overlay2
    GIT_SUBMODULE_STRATEGY: none
  only:
    changes:
      - docker-compose.yml
      - linting/**/*
  before_script:
    - echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
  script:
    - docker-compose build
    - docker-compose push