diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..b14c72f --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,63 @@ +name: Lint Check + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + style: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + extensions: mbstring, bcmath + tools: composer:v2 + + - name: Install Dependencies + run: composer install --no-scripts --no-interaction --prefer-dist + + - name: Check code style with Pint + run: | + vendor/bin/pint --test + if [ $? -eq 0 ]; then + echo "✅ Code style is clean" + else + echo "❌ Code style issues found" + vendor/bin/pint --verbose + exit 1 + fi + + - name: Add Lint Results as PR Comment + if: github.event_name == 'pull_request' && failure() + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const output = ` + ## ⚠️ PHP Code Style Check Failed + + Please fix the code style issues found by Laravel Pint. + Run \`composer lint\` locally to see and fix the issues. + + For more information about Laravel Pint, visit: https://laravel.com/docs/pint + `; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) diff --git a/composer.json b/composer.json index 4256cc2..0d32ff3 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "homepage": "https://github.com/eramitgupta/laravel-role-permission", "require": { "php": "^8.0", + "laravel/pint": "^1.13", "illuminate/auth": "^8.12|^9.0|^10.0|^11.0", "illuminate/container": "^8.12|^9.0|^10.0|^11.0", "illuminate/contracts": "^8.12|^9.0|^10.0|^11.0", @@ -38,11 +39,19 @@ } }, "prefer-stable": true, + "minimum-stability": "stable", "extra": { "laravel": { "providers": [ "EragPermission\\PermissionServiceProvider" ] } + }, + "scripts": { + "lint": "pint", + "lint:dirty": "pint --dirty", + "post-install-cmd": [ + "@lint" + ] } }