name: CI

on:
  push:
  pull_request:
  schedule:
    - cron: "0 3 * * 1" # Every monday at 3 AM

jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        crystal: [latest, nightly]
    runs-on: ${{ matrix.os }}

    steps:
      - name: Install Crystal
        uses: crystal-lang/install-crystal@v1
        with:
          crystal: ${{ matrix.crystal }}

      - name: Download source
        uses: actions/checkout@v4

      - name: Install dependencies
        run: shards install

      - name: Run specs
        run: |
          crystal spec

  format:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        crystal: [latest, nightly]
    runs-on: ${{ matrix.os }}

    steps:
      - name: Install Crystal
        uses: crystal-lang/install-crystal@v1
        with:
          crystal: ${{ matrix.crystal }}

      - name: Download source
        uses: actions/checkout@v4

      - name: Check formatting
        run: crystal tool format --check
    
  ameba:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest]
        crystal: [latest]
    runs-on: ${{ matrix.os }}

    steps:
      - name: Install Crystal
        uses: crystal-lang/install-crystal@v1
        with:
          crystal: ${{ matrix.crystal }}

      - name: Download source
        uses: actions/checkout@v4

      - name: Install dependencies
        run: shards install

      - name: Run ameba linter
        run: bin/ameba
        