stages:
- test
- build
- push

flake8:
  stage: test
  image:
    name: xcgd/flake8:3
    entrypoint: [/bin/busybox]
  script:
  - flake8

isort:
  stage: test
  image: xcgd/isort
  script:
  - isort --check-only --diff

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_PASSWORD: ""
    POSTGRES_HOST_AUTH_METHOD: trust
  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 ";"

docker:
  stage: build
  image: docker.orus.io/cc/docker
  script:
  - export DOCKER_IMAGE=xcgd/odoo_scripts CUSTOM_TAG=latest
  - docker-build

build-documentation:
  stage: build
  image: python:3
  artifacts:
    paths:
    - doc/_build
    expire_in: 10m
  script:
  - pip3 install -r requirements
  - cd doc
  - pip3 install -r requirements
  - for language in en fr ; do LANGUAGE=$language BUILDDIRSUFFIX=/$(hg identify --debug --branch) make html ; done

push:
  stage: push
  image:
    name: minio/mc:RELEASE.2020-01-13T22-49-03Z
    entrypoint: ["/bin/busybox"]
  script:
    - mc config host add s3 $S3_ENDPOINT_URL $S3_KEY $S3_SECRET --api S3v2
    - mc cp --recursive doc/_build/html/ s3/xcg-io-doc/odoo_scripts