image: python:3.10

stages:
  - dependencies
  - lint
  - test
  - deploy

download_dependencies:
  stage: dependencies
  script:
    - python -m venv .venv
    - source .venv/bin/activate
    - pip install -r requirements.txt
  artifacts:
    paths:
      - .venv

pylint:
  stage: lint
  dependencies:
    - download_dependencies
  needs:
    - download_dependencies
  script:
    - source .venv/bin/activate
    - pip install pylint
    - pylint calculator --fail-on=error

pytest:
  stage: test
  dependencies:
    - download_dependencies
  needs:
    - download_dependencies
  script:
    - source .venv/bin/activate
    - pip install pytest
    - pytest calculator

deploy:
  stage: deploy
  needs:
    - pylint
    - pytest
  script:
    - apt-get update
    - apt-get install -y openssh-client sshpass
    - sshpass -p <mot-de-passe> ssh -o StrictHostKeyChecking=no <nom-d'utilisateur>@<ip-de-ma-vm>
      "cd /var/www/cicd && sudo git pull && sudo systemctl restart calculator"
