name: Build

on:
  push:
  pull_request:
    branches:
      - master

jobs:
  build_wheels:
    name: Build wheels on ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]

    steps:
      - uses: actions/checkout@v4

      - name: Build wheels
        uses: pypa/cibuildwheel@v3.3.1
        env:
          CIBW_SKIP: pp*
          CIBW_TEST_COMMAND: python -m unittest discover ephem
          CIBW_TEST_REQUIRES: tzdata

  build_wheels_python2:
    name: Build wheels on ${{ matrix.os }} (Python 2.7)
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        # GitHub Actions no longer supports macos-13
        os: [ubuntu-latest]

    steps:
      - uses: actions/checkout@v4

      - name: Build wheels
        uses: pypa/cibuildwheel@v1.12.0
        env:
          CIBW_BUILD: cp27-*
          CIBW_SKIP: pp*
          CIBW_TEST_COMMAND: python -m unittest discover ephem
          CIBW_TEST_REQUIRES: tzdata

  twine_check:
    name: Run twine check
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5
        name: Install Python
        with:
          python-version: '3.12'

      - name: Install dependencies
        run: python -m pip install build twine

      - name: Build sdist and wheel
        run: python -m build

      - name: Run twine check
        run: ls dist/* | xargs twine check
