include:
- file: python3-lint-needs.gitlab-ci.yaml
  project: xcg/ci-templates
- file: docker-build.gitlab-ci.yaml
  project: xcg/ci-templates
- file: deploy-doc.gitlab-ci.yaml
  project: xcg/ci-templates

variables:
  HTML_DOC_SOURCES: doc/_build/html

import_jsonrpc_odoo11_test:
  stage: test
  needs: []
  image:
    # ci runners do not get the latest 11.0-bionic, so use the hash
    #name: registry.xcg.io/odoo/odoo:11.0-bionic
    name: registry.xcg.io/odoo/odoo:hg-9d8e9462c31889244df9569ed9ac159599d17472
    entrypoint: [""]
  services:
  - name: postgres:12-alpine
    command: ["-c", "fsync=off"]
    alias: db
  variables:
    POSTGRES_USER: odoo
    POSTGRES_HOST_AUTH_METHOD: trust
    ODOO_ADDONS_PATH: ""
    ODOO_TYPE: odoo11
  before_script:
  # install modules
  - $CI_PROJECT_DIR/start --db_host=db -d test_setup --max-cron-threads=0 --without-demo=all --data-dir /var/lib/odoo --init base --stop-after-init
  script:
  # restart odoo with installed modules and use it in background
  - $CI_PROJECT_DIR/start --db_host=db -d test_setup --max-cron-threads=0 --data-dir /var/lib/odoo &
  - sleep 3
  # then test the setup files
  - import_jsonrpc -v --host localhost --password admin -d test_setup --protocol jsonrpc -p 8069 --directory tests/import
  - import_jsonrpc -v --host localhost --password admin -d test_setup --protocol jsonrpc -p 8069 --file tests/context_import/res.company.csv --context test=value
  - import_jsonrpc -v --host localhost --password admin -d test_setup --protocol jsonrpc -p 8069 --directory tests/import_emptyyaml --delimiter ";"
  - import_sql -v --host postgres --user odoo --database test_setup --directory tests/import_sql
  # clean up background process
  - pkill --echo --full /usr/bin/python3
  - pkill --echo --full zsh

import_base_import_odoo11_test:
  extends: import_jsonrpc_odoo11_test
  script:
  # restart odoo with installed modules and use it in background
  - $CI_PROJECT_DIR/start --db_host=db -d test_setup --max-cron-threads=0 --data-dir /var/lib/odoo &
  - sleep 3
  # then test the setup files
  - import_base_import -v --host localhost --password admin -d test_setup --protocol jsonrpc -p 8069 --directory tests/import
  - import_sql -vv --host postgres --user odoo --database test_setup --directory tests/import_sql
  # clean up background process
  - pkill --echo --full /usr/bin/python3
  - pkill --echo --full zsh

import_jsonrpc_odoo13_test:
  extends: import_jsonrpc_odoo11_test
  image:
    # ci runners do not get the latest 13.0, so use the hash
    #name: registry.xcg.io/odoo/odoo:13.0
    name: registry.xcg.io/odoo/odoo:hg-05143ce629ed64d9b4d4713df4443ff4dddd3d9f
    entrypoint: [""]
  variables:
    ODOO_TYPE: odoo13

import_base_import_odoo13_test:
  extends: import_base_import_odoo11_test
  image:
    # ci runners do not get the latest 13.0, so use the hash
    #name: registry.xcg.io/odoo/odoo:13.0
    name: registry.xcg.io/odoo/odoo:hg-05143ce629ed64d9b4d4713df4443ff4dddd3d9f
    entrypoint: [""]
  variables:
    ODOO_TYPE: odoo13
  allow_failure: true

build-docker-image:
  needs: []
  variables:
    TAG_LATEST: branch/default
  script:
  - DOCKER_IMAGE=registry.xcg.io/xcgd/odoo_scripts docker-build
  - DOCKER_BASE_IMAGE_NAME=registry.xcg.io/xcgd/odoo_scripts DOCKER_IMAGE=xcgd/odoo_scripts docker-tag

build-documentation:
  stage: build
  needs: []
  image: python:3.8-alpine
  artifacts:
    paths:
    - doc/_build
    expire_in: 10m
  script:
  - apk add make mercurial
  # It might not be necessary to install this and the dependency (maybe just reuse the built image? but its done after)
  - pip3 install .
  - cd doc
  - pip3 install -r requirements hg-evolve
  - for language in en fr ; do LANGUAGE=$language BUILDDIRSUFFIX=/$CI_COMMIT_HG_BRANCH make html ; done

publish_documentation:
  needs:
  - job: build-documentation
    artifacts: true
  only:
  - /^branch\/.*/
