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
  only:
    - main
  dependencies: 
    - npm_build
  script:
    - sudo apt-get install rsync
    - 'rsync -atv --progress --human-readable --delete --exclude="neos-assets/" dist/ kirayamato@8.142.104.5:$NEOS_DEPLOY_PATH'
    - 'rsync -atv --progress --human-readable --delete neos-assets/ kirayamato@8.142.104.5:$NEOS_DEPLOY_PATH/neos-assets'
    - 'rsync -atv --progress --human-readable --delete ygopro-database kirayamato@8.142.104.5:$NEOS_DEPLOY_PATH/ygopro-database'
  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'
    - chmod 700 ~/.ssh

