stages:
  - install
  - lint
  - test
  - build
  - deploy

before_script:
  - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'

  - eval $(ssh-agent -s)

  - chmod 400 "$NEOS_SSH_PRIVATE_KEY"
  - ssh-add <(echo "$NEOS_SSH_PRIVATE_KEY" | base64 -d)

  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh

npm_ci:
  stage: install
  tags:
    - linux
  script: npm ci
  artifacts:
    paths:
      - node_modules

.build_base:
  tags:
    - linux
  dependencies:
    - npm_ci

npm_lint:
  extends: .build_base
  stage: lint
  tags:
    - linux
  script: npm run lint

npm_build:
  extends: .build_base
  stage: build
  tags:
    - linux
  script: npm run build

deploy:
  stage: deploy
  tags:
    - linux
  script:
    - sudo apt-get install rsync
    - rsync -av -e 'ssh -p 22' dist/ 'kirayamato@8.142.104.5:${NEOS_DEPLOY_PATH}'
    - rsync -av -e 'ssh -p 22' assets/ 'kirayamato@8.142.104.5:${NEOS_DEPLOY_PATH}/assets'

