name: Build and Deploy Jekyll site

on:
  push:
    branches: [ main, master ]
  pull_request:
    branches: [ main, master ]
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: website
    
    steps:
    - uses: actions/checkout@v3
    
    - name: Setup Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: '3.2'
        bundler-cache: true
        working-directory: website
    
    - name: Install dependencies
      run: |
        bundle install
    
    - name: Build site
      run: bundle exec jekyll build

    - name: Deploy to gh_pages branch
      uses: peaceiris/actions-gh-pages@v4
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        publish_dir: ./website/_site
        publish_branch: gh-pages
        keep_files: true