name: Deploy to GH Pages

on:
  push:
    branches: [ "master" ]

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./frontend
    permissions:
      pages: write
      id-token: write

    steps:
    - uses: actions/checkout@v3

    - uses: actions/setup-node@v3
      with:
        node-version: 18
        cache: 'yarn'
        cache-dependency-path: './frontend/yarn.lock'

    - name: Install and build
      run: |
        yarn install
        CI=false yarn build

    - name: Upload build artifact
      uses: actions/upload-pages-artifact@v1
      with:
        path: ./frontend/build   # Make sure this path points to your build output directory

    - name: Deploy to GitHub Pages
      id: deployment
      uses: actions/deploy-pages@v2

    # Optionally, add a step to output the deployment URL
    - name: Output deployment URL
      run: echo "Deployed to ${{ steps.deployment.outputs.page_url }}"
