name: Scheduled pre-release tests

on:
  schedule:
    # Run this workflow twice a week
    # ref: https://crontab.guru/#0_5_*_*_1,4
    - cron: "0 5 * * 1,4"
  workflow_dispatch:

env:
  FORCE_COLOR: "1" # Make tools pretty
  PIP_DISABLE_PIP_VERSION_CHECK: "1" # Don't check for pip updates

permissions: {}

jobs:
  prerelease:
    # only run this workflow for pydata owned repositories (avoid forks)
    if: github.repository_owner == 'pydata'
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.10", "3.14"]

    steps:
      - name: "Checkout repository 🛎"
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
        with:
          persist-credentials: false

      - name: "Setup CI environment 🛠"
        # Important: make sure to update the SHA after making any changes to the set-dev-env action
        uses: pydata/pydata-sphinx-theme/.github/actions/set-dev-env@e8db643b990df73812cf9397bc0f8cfa1164e4d3
        with:
          python-version: ${{ matrix.python-version }}
          pandoc: true

      - name: "Install (prerelease) dependencies 📦"
        run: |
          python -Im pip install --upgrade pip wheel setuptools

      - name: "Build PST docs and check for warnings 📖"
        run: |
          # example substitution: tox run -e docs-py312-docs
          python -Im tox run -e docs-py$(echo ${{ matrix.python-version }} | tr -d .)-docs -- --keep-going

      - name: "Run tests ✅ (no coverage)"
        run: |
          # this will compile the assets then run the tests
          python -Im tox run -e compile-assets,i18n-compile,py$(echo ${{ matrix.python-version }} | tr -d .)-tests-no-cov
          echo "PYTEST_ERRORS=$?" >> $GITHUB_ENV

      - name: "Build and inspect package 📦"
        uses: hynek/build-and-inspect-python-package@fe0a0fb1925ca263d076ca4f2c13e93a6e92a33e # 2.17.0
        if: matrix.python-version == '3.10'
        id: baipp
        with:
          # pydantic-core (via PyO3) does not yet support Python 3.14
          python-version: "3.13"

      - run: echo Packages can be found at "${BAIPP_DIST}"
        if: matrix.python-version == '3.10'
        env:
          BAIPP_DIST: ${{ steps.baipp.outputs.dist }}

      # Run tests on the built package (which will be later uploaded to PyPI)
      - name: "Install PST from wheel and test"
        if: matrix.python-version == '3.10'
        env:
          BAIPP_DIST: ${{ steps.baipp.outputs.dist }}
        run: |
          dist_loc="${BAIPP_DIST}"
          # calling with --installpkg so we can use the already built package
          tox run -e py312-tests-no-cov \
          --installpkg $dist_loc/*.whl \
          -- --deselect tests/test_build.py::test_translations

      # If either the docs build or the tests resulted in an error, create an issue to note it
      - name: "Create an issue if failure"
        uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5
        if: ${{ env.SPHINX_BUILD_UNEXPECTED_WARNINGS || !env.PYTEST_ERRORS }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          filename: .github/prerelease-template.md
