Skip to content

chore(ci): add lint job #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: 4.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .commitlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
"defaultIgnores": true,
"extends": "@commitlint/config-conventional",
"rules": {
"scope-enum": [
2,
"always",
[
"app",
"config",
"database",
"routes",
"resources",
"laravel",
"api-p",
"js",
"blade",
"deps",
"larastan",
]
],
"scope-empty": [
0
],
"body-leading-blank": [
1,
"always"
],
"body-max-line-length": [
2,
"always",
100
],
"footer-leading-blank": [
1,
"always"
],
"footer-max-line-length": [
2,
"always",
100
],
"header-max-length": [
2,
"always",
100
],
"subject-case": [
2,
"never",
[
"sentence-case",
"start-case",
"pascal-case"
]
],
"subject-empty": [
2,
"never"
],
"subject-full-stop": [
2,
"never",
"."
],
"type-case": [
2,
"always",
"lower-case"
],
"type-empty": [
2,
"never"
],
"type-enum": [
2,
"always",
[
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"cs",
"test"
]
]
}
}
22 changes: 22 additions & 0 deletions .github/workflows/commitlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: commitlint

on: [pull_request]

jobs:
commitlint:
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run commitlint
run: |
commit=$(gh api \
/repos/${{ github.repository }}/pulls/${{github.event.number}}/commits \
| jq -r '.[0].commit.message' \
| head -n 1)
# we can't use npx see https://github.com/conventional-changelog/commitlint/issues/613
echo '{}' > package.json
npm install --no-fund --no-audit @commitlint/config-conventional @commitlint/cli
echo $commit | ./node_modules/.bin/commitlint -g .commitlintrc
81 changes: 81 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Lint

on:
push:
pull_request:

env:
fail-fast: true

permissions:
contents: read

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
matrix:
operating-system: [ 'ubuntu-latest', 'windows-latest', 'macos-latest' ]
php-versions: [ '8.3' ] # TODO: Await PHP-CS-Fixer support for PHP 8.4 compatibility
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup PHP with quality tools
uses: shivammathur/setup-php@v2

#TODO: extensions and caching if we use them
with:
php-version: ${{ matrix.php-versions }}
tools: composer, php-cs-fixer, rector, phpstan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Lint composer
run: composer validate --strict

- name: Install dependencies
run: composer install --prefer-dist

- name: Composer normalize
run: composer normalize --dry-run

- name: Composer audit
run: composer audit

- name: Setup PHP Code Quality Tools
run: composer run install-tools

- name: Lint PHP files (CS)
run: composer run fix-cs -- --dry-run --diff --using-cache=no --stop-on-violation --show-progress=bar

- name: Static analysis on PHP files
#TODO: replace with larastan when https://github.com/api-platform/laravel-demo/pull/4 will be merged
run: composer run phpstan -- -n

- name: Lint with Rector
run: composer run rector -- --dry-run --clear-cache

# Lint other files with Super Linter
- name: Lint with Super Linter
uses: super-linter/super-linter/slim@v7
env:
DEFAULT_BRANCH: "origin/4.0"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_PHP_PHPSTAN: false
VALIDATE_PHP: false
VALIDATE_EDITORCONFIG: false
VALIDATE_JSCPD: false
VALIDATE_MARKDOWN_PRETTIER: false
71 changes: 40 additions & 31 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
{
"name": "api-platform/demo",
"description": "Demo app for the API Platform framework using Laravel",
"type": "project",
"keywords": ["api-platform", "demo", "laravel", "api", "framework"],
"license": "MIT",
"type": "project",
"keywords": [
"api-platform",
"demo",
"laravel",
"api",
"framework"
],
"require": {
"php": "^8.3",
"api-platform/laravel": "^4.0.16",
"laravel/framework": "^11.41.3",
"laravel/tinker": "^2.10.1"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.45",
"ergebnis/phpunit-slow-test-detector": "^2.18",
"fakerphp/faker": "^1.24.1",
"laravel/pail": "^1.2.2",
"laravel/pint": "^1.20",
Expand All @@ -19,6 +27,8 @@
"nunomaduro/collision": "^8.6.1",
"phpunit/phpunit": "^11.5.6"
},
"minimum-stability": "stable",
"prefer-stable": true,
"autoload": {
"psr-4": {
"App\\": "app/",
Expand All @@ -31,14 +41,30 @@
"Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
"pestphp/pest-plugin": true,
"php-http/discovery": true
},
"bump-after-update": true,
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"scripts": {
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
Expand All @@ -51,19 +77,14 @@
"Composer\\Config::disableProcessTimeout",
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite"
],
"fix-cs": [
"./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=php-cs-fixer.dist.php"
],
"install-tools": [
"composer install --working-dir=tools/php-cs-fixer",
"composer install --working-dir=tools/phpstan",
"composer install --working-dir=tools/rector"
],
"update-tools": [
"composer update --working-dir=tools/php-cs-fixer",
"composer update --working-dir=tools/phpstan",
"composer update --working-dir=tools/rector"
],
"fix-cs": [
"./tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=php-cs-fixer.dist.php"
],
"phpstan": [
"./tools/phpstan/vendor/bin/phpstan"
],
Expand All @@ -74,23 +95,11 @@
"@fix-cs",
"@run-phpstan",
"@run-rector"
],
"update-tools": [
"composer update --working-dir=tools/php-cs-fixer",
"composer update --working-dir=tools/phpstan",
"composer update --working-dir=tools/rector"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
},
"bump-after-update": true
},
"minimum-stability": "stable",
"prefer-stable": true
}
}
Loading
Loading