name: macOS CI

on: [push, pull_request]

permissions: {}

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

env:
  SPEC_SPLIT_DOTS: 160
  CI_NIX_SHELL: true

jobs:
  darwin-test:
    runs-on: ${{ matrix.runs-on }}
    name: "${{ matrix.runs-on }} (${{ matrix.arch }})"
    strategy:
      fail-fast: false
      matrix:
        include:
        - runs-on: macos-15-intel
          arch: x86_64-darwin
        - runs-on: macos-14
          arch: aarch64-darwin
        - runs-on: macos-15
          arch: aarch64-darwin
    steps:
      - name: Download Crystal source
        uses: actions/checkout@v6
        with:
          persist-credentials: false

      - uses: cachix/install-nix-action@616559265b40713947b9c190a8ff4b507b5df49b # v31.10.4
        with:
          extra_nix_config: |
            experimental-features = nix-command

      - uses: cachix/cachix-action@1eb2ef646ac0255473d23a5907ad7b04ce94065c # v17
        with:
          name: crystal-ci
          signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'

      - name: Prepare System
        run: bin/ci prepare_system

      - name: Prepare Build
        run: bin/ci prepare_build

      - name: Test
        run: bin/ci build

      - name: Test interpreter
        run: bin/ci with_build_env 'make interpreter_spec'

  test-std:
    runs-on: macos-15
    strategy:
      fail-fast: false
      matrix:
        opts:
          - flags: "-Dexecution_context -Dpreview_mt" # execution_context: concurrent
            workers: 1
          - flags: "-Dexecution_context -Dpreview_mt" # execution_context: parallel
            workers: 4
    steps:
      - name: Download Crystal source
        uses: actions/checkout@v6
        with:
          persist-credentials: false

      - uses: cachix/install-nix-action@616559265b40713947b9c190a8ff4b507b5df49b # v31.10.4
        with:
          extra_nix_config: |
            experimental-features = nix-command

      - uses: cachix/cachix-action@1eb2ef646ac0255473d23a5907ad7b04ce94065c # v17
        with:
          name: crystal-ci
          signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'

      - name: Prepare System
        run: bin/ci prepare_system

      - name: Prepare Build
        run: bin/ci prepare_build

      - name: Test
        run: bin/ci with_build_env 'CRYSTAL_WORKERS=${{ matrix.opts.workers || 1 }} make std_spec threads=1 FLAGS="${{ matrix.opts.flags }}"'
