# .github/workflows/netlify.yml
name: Build and Deploy to Netlify
on:
  pull_request:
  push:
  workflow_dispatch:
jobs:
  build:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v3
        
      - uses: actions/setup-node@v3
        with:
          node-version: 16

      - run: npm ci
      - run: npm run lint  
      - run: |
          cat <<EOF > ./backend/.env
          OPENVIDU_URL=${{ secrets.OPENVIDU_URL }}
          OPENVIDU_SECRET=${{ secrets.OPENVIDU_SECRET }}
          EOF
      - run: cat backend/.env
      - run: cd backend && npm ci && npm run build
        env:      
          RICOCHET_SITE_KEY: ${{ secrets.RICOCHET_SECRET_KEY }}
      - run: npm run build
        env:
          VITE_API_ENDPOINT: /api
          VITE_SOCKET_URL: https://public.jeremiez.net/
          VITE_SOCKET_PATH: /wamp/socket.io
          VITE_RICOCHET_SITEID: airboardgame
          VITE_USE_PROXY: 0
          VITE_WEBCONFERENCE: audio
          VITE_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
          VITE_ENVIRONMENT: production
          CYPRESS_INSTALL_BINARY: 0
      - run: |
          cat <<EOF > ./dist/_redirects
          /api/*  https://ricochetjs-deploy-production.up.railway.app/:splat  200
          /*    /index.html   200
          EOF

      - name: Deploy to Netlify
        uses: nwtgck/actions-netlify@v1.2
        with:
          publish-dir: './dist'
          production-branch: master
          github-token: ${{ secrets.GITHUB_TOKEN }}
          deploy-message: "Deploy from GitHub Actions"
          enable-pull-request-comment: false
          enable-commit-comment: true
          overwrites-pull-request-comment: true
        env:
          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
          NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
        timeout-minutes: 1
