# vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0:

.templates_sha: &templates_sha 007f3e2fe2235328e77d3cd4ce007ab41cd9ce6c

include:
  - project: 'freedesktop/ci-templates'
    ref: *templates_sha
    file: '/templates/fedora.yml'
  - project: 'freedesktop/ci-templates'
    ref: *templates_sha
    file: '/templates/ci-fairy.yml'


variables:
  FDO_UPSTREAM_REPO: 'libevdev/python-libevdev'
  ARCH_PKGS: 'flake8'


stages:
  - prep
  - test
  - deploy

.fedora:
  variables:
    FDO_DISTRIBUTION_VERSION: 34
    FDO_DISTRIBUTION_TAG: 'qemu-2021-08-24.0'
    FDO_DISTRIBUTION_PACKAGES: 'git python3 python3-pytest libevdev python3-flake8'

.fedora-qemu:
  extends:
    .fedora
  variables:
    FDO_DISTRIBUTION_TAG: '2021-08-24.0'

#
# Verify that commit messages are as expected, etc.
#

check-commit:
  extends:
    - .fdo.ci-fairy
  stage: prep
  script:
    - ci-fairy check-commits --junit-xml=results.xml
  except:
    - master@libevdev/python-libevdev
  variables:
    GIT_DEPTH: 100
  artifacts:
    reports:
      junit: results.xml

#
# Verify that the merge request has the allow-collaboration checkbox ticked
#

check-merge-request:
  extends:
    - .fdo.ci-fairy
  stage: deploy
  script:
    - ci-fairy check-merge-request --require-allow-collaboration --junit-xml=results.xml
  artifacts:
    when: on_failure
    reports:
      junit: results.xml
  allow_failure: true

#
# Prep one regular container for flake and setup.py, one qemu image for pytest
#
container-prep:
  extends:
  - .fedora
  - .fdo.container-build@fedora
  stage: prep
  variables:
    GIT_STRATEGY: none

qemu-prep:
  extends:
  - .fedora-qemu
  - .fdo.qemu-build@fedora
  stage: prep
  variables:
    GIT_STRATEGY: none

pytest:
  extends:
    - .fedora-qemu
    - .fdo.distribution-image@fedora
  stage: test
  needs:
    - qemu-prep
  script:
    - /app/vmctl start || (echo "Error - Failed to start the VM." && exit 1)
    - "scp -r $PWD vm:"
    # We must not exit our script until VM cleanup is complete
    - set +e
    - /app/vmctl exec "cd $CI_PROJECT_NAME ; pytest --junit-xml=results.xml" && touch .success || true
    - scp -r vm:$CI_PROJECT_NAME/results.xml
    - /app/vmctl stop
    - test -e .success || exit 1
  artifacts:
    reports:
      junit: results.xml

flake:
  extends:
    - .fedora
    - .fdo.distribution-image@fedora
  stage: test
  needs:
    - container-prep
  script:
    - python3 setup.py flake8

install:
  extends:
    - .fedora
    - .fdo.distribution-image@fedora
  stage: test
  needs:
    - container-prep
  script:
    - python3 setup.py install
