default:
  image: node:12

stages:
  - deps
  - check
  - build
  - test
  - deploy

node_install:
  stage: deps
  script:
    - npm ci --only=prod
  artifacts:
    paths:
      - node_modules

dev_node_install:
  stage: deps
  script:
    - npm ci
  artifacts:
    paths:
      - node_modules

check_format:
  stage: check
  dependencies:
    - dev_node_install
  script:
    - npx prettier --ignore-path .gitignore --check "**/*.{html,js,json,md}"

lint:
  stage: check
  dependencies:
    - dev_node_install
  script:
    - npx eslint --ignore-path .gitignore "**/*.js"

backend_build:
  stage: build
  dependencies:
    - dev_node_install
  script:
    - npm run build
  artifacts:
    paths:
      - public/

backend_test:
  stage: test
  dependencies:
    - dev_node_install
  script:
    - npm test

deploy:
  stage: deploy
  dependencies:
    - node_install
    - backend_build
  only:
    - master
  script:
    - apt-get update -qq && apt-get install -qq zip
    - zip -r application.zip * .[^.]*
    - curl -X POST -u "$DEPLOYMENT_USERNAME:$DEPLOYMENT_PASSWORD" $DEPLOYMENT_ENDPOINT -T application.zip
