name: Liquid
on: [push]

env:
  BUNDLE_JOBS: 4
  BUNDLE_RETRY: 3

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        entry:
          - { ruby: 3.3, allowed-failure: false } # minimum supported
          - { ruby: 3.4, allowed-failure: false, rubyopt: "--yjit" }
          - { ruby: 4.0, allowed-failure: false } # latest stable
          - {
              ruby: 4.0,
              allowed-failure: false,
              rubyopt: "--enable-frozen-string-literal",
            }
          - { ruby: 4.0, allowed-failure: false, rubyopt: "--yjit" }
          - { ruby: 4.0, allowed-failure: false, rubyopt: "--zjit" }

          # Head can have failures due to being in development
          - { ruby: head, allowed-failure: true }
          - {
              ruby: head,
              allowed-failure: true,
              rubyopt: "--enable-frozen-string-literal",
            }
          - { ruby: head, allowed-failure: true, rubyopt: "--yjit" }
          - { ruby: head, allowed-failure: true, rubyopt: "--zjit" }
    name: Test Ruby ${{ matrix.entry.ruby }} ${{ matrix.entry.rubyopt }} --${{ matrix.entry.allowed-failure && 'allowed-failure' || 'strict' }}
    steps:
      - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
      - uses: ruby/setup-ruby@a25f1e45f0e65a92fcb1e95e8847f78fb0a7197a # v1.273.0
        with:
          ruby-version: ${{ matrix.entry.ruby }}
          bundler-cache: true
          bundler: latest
      - run: bundle exec rake
        continue-on-error: ${{ matrix.entry.allowed-failure }}
        env:
          RUBYOPT: ${{ matrix.entry.rubyopt }}

  spec:
    runs-on: ubuntu-latest
    env:
      BUNDLE_WITH: spec
    steps:
      - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
      - uses: ruby/setup-ruby@a25f1e45f0e65a92fcb1e95e8847f78fb0a7197a # v1.273.0
        with:
          bundler-cache: true
          bundler: latest
      - name: Run liquid-spec for all adapters
        run: |
          for adapter in spec/*.rb; do
            echo "=== Running $adapter ==="
            bundle exec liquid-spec run "$adapter" --no-max-failures
          done

  memory_profile:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
      - uses: ruby/setup-ruby@a25f1e45f0e65a92fcb1e95e8847f78fb0a7197a # v1.273.0
        with:
          bundler-cache: true
      - run: bundle exec rake memory_profile:run
