name: pyenv_tests
on: [pull_request, push]

permissions:
  contents: read  #  to fetch code (actions/checkout)

jobs:
  pyenv_tests:
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-24.04
          - ubuntu-22.04
          - macos-15-intel
          - macos-14
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v5
      # Normally, we would use the superbly maintained...
      # - uses: actions/setup-python@v2
      #   with:
      #    python-version: ${{ matrix.python-version }}
      # ... but in the repo, we want to test pyenv builds on Ubuntu
      # - run: |
          # sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
              # libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
              # xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
      # https://github.com/pyenv/pyenv#installation
      - run: |
          if test "$RUNNER_OS" == "macOS"; then
            brew install coreutils fish
          elif [[ $(lsb_release -sr | awk -F. '{print $1}') -ge 20 ]]; then
            # Ubuntu 18 has fish 2 which lacks many features that facilitate testing
            sudo apt install fish -yq
          fi
      - run: pwd
      - env:
          PYENV_ROOT: /home/runner/work/pyenv/pyenv
        run: |
          echo $PYENV_ROOT
          echo "$PYENV_ROOT/shims:$PYENV_ROOT/bin" >> $GITHUB_PATH
      - name: Run test on the host
        run: |
          make test
      - name: Run test with docker
        if: ${{ ! contains(matrix.os, 'macos') }}
        run: |
          make test-docker
      - env:
          PYENV_NATIVE_EXT: 1
        run: |
          (cd src; ./configure; make)
          bats/bin/bats test/{pyenv,hooks,versions}.bats
