KonstantinCodes/messenger-kafka

View on GitHub
.github/workflows/php.yml

Summary

Maintainability
Test Coverage
name: Tests

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        php:
          - "7.4"
          - "8.1"

    services:
      kafka:
        image: lensesio/fast-data-dev
        env:
          ADV_HOST: 127.0.0.1
          SAMPLEDATA: 0
          RUNTESTS: 0
          FORWARDLOGS: 0
        ports:
          - 9092:9092
          - 8081:8081
          - 8082:8082
          - 8083:8083
          - 2181:2181

    steps:
      - uses: actions/checkout@v2

      - name: Validate composer.json and composer.lock
        run: composer validate

      - name: Install rdkafka
        run:
          sudo add-apt-repository universe && sudo apt update && sudo apt install netcat librdkafka1 librdkafka-dev

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: "${{ matrix.php }}"
          coverage: xdebug
          tools: pecl, phpunit
          extensions: rdkafka
          ini-values: post_max_size=256M, short_open_tag=On

      - name: check if rdkafka is there
        run: php -v && php --ri rdkafka

      - name: Cache Composer packages
        id: composer-cache
        uses: actions/cache@v2
        with:
          path: vendor
          key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
          restore-keys: |
            ${{ runner.os }}-php-

      - name: Install dependencies
        if: steps.composer-cache.outputs.cache-hit != 'true'
        run: composer update --prefer-dist --no-progress

      - name: Wait for Kafka
        run: .github/workflows/wait-for-kafka.sh

      - name: Unit Tests
        run: ./vendor/bin/simple-phpunit --log-junit results/tests/junit.xml

      #- name: try to produce
      #  run: echo "test" > testfile.json && kafkacat -b 0.0.0.0:9092 -t kafkacat_test -P testfile.json

      # Docs: https://getcomposer.org/doc/articles/scripts.md
      #- name: Run test suite
      #  run: phpunit --log-junit results/tests/junit.xml --coverage-html results/coverage-report --coverage-clover clover.xml