name: ci

on:
  pull_request:
    branches:
    - gh-pages
  pull_request_review:
      types: [submitted]
  push:
    branches:
    - gh-pages

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-latest
    if: |
      github.event.pull_request.draft != true &&
      (github.event_name == 'pull_request_review' && github.event.review.state == 'approved') ||
      github.event_name != 'pull_request_review'

    steps:
    - uses: actions/checkout@v6
      with:
        persist-credentials: false
 

    - name: Set up Node.js
      uses: actions/setup-node@v6

    - name: Install Node.js dependencies
      run: npm install

    - name: Run tests
      shell: bash
      run: npm test

  build:
    name: Build
    runs-on: ubuntu-latest
    if: |
      github.event.pull_request.draft != true &&
      (github.event_name == 'pull_request_review' && github.event.review.state == 'approved') ||
      github.event_name != 'pull_request_review'

    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false

      - name: Setup Ruby    
        uses: ruby/setup-ruby@4c24fa5ec04b2e79eb40571b1cee2a0d2b705771 # https://github.com/ruby/setup-ruby/releases/tag/v1.278.0
        with:
          bundler-cache: true # runs 'bundle install' and caches installed gems automatically

      - name: Jekyll Build
        run: bundle exec jekyll build

      - name: Check Docker support
        shell: bash
        run: |
          docker --version
          make build
