---

include:
  - template: Security/SAST.gitlab-ci.yml

stages:
  - lint
  - tests
  - dist
  - deploy

variables:
  DEBIAN_FRONTEND: noninteractive
  SAST_DEFAULT_ANALYZERS: bandit
  PASS_VERSION: 1.7.3


# Dependencies definitions
# ------------------------

.pass: &pass
  - wget https://git.zx2c4.com/password-store/snapshot/password-store-$PASS_VERSION.tar.xz
  - tar -xf password-store-$PASS_VERSION.tar.xz
  - make --directory=password-store-$PASS_VERSION install

.script:
  script:
    - mkdir -p ~/.local/share/keyrings/
    - cp tests/assets/db/gnome-keyring.keyring ~/.local/share/keyrings/pass-import.keyring
    - pip3 install --upgrade pip
    - pip3 install --upgrade green coverage defusedxml pyaml cryptography pykeepass secretstorage file-magic
    - make
    - dbus-run-session -- make tests
    - make install
    - cd ~
    - pass import --help

.tests:
  extends: .script
  stage: tests
  before_script:
    - apt-get update -q && apt-get install -y make pass python3-pip grep dbus gnome-keyring

.distribution:
  extends: .script
  stage: dist
  only:
   - tags
   - web


# Jobs definitions
# ----------------

# Code Linters

shellcheck:
  stage: lint
  image: koalaman/shellcheck-alpine
  script:
    - shellcheck --shell=bash import.bash

prospector:
  stage: lint
  image: python:latest
  allow_failure: True
  before_script:
    - pip install prospector[with_everything] defusedxml dominate
  script:
    - make lint

sast:
  stage: lint

# Code tests

python 3.9:
  image: python:3.9
  extends: .tests
  coverage: '/\d+\%\s*$/'
  artifacts:
    expire_in: 2 days
    paths:
      - htmlcov/

python 3.8:
  image: python:3.8
  extends: .tests

python 3.7:
  image: python:3.7
  extends: .tests

python 3.6:
  image: python:3.6
  extends: .tests

# Distribution tests

archlinux:
  image: archlinux/base
  extends: .distribution
  before_script:
    - pacman -Syu --noconfirm --noprogressbar which grep make python-pip pass
        dbus gnome-keyring file

ubuntu:
  image: ubuntu
  extends: .distribution
  before_script:
    - apt-get update -q && apt-get install -y make pass python3-pip grep dbus
        gnome-keyring

debian:
  image: debian
  extends: .distribution
  before_script:
    - apt-get update -q && apt-get install -y make pass python3-pip grep wget
        dbus gnome-keyring
    - *pass

fedora:
  image: fedora
  extends: .distribution
  before_script:
    - dnf -y install make gpg pass python-setuptools python3-pip grep which dbus dbus-daemon
        gnome-keyring --setopt=install_weak_deps=False


# Code coverage deployment

pages:
  stage: deploy
  dependencies:
    - python 3.9
  script:
    - mv htmlcov/ public/
  artifacts:
    expire_in: 1 day
    paths:
      - public
  only:
    - master
