# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js Github Side

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    name: build app
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js 20.x
      uses: actions/setup-node@v2
      with:
        node-version: 20.x
        cache-dependency-path: package-lock.json
    - run: echo "test"
    - run: npm ci
    - run: npm run build
      env:
        VITE_SYNCDB_ENDPOINT: ${{ secrets.VITE_SYNCDB_ENDPOINT }}
        VITE_USER_ENDPOINT: ${{ secrets.VITE_USER_ENDPOINT }}
        VITE_CREATE_ENDPOINT: ${{ secrets.VITE_CREATE_ENDPOINT }}
        NODE_OPTIONS: --max-old-space-size=4096
    - name: Archive production artifacts
      uses: actions/upload-artifact@v4
      with:
        name: upload-dist
        path: ./dist
        overwrite: true
  deploy:
    name: deploy on linode
    needs: build
    runs-on: self-hosted
    steps:
      - name: get artifact
        uses: actions/download-artifact@v4
        with:
          name: upload-dist
          path: dist
      - run: pwd
      - run: cp -r ./dist/* /var/www/deepdiagram/
    
