diff --git a/.gitattributes b/.gitattributes index 368d461..8d6d4e1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ * text eol=lf tests/ export-ignore +.github export-ignore .gitattributes export-ignore .gitignore export-ignore composer.* export-ignore diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..a65bb36 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,67 @@ +name: "PHP" +on: + push: + branches: + - "main" + pull_request: + branches: + - "main" +permissions: + contents: "read" +jobs: + # PHP lint for different PHP versions + build: + runs-on: "ubuntu-latest" + strategy: + matrix: + php-version: + - "7.4" + - "8.1" + env: + CC_TEST_REPORTER_ID: "b6d85f5dc7af90e89653c56b04866b27d98b35e84c2ff9a5d9499bbb53469cbf" + name: "PHP ${{ matrix.php-version }}" + steps: + - # git checkout + name: "git checkout" + uses: "actions/checkout@v3" + - # Setup PHP + name: "Setup PHP" + uses: "shivammathur/setup-php@v2" + with: + php-version: "${{ matrix.php-version }}" + coverage: "xdebug" + - # Check PHP version + name: "Check PHP version" + run: "php -v" + - # Lint PHP files + name: "Lint PHP files" + run: | + for file in $(find src/ -type f -name '*.php'); do + echo -n "==> ${file}: "; + php -l "${file}"; + done + - # Validate composer.json and composer.lock + name: "Validate composer.json and composer.lock" + run: "composer validate --strict" + - # Cache Composer packages + name: "Cache Composer packages" + id: "composer-cache" + uses: "actions/cache@v3" + with: + path: "vendor" + key: "${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}" + restore-keys: "${{ runner.os }}-php-" + - # Install dependencies + name: "Install composer dependencies" + run: "composer install --prefer-dist --no-progress" + - # CodeClimate Reporter Setup + name: "CodeClimate Reporter Setup" + run: | + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + chmod +x ./cc-test-reporter + ./cc-test-reporter before-build + - # Run phpunit + name: "Run phpunit" + run: | + php vendor/bin/phpunit --coverage-clover clover.xml --coverage-text + ./cc-test-reporter after-build -t clover --exit-code $? \ No newline at end of file