image: node:latest

stages:
    - prepare
    - test
    - build
    - deploy

cache: &global_cache
    key:
        files:
            - package-lock.json
    policy: pull
    paths:
        - node_modules/

install-dependencies:
    stage: prepare
    script:
        - npm install
    cache:
        <<: *global_cache
        policy: pull-push

lint:
    stage: test
    script:
        - npm run lint
    cache:
        <<: *global_cache

test:
    stage: test
    script:
        - npm run test:ci
    cache:
        <<: *global_cache
    artifacts:
        when: always
        reports:
            junit:
                - results.xml

build:
    stage: build
    script:
        - npm run build
    cache:
        <<: *global_cache
    artifacts:
        paths:
            - dist
        expire_in: 1 week

deploy:
    image: ianayoung/rsync:latest
    stage: deploy
    dependencies:
        - build
    script:
        - rsync --delete -az ./dist/ rsync://${DEPLOYMENT_USER}@${DEPLOYMENT_SERVER}:${DEPLOYMENT_PATH}
    environment:
        name: production
        url: https://vtt.f3l.de/
    only:
        - master