name: Build and Deploy Web App
on:
  push:
    paths:
      - 'web-app/**'
      - '.gitea/workflows/web-app.yaml'
    branches:
      - main
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '22.x'
      - name: Enable Corepack
        run: corepack enable
      - name: Install Dependencies
        run: yarn install --immutable
        working-directory: ./web-app
      - name: Build
        run: yarn build
        working-directory: ./web-app
      - name: Install SSH Key
        uses: shimataro/ssh-key-action@v2
        with:
          key: ${{ secrets.DEPLOY_KEY }}
          known_hosts: ${{ secrets.SSH_HOST }}
      - name: Setup rsync
        uses: GuillaumeFalourd/setup-rsync@v1.2
      - name: Upload static web content
        run: rsync -rav -e ssh --delete dist/* root@andrewlalis.com:/opt/finnow/app-content
        working-directory: ./web-app
