name: CI
on:
  push:
    branches:
      - 'main'
      - 'release-*'
    tags: ['*']
  pull_request:
  workflow_dispatch:
concurrency:
  # Skip intermediate builds: all builds except for builds on the `main` or `release-*` branches
  # Cancel intermediate builds: only pull request builds
  group: ${{ github.workflow }}-${{ github.ref }}-${{ github.ref != 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release-') || github.run_number }}
  cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
  test:
    name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
    runs-on: ${{ matrix.os }}
    permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created
      actions: write
      contents: read
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - macos-13 # Intel
          - windows-latest
        arch:
          - 'x64'
          - 'x86'
        version:
          - '1.6' # compat
          - 'lts'
          - 'nightly'
        exclude:
          - os: macos-13 # Intel
            arch: x86
        include:
          # macos-latest -> Apple Silicon (Need julia >= v1.8)
          - os: macos-latest # Apple Silicon
            arch: 'aarch64'
            version: 'lts'
          - os: macos-latest # Apple Silicon
            arch: 'aarch64'
            version: 'nightly'
    steps:
      - uses: actions/checkout@v5
      - uses: julia-actions/setup-julia@v2
        with:
          version: ${{ matrix.version }}
          arch: ${{ matrix.arch }}
      - uses: julia-actions/cache@v2
      - run: julia --color=yes .ci/test_and_change_uuid.jl
      - uses: julia-actions/julia-buildpkg@v1
      - uses: julia-actions/julia-runtest@v1
      - uses: julia-actions/julia-processcoverage@v1
      - uses: codecov/codecov-action@v5
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: lcov.info

  docs:
    name: Documentation
    runs-on: ubuntu-latest
    permissions:
      # needed to allow julia-actions/cache to proactively delete old caches that it has created
      actions: write 
      contents: write
      statuses: write
    steps:
      - uses: actions/checkout@v5
      - uses: julia-actions/setup-julia@v2
        with:
          version: 'nightly'
      - uses: julia-actions/cache@v2
      - run: julia --color=yes .ci/test_and_change_uuid.jl
      - name: Configure doc environment
        shell: julia --project=docs --color=yes {0}
        run: |
          using Pkg
          Pkg.develop(PackageSpec(path=pwd()))
          Pkg.instantiate()
      - uses: julia-actions/julia-buildpkg@v1
      - name: Run doctests
        shell: julia --project=docs --color=yes {0}
        run: |
          using Documenter: DocMeta, doctest
          using DelimitedFiles
          DocMeta.setdocmeta!(DelimitedFiles, :DocTestSetup, :(using DelimitedFiles); recursive=true)
          doctest(DelimitedFiles)
      - uses: julia-actions/julia-docdeploy@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
