name: Upload nightly wheels
on:
  workflow_dispatch:
  schedule:
    - cron: "0 0 * * *"
jobs:
  cron:
    runs-on: ubuntu-latest
    if: github.repository == 'pydata/xarray'
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0
      - uses: actions/setup-python@v6
        with:
          python-version: "3.12"

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

      - name: Build tarball and wheels
        run: |
          git clean -xdf
          git restore -SW .
          python -m build

      - name: Check built artifacts
        run: |
          python -m twine check --strict dist/*
          pwd
          if [ -f dist/xarray-0.0.0.tar.gz ]; then
              echo "❌ INVALID VERSION NUMBER"
              exit 1
          else
              echo "✅ Looks good"
          fi

      - name: Upload wheel
        uses: scientific-python/upload-nightly-action@5748273c71e2d8d3a61f3a11a16421c8954f9ecf # 0.6.3
        with:
          anaconda_nightly_upload_token: ${{ secrets.ANACONDA_NIGHTLY }}
          artifacts_path: dist
