From 5e2470955f21e162df87fcd00abf21575b2d87da Mon Sep 17 00:00:00 2001 From: Olajide Date: Fri, 12 Dec 2025 19:13:59 +0100 Subject: [PATCH] branch the workflows --- .github/workflows/phpcs.yml | 87 +++++++++++++++++++ .github/workflows/phpstan.yml | 79 +++++++++++++++++ .github/workflows/{action.yml => phpunit.yml} | 24 +---- README.md | 4 +- 4 files changed, 170 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/phpcs.yml create mode 100644 .github/workflows/phpstan.yml rename .github/workflows/{action.yml => phpunit.yml} (75%) diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml new file mode 100644 index 0000000..13703cd --- /dev/null +++ b/.github/workflows/phpcs.yml @@ -0,0 +1,87 @@ +name: PHPCS + +on: + pull_request: + branches: [ "main", "develop" ] + # Manual runs from the Actions tab + workflow_dispatch: + +jobs: + tests: + name: "PHP ${{ matrix.php }} (deps: ${{ matrix.deps }})" + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php: [ "8.2" ] + deps: [ "stable" ] + + env: + # Typical CI4 testing env values + APP_ENV: testing + CI_ENVIRONMENT: testing + + steps: + # --- 1. Checkout code --------------------------------------------------- + - name: Checkout repository + uses: actions/checkout@v4 + + # --- 2. Setup PHP ------------------------------------------------------- + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring, intl, json, pdo_mysql, sqlite3 + ini-values: | + memory_limit=512M + coverage: none + tools: composer + + # --- 3. Cache Composer dependencies ------------------------------------ + - name: Get Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.deps }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.deps }}-composer- + + # --- 4. Install dependencies ------------------------------------------- + - name: Install Composer dependencies + run: | + if [ "${{ matrix.deps }}" = "lowest" ]; then + composer update --prefer-lowest --no-interaction --no-progress + else + composer install --no-interaction --no-progress --prefer-dist + fi + + # --- 5. Prepare .env for CodeIgniter 4---------------------- + # name it `.env.github-ci` + - name: Prepare .env + run: | + if [ -f .env.github-ci ]; then + cp .env.github-ci .env + elif [ -f env ]; then + cp env .env + fi + + # --- 6. Coding standards (PHPCS) - optional ---------------------------- + - name: Run PHPCS (if configured) + if: ${{ hashFiles('phpcs.xml*') != '' }} + run: | + if [ -f vendor/bin/phpcs ]; then + vendor/bin/phpcs + fi + + # --- 7. PHP-CBF (dry-run) - optional ----------------------------- + - name: Run PHP-CBF (dry-run, if configured) + if: ${{ hashFiles('.php-cs-fixer.dist.php', '.php-cs-fixer.php') != '' }} + run: | + if [ -f vendor/bin/phpcbf ]; then + vendor/bin/phpcbf + fi diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..fbf1998 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,79 @@ +name: PHPStan + +on: + pull_request: + branches: [ "main", "develop" ] + # Manual runs from the Actions tab + workflow_dispatch: + +jobs: + tests: + name: "PHP ${{ matrix.php }} (deps: ${{ matrix.deps }})" + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php: [ "8.2" ] + deps: [ "stable" ] + + env: + # Typical CI4 testing env values + APP_ENV: testing + CI_ENVIRONMENT: testing + + steps: + # --- 1. Checkout code --------------------------------------------------- + - name: Checkout repository + uses: actions/checkout@v4 + + # --- 2. Setup PHP ------------------------------------------------------- + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring, intl, json, pdo_mysql, sqlite3 + ini-values: | + memory_limit=512M + coverage: none + tools: composer + + # --- 3. Cache Composer dependencies ------------------------------------ + - name: Get Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.deps }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.deps }}-composer- + + # --- 4. Install dependencies ------------------------------------------- + - name: Install Composer dependencies + run: | + if [ "${{ matrix.deps }}" = "lowest" ]; then + composer update --prefer-lowest --no-interaction --no-progress + else + composer install --no-interaction --no-progress --prefer-dist + fi + + # --- 5. Prepare .env for CodeIgniter 4---------------------- + # name it `.env.github-ci` + - name: Prepare .env + run: | + if [ -f .env.github-ci ]; then + cp .env.github-ci .env + elif [ -f env ]; then + cp env .env + fi + + # --- 6. Static analysis (PHPStan) - --------------------------- + - name: Run PHPStan (if configured) + if: ${{ hashFiles('phpstan.neon*') != '' }} + run: | + if [ -f vendor/bin/phpstan ]; then + vendor/bin/phpstan analyse src tests --no-progress + fi diff --git a/.github/workflows/action.yml b/.github/workflows/phpunit.yml similarity index 75% rename from .github/workflows/action.yml rename to .github/workflows/phpunit.yml index f3d941a..de5f378 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/phpunit.yml @@ -86,26 +86,4 @@ jobs: exit 1 fi - # --- 8. Static analysis (PHPStan) - optional --------------------------- - - name: Run PHPStan (if configured) - if: ${{ hashFiles('phpstan.neon*') != '' }} - run: | - if [ -f vendor/bin/phpstan ]; then - vendor/bin/phpstan analyse src tests --no-progress - fi - - # --- 9. Coding standards (PHPCS) - optional ---------------------------- - - name: Run PHPCS (if configured) - if: ${{ hashFiles('phpcs.xml*') != '' }} - run: | - if [ -f vendor/bin/phpcs ]; then - vendor/bin/phpcs - fi - - # --- 10. PHP-CBF (dry-run) - optional ----------------------------- - - name: Run PHP-CBF (dry-run, if configured) - if: ${{ hashFiles('.php-cs-fixer.dist.php', '.php-cs-fixer.php') != '' }} - run: | - if [ -f vendor/bin/phpcbf ]; then - vendor/bin/phpcbf - fi + diff --git a/README.md b/README.md index 8c1d02d..b933b21 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@ [![Latest Version on Packagist](https://img.shields.io/packagist/v/olajideolamide/ci4-settings.svg)](https://packagist.org/packages/olajideolamide/ci4-settings) ![GitHub License](https://img.shields.io/github/license/olajideolamide/ci4-settings) -![PHP CI](https://github.com/olajideolamide/ci4-settings/actions/workflows/action.yml/badge.svg) +![PHP UNIT](https://github.com/olajideolamide/ci4-settings/actions/workflows/phpunit.yml/badge.svg) +![PHP STAN](https://github.com/olajideolamide/ci4-settings/actions/workflows/phpstan.yml/badge.svg) +![PHP CS](https://github.com/olajideolamide/ci4-settings/actions/workflows/phpcs.yml/badge.svg)