variables:
  WORKON_HOME: .pipenv/venvs
  PIP_CACHE_DIR: .pipenv/pipcache

stages:
  - deploy_dev
  - package_test
  - deploy

build_and_deploy_gitlab:
  image: nikolaik/python-nodejs:python3.11-nodejs20
  stage: deploy_dev
  script:
    - pip install pipenv
    - pipenv install
    - npm ci --cache .npm --prefer-offline
    - pipenv run npm run build:prod
    - pipenv run python -m build
    - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token pipenv run python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
  cache:
    paths:
      - .npm/
      - .pipenv/
  rules:
    - if: ($CI_COMMIT_BRANCH == "main")

deploy_exemple_site:
  image: python:3.11.6-bookworm
  stage: package_test
  script:
    - git clone --no-tags --single-branch --depth=1 ${CI_SERVER_URL}/pub/numeco/mkdocs-dsfr-exemple.git
    - cd mkdocs-dsfr-exemple
    - pip install mkdocs-dsfr --index-url https://gitlab-forge.din.developpement-durable.gouv.fr/api/v4/projects/20363/packages/pypi/simple
    - mkdocs build --strict --verbose -d ../public
  artifacts:
    paths:
      - public