name: Test mupdf release branch

on:
  schedule:
    - cron: '20 6 * * *'
  workflow_dispatch:

jobs:

  test_mupdf_release_branch:
    # Build+test current PyMuPDF git with mupdf git release branch.
    #
    name: Test mupdf release branch
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-20.04, windows-2019, macos-10.15]

      # Avoid cancelling of all cibuildwheel runs after a single failure.
      fail-fast: false

    steps:

      - uses: actions/checkout@v2
        with:
          ref: 1.21
      - uses: actions/setup-python@v2

      # Set up cibuildwheel.
      #
      - name: cibuildwheel
        uses: pypa/cibuildwheel@v2.11.2

        env:
            # PYMUPDF_SETUP_MUPDF_TGZ="": don't embed mupdf in sdist - no need
            # because the build stage gets MuPDF using `git clone ...`.
            #
            # PYMUPDF_SETUP_MUPDF_BUILD="git:...": build with mupdf from a `git
            # clone` command, selecting the current release branch.
            #
            CIBW_ENVIRONMENT: PYMUPDF_SETUP_MUPDF_TGZ="" PYMUPDF_SETUP_MUPDF_BUILD="git:--recursive --depth 1 --shallow-submodules --branch 1.21.x https://github.com/ArtifexSoftware/mupdf.git"

            # Build on single cpu.
            CIBW_ARCHS_LINUX: x86_64

            # Build for single python version.
            CIBW_BUILD: "cp311*"

            # Don't build for unsupported platforms.
            CIBW_SKIP: "pp* *i686 *-musllinux_* cp36*"

            # Get cibuildwheel to run pytest with each wheel.
            CIBW_TEST_REQUIRES: "fontTools pytest"
            CIBW_TEST_COMMAND: "pytest -s {project}/tests"
            CIBW_BUILD_VERBOSITY: 3
