name: Testing clients
on:
  - push
  - pull_request
jobs:
  build:
    name: Build beanstalkd
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: make
      - uses: actions/upload-artifact@v3
        with:
          name: beanstalkd
          path: beanstalkd
  pheanstalk:
    name: Test Pheanstalk PHP
    runs-on: ubuntu-latest
    continue-on-error: true
    needs:
      - build
    steps:
      - name: Set up PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: '8.1'
          tools: phpunit
      - uses: actions/download-artifact@v3
        with:
          name: beanstalkd
      - name: Start beanstalkd
        run: chmod +x ./beanstalkd && ./beanstalkd &
      - uses: actions/checkout@v3
        with:
          repository: pheanstalk/pheanstalk
          ref: v5
      - name: Install dependencies including dev-dependencies
        run: composer install
      - name: Run tests
        run: phpunit
        env:
          SERVER_HOST: localhost
  greenstalk:
    # Disable this test suite until https://github.com/justinmayhew/greenstalk/issues/9 is fixed
    if: ${{ false }}
    name: Test Greenstalk Python
    runs-on: ubuntu-latest
    continue-on-error: true
    strategy:
      matrix:
        python-version: [ 3.9 ]
    needs:
      - build
    steps:
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - uses: actions/checkout@v3
        with:
          repository: justinmayhew/greenstalk
      - uses: actions/download-artifact@v3
        id: download
        with:
          name: beanstalkd
      - name: Make beanstalkd executable
        run: chmod +x ${{steps.download.outputs.download-path}}/beanstalkd
      - name: Run beanstalkd -v
        run: ${{steps.download.outputs.download-path}}/beanstalkd -v

      - name: Install dependencies
        run: |
          pip install pytest
          pip install .
      - name: Run tests
        env:
          BEANSTALKD_PATH: ${{steps.download.outputs.download-path}}/beanstalkd
        run: make test
  pystalk:
    name: Test Pystalk Python
    runs-on: ubuntu-latest
    continue-on-error: true
    strategy:
      matrix:
        python-version: [ "3.10" ]
    needs:
      - build
    steps:
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - uses: actions/checkout@v3
        with:
          repository: EasyPost/pystalk
      - uses: actions/download-artifact@v3
        id: download
        with:
          name: beanstalkd
      - name: Make beanstalkd executable
        run: chmod +x ${{steps.download.outputs.download-path}}/beanstalkd
      - name: Run beanstalkd -v
        run: ${{steps.download.outputs.download-path}}/beanstalkd -v
      - name: Install dependencies
        run: python -m pip install -r requirements-tests.txt -e .
      - name: Run tests
        env:
          BEANSTALKD_PATH: ${{steps.download.outputs.download-path}}/beanstalkd
        run: pytest tests/
