image: python:3.8-buster

stages:
  - bundle
  - test
  - deploy

variables:
  API_ROOT_FILE: ./src/aura_engine_api/rest/swagger/swagger.yaml
  BUNDLED_JSON_FILE: ./public/api.json

cache:
  paths:
    - ./node_modules

bundle_and_test:
  stage: bundle
  before_script:
    - apt-get --quiet update
    - apt-get --quiet --yes install nodejs
    - npm install -g @apidevtools/swagger-cli

  script:
    - mkdir public
    - swagger-cli bundle -t json $API_ROOT_FILE > $BUNDLED_JSON_FILE
    - swagger-cli validate $BUNDLED_JSON_FILE

  artifacts:
    paths:
      - public
    expire_in: 2 days
  only:
    - $CI_DEFAULT_BRANCH

check_style:
  stage: test
  before_script:
    - apt-get --quiet update
    - apt-get --quiet --yes install codespell make
    - pip install flake8
  script:
    - make lint
    - make spelling

# test_api:
#   stage: test
#   script:
#     - pip3 install tox
#     - tox

pages:
  stage: deploy
  before_script:
    - apt-get --quiet update
    - apt-get --quiet --yes install nodejs
    - npm install swagger-ui-dist@3.22.1
  script:
    - cp -rp node_modules/swagger-ui-dist/* ./public
    - 'sed -i "s@.*url.*@url: \"api.json\",@" ./public/index.html'
  artifacts:
    paths:
      - public
    expire_in: 2 days
  only:
    - $CI_DEFAULT_BRANCH