diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5dfc28e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,46 @@ +name: CI + +on: + push: + branches: ["**"] + pull_request: + +jobs: + quality: + name: PHP ${{ matrix.php }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: ["8.2", "8.3"] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - name: Validate composer.json + run: composer validate --strict + + - name: Install dependencies + run: composer install --no-interaction --no-progress --prefer-dist + + - name: Run CI checks + run: composer ci + + - name: Build app + if: matrix.php == '8.2' + run: composer ci:build + + - name: Upload build artifact + if: matrix.php == '8.2' + uses: actions/upload-artifact@v4 + with: + name: laracord-build-php82 + path: builds/laracord + if-no-files-found: error diff --git a/.gitignore b/.gitignore index d7428c8..ba742e2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ /.laracord *.sqlite .env +.box_dump \ No newline at end of file diff --git a/README.md b/README.md index 550f821..0a3ae9a 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,12 @@ Use `--no-migrate` if you want to skip migrations on boot. ## Dev +Run CI checks locally: + +```bash +composer ci +``` + Format with Pint: ```bash diff --git a/composer.json b/composer.json index 48bdef9..a81d398 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,20 @@ } }, "scripts": { + "lint": [ + "@php scripts/php-lint.php" + ], + "format:check": [ + "vendor/bin/pint --test" + ], + "ci": [ + "@composer validate --strict", + "@composer lint", + "@composer format:check" + ], + "ci:build": [ + "@php laracord app:build --build-version=ci" + ], "post-root-package-install": [ "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" ] diff --git a/scripts/php-lint.php b/scripts/php-lint.php new file mode 100644 index 0000000..b4adef4 --- /dev/null +++ b/scripts/php-lint.php @@ -0,0 +1,28 @@ +isFile() || $file->getExtension() !== 'php') { + continue; + } + + $command = sprintf('php -l %s', escapeshellarg($file->getPathname())); + passthru($command, $exitCode); + + if ($exitCode !== 0) { + exit($exitCode); + } + } +}