variables:
  DEBIAN_FRONTEND: noninteractive
  LC_ALL: C.UTF-8
  GIT_STRATEGY: fetch

stages:
  - configure
  - build
  - test
  - deploy

.debian_stretch: &debian_stretch
  image: cznic/debian:stretch-knot-v2
  tags:
    - docker
    - linux
    - amd64
  
.ubuntu_xenial: &ubuntu_xenial
  image: cznic/ubuntu:16.04-knot
  tags:
    - docker
    - linux
    - amd64

.debian_stretch_armel: &debian_stretch_armel
  image: cznic/armel-debian-knot
  tags:
    - docker
    - linux
    - arm

.configure: &configure_job
  stage: configure
  script:
    - autoreconf -fi
    - ./configure --disable-fastparser
  artifacts:
    untracked: true
    expire_in: '1 hour'

.build: &build_job
  stage: build
  script:
    - make -k all
  artifacts:
    untracked: true
    expire_in: '1 hour'

.test: &test_job
  stage: test
  script:
    - make -k check

configure:ubuntu:amd64:
  <<: *ubuntu_xenial
  <<: *configure_job
  except:
    - tags
    - docs-*

build:ubuntu:amd64:
  <<: *ubuntu_xenial
  <<: *build_job
  dependencies:
    - configure:ubuntu:amd64
  except:
    - tags
    - docs-*

test:ubuntu:amd64:
  <<: *ubuntu_xenial
  <<: *test_job
  dependencies:
    - build:ubuntu:amd64
  except:
    - tags
    - docs-*

configure:debian:stretch:amd64:
  <<: *debian_stretch
  <<: *configure_job

build:debian:stretch:amd64:
  <<: *debian_stretch
  <<: *build_job
  dependencies:
    - configure:debian:stretch:amd64

test:debian:stretch:amd64:
  <<: *debian_stretch
  <<: *test_job
  dependencies:
    - build:debian:stretch:amd64

configure:debian:stretch:armel:
  <<: *debian_stretch_armel
  <<: *configure_job
  only:
    - triggers

build:debian:stretch:armel:
  <<: *debian_stretch_armel
  <<: *build_job
  dependencies:
    - configure:debian:stretch:armel
  only:
    - triggers

test:debian:stretch:armel:
  <<: *debian_stretch_armel
  <<: *test_job
  dependencies:
    - build:debian:stretch:armel
  only:
    - triggers

build:documentation:
  <<: *debian_stretch
  stage: build
  dependencies:
    - configure:debian:stretch:amd64
  only:
    - tags
    - triggers
    - docs-*
  script:
    - make -C doc html singlehtml pdf
  artifacts:
    paths:
      - doc/_build/html/
      - doc/_build/singlehtml/
      - doc/_build/latex/knot.pdf
    expire_in: '1 hour'

deploy:documentation:
  <<: *debian_stretch
  stage: deploy
  before_script:
    - apt-get update
    - apt-get -y install curl
  only:
    - tags
    - triggers
    - docs-*
  script:
    - "curl --http1.1 --request POST --form token=$WEBSITE_TOKEN --form ref=master --form \"variables[RELEASE_CI_BUILD_REF_NAME]=$CI_BUILD_REF_NAME\" --form \"variables[RELEASE_CI_BUILD_ID]=$CI_BUILD_ID\" https://gitlab.labs.nic.cz/api/v3/projects/5/trigger/builds"
  artifacts:
    name: "knot-dns-$CI_BUILD_REF_NAME-doc"
    paths:
      - doc/_build/html/
      - doc/_build/singlehtml/
      - doc/_build/latex/knot.pdf
