include:
- file: python3-lint.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
- file: shell-lint.gitlab-ci.yaml
  project: xcg/ci-templates

variables:
  TAG_LATEST: branch/default
  DOCKER_IMAGE: xcgd/odoo_scripts
  HTML_DOC_SOURCES: doc/_build/html
  SH_SCRIPTS: isort create_archive start

checkbashisms:
  allow_failure: true

import_jsonrpc_odoo11_test:
  stage: test
  image:
    name: registry.xcg.io/odoo/odoo:11.0-bionic
    entrypoint: [""]
  services:
  - name: postgres:11-alpine
    command: ["-c", "fsync=off"]
    alias: db
  variables:
    POSTGRES_USER: odoo
    POSTGRES_HOST_AUTH_METHOD: trust
    ODOO_ADDONS_PATH: ""
  before_script:
  - pip3 install $CI_PROJECT_DIR --disable-pip-version-check --no-cache-dir
  script:
  - sudo -u odoo env ODOO_TYPE=odoo11 $CI_PROJECT_DIR/start --db_host=db -d test_setup --max-cron-threads=0 --without-demo=all --data-dir /var/lib/odoo --init base &
  # wait for odoo to install the modules
  - sleep 35
  # 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 -vv --host postgres --user odoo --database test_setup --directory tests/import_sql

build-documentation:
  stage: build
  image: python:3-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=/$(hg identify --debug --branch) make html ; done

publish_documentation:
  only:
  - /^branch\/.*/
