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

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
  artifacts:
    paths:
      - dist

deploy:
  stage: deploy
  tags:
    - linux
  extends: npm_build
  script:
    - sudo apt-get install rsync
    - rsync -atv --progress --human-readable -e 'ssh -i ~/.ssh/id_ed25519' dist/ 'kirayamato@8.142.104.5:${NEOS_DEPLOY_PATH}'
    - rsync -atv --progress --human-readable -e 'ssh -i ~/.ssh/id_ed25519' assets/ 'kirayamato@8.142.104.5:${NEOS_DEPLOY_PATH}/assets'
  before_script:
    - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'

    - eval $(ssh-agent -s)

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

    - mkdir -p ~/.ssh
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
    - echo '$NEOS_SSH_PRIVATE_KEY' > ~/.ssh/id_ed25519
    - chmod 700 ~/.ssh

