image: registry.fedoraproject.org/fedora:latest

.instscript: &instscript
  - dnf install -y python3-pip python3-setuptools python3-devel python3-cryptography
  - dnf install -y make gcc diffutils help2man edk2-ovmf
  - dnf install -y edk2-aarch64 || true # optional
  - pip3 install --user crc32c pylint build twine
  - export PATH="${PATH}:${HOME}/.local/bin"

.testscript: &testscript
  - make test-dump
  - make test-vars
  - make test-sigdb
  - make test-pe
  - make test-bootcfg
  - make test-unittest
  - make manpages

package:
  stage: build
  before_script:
    - *instscript
    - dnf install -y fedora-packager pyp2rpm createrepo
  script:
    - make dist rpms
  artifacts:
    paths:
      - dist
      - rpms

test-fedora-pylint:
  stage: test
  before_script:
    - *instscript
    - dnf install -y python3-textual
  script:
    - make install
    - make pylint
    - *testscript

test-centos8:
  stage: test
  image: quay.io/centos/centos:stream8
  before_script:
    - dnf install -y 'dnf-command(config-manager)'
    - dnf config-manager --set-enabled powertools
    - *instscript
  script:
    - make install
    - *testscript

test-centos9:
  stage: test
  image: quay.io/centos/centos:stream9
  before_script:
    - *instscript
  script:
    - make install
    - *testscript

test-rpm:
  stage: test
  needs:
    - job: package
      artifacts: true
  before_script:
    - dnf install -y make diffutils help2man edk2-ovmf
    - dnf install -y edk2-aarch64 || true # optional
  script:
    - dnf install -y rpms/noarch/*.noarch.rpm
    - *testscript

pages:
  stage: deploy
  needs:
    - job: package
      artifacts: true
  only:
    - tags
  before_script:
    - dnf install -y tree
  script:
    - mkdir public
    - mv dist rpms public
    - tree -T "$CI_PROJECT_NAME rpms" --charset utf8 -H . public > index.html
    - mv index.html public
  artifacts:
    paths:
      - public/

twine:
  stage: deploy
  image: python:latest
  needs:
    - job: package
      artifacts: true
  only:
    - tags
  script:
    - pip install twine
    - ls -l dist
    - python -m twine check dist/*
    - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
