image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA

stages:
  - BuildImage
  - SetupPackage
  - PrepareDb
  - UnitTests
  - PackageTests
  
build:
  stage: BuildImage
  image: docker:stable
  services:
    - docker:stable-dind
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker pull $CI_REGISTRY_IMAGE:latestci || true
    - cd docker
    - docker build -f Dockerfile_externals --cache-from $CI_REGISTRY_IMAGE:latestci --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE:latestci .
    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
    - docker push $CI_REGISTRY_IMAGE:latestci
    
setup_wheel:
  stage: SetupPackage
  script:
    - echo -n "latestci" > dist/version.txt
    - dist/build.sh
    - ls dist
  artifacts:
    paths:
      - dist

init_sqlite:
  stage: PrepareDb
  script:
    - export LT_CFG=Voiture
    - dist/install.sh
    - test/instance/init_db.sh
  artifacts:
    paths:
      - test/instance

test_sqlite:
  stage: PackageTests
  script:
    - export LT_CFG=Voiture
    - cd test/instance
    - ls -l ${LT_CFG}.sqlite

doctests:
  stage: UnitTests
  script:
    - export LT_CFG=Voiture
    - test/scripts/doctests.sh
