stages:
  - build
  - autopkgtest

.build: &build
  stage: build
  before_script:
    # allow origtargz to use 'apt-get source'
    - sed -e 's/^deb /deb-src /' /etc/apt/sources.list > /etc/apt/sources.list.d/src.list
    - apt-get -q update
    - apt-get -y --no-install-recommends install devscripts fakeroot liblwp-protocol-https-perl libwww-perl
    - useradd builduser
    - chown -R builduser:builduser .
    - chown builduser:builduser ..
    - su -c 'origtargz' builduser
    - apt-get -y --no-install-recommends build-dep .
  script:
    - su -c 'dpkg-buildpackage --no-sign -sa -rfakeroot' builduser
  after_script:
    - rm -rf .built && mkdir .built
    - dcmd mv ../*.changes .built/
  artifacts:
    paths:
      - .built

.test: &test
  stage: autopkgtest
  before_script:
    - apt-get -q update -q
    - apt-get -y --no-install-recommends install autopkgtest autodep8
  script:
    - autopkgtest .built/*.changes -- null

build:testing:
  <<: *build
  image: debian:testing
build:unstable:
  <<: *build
  image: debian:sid

test:testing:
  <<: *test
  dependencies:
    - build:testing
  image: debian:testing
test:unstable:
  <<: *test
  dependencies:
    - build:unstable
  image: debian:sid
