# Scheduled workflow to test against upcoming Rust versions and latest dependencies
# Runs monthly to catch Rust ecosystem issues before they affect development
name: rust-next

permissions:
  contents: read

# First of each month at midnight UTC
on:
  schedule:
    - cron: '0 0 1 * *'
  workflow_dispatch:

env:
  RUST_BACKTRACE: 1
  CARGO_TERM_COLOR: always

concurrency:
  group: "${{ github.workflow }}-${{ github.ref }}"
  cancel-in-progress: true

jobs:
  test:
    name: Test (${{ matrix.os }}, ${{ matrix.rust }})
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        rust: [stable, beta]
        include:
          # Only test nightly on Linux to reduce CI time
          - os: ubuntu-latest
            rust: nightly
    # Beta and nightly failures are non-blocking to avoid breaking on known issues
    continue-on-error: ${{ matrix.rust != 'stable' }}
    runs-on: ${{ matrix.os }}
    env:
      CARGO_PROFILE_DEV_DEBUG: line-tables-only

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust ${{ matrix.rust }}
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.rust }}

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2

      - name: Install cargo-hack
        uses: taiki-e/install-action@cargo-hack

      - name: Build
        run: cargo test --workspace --no-run

      - name: Test each feature combination
        run: cargo hack test --each-feature --workspace

  latest:
    name: Check latest dependencies
    runs-on: ubuntu-latest
    env:
      # Allow testing with newer deps that may require newer Rust
      CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS: allow
      CARGO_PROFILE_DEV_DEBUG: line-tables-only

    steps:
      - uses: actions/checkout@v6

      - name: Install Rust stable
        uses: dtolnay/rust-toolchain@stable

      - name: Cache Rust dependencies
        uses: Swatinem/rust-cache@v2

      - name: Install cargo-hack
        uses: taiki-e/install-action@cargo-hack

      - name: Update dependencies to latest versions
        run: cargo update

      - name: Build
        run: cargo test --workspace --no-run

      - name: Test each feature combination
        run: cargo hack test --each-feature --workspace
