Skip to content

Commit 29726b2

Browse files
committed
👷 Add GitHub workflow for linting and code validation
1 parent 7a38635 commit 29726b2

3 files changed

Lines changed: 179 additions & 0 deletions

File tree

.github/workflows/code-lint.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
name: Code Lint
3+
4+
on:
5+
push:
6+
7+
jobs:
8+
php-cs-fixer:
9+
name: PHP CS Fixer
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup PHP
17+
uses: shivammathur/setup-php@v2
18+
with:
19+
php-version: '8.2'
20+
extensions: mbstring, intl
21+
coverage: none
22+
tools: php-cs-fixer
23+
24+
- name: Cache Composer packages
25+
id: composer-cache
26+
uses: actions/cache@v4
27+
with:
28+
path: vendor
29+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
30+
restore-keys: |
31+
${{ runner.os }}-php-
32+
33+
- name: Install dependencies
34+
run: composer install --prefer-dist --no-progress --no-dev
35+
36+
- name: Cache PHP CS Fixer
37+
uses: actions/cache@v4
38+
with:
39+
path: .php-cs-fixer.cache
40+
key: ${{ runner.os }}-php-cs-fixer-${{ hashFiles('.php-cs-fixer.dist.php') }}
41+
restore-keys: |
42+
${{ runner.os }}-php-cs-fixer-
43+
44+
- name: Run PHP CS Fixer (dry-run)
45+
shell: /usr/bin/bash -e {0}
46+
env:
47+
COMPOSER_PROCESS_TIMEOUT: 0
48+
COMPOSER_NO_INTERACTION: 1
49+
COMPOSER_NO_AUDIT: 1
50+
run: php-cs-fixer fix --dry-run --diff --verbose
51+
52+
- name: Upload PHP CS Fixer results
53+
if: failure()
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: php-cs-fixer-results
57+
path: .php-cs-fixer.cache
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
name: Code Validation
3+
4+
on:
5+
push:
6+
7+
jobs:
8+
phpstan:
9+
name: PHPStan
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
php-version: ['7.4','8.0', '8.1', '8.2', '8.3']
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup PHP ${{ matrix.php-version }}
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php-version }}
24+
extensions: mbstring, intl
25+
coverage: none
26+
tools: phpstan
27+
28+
- name: Cache Composer packages
29+
id: composer-cache
30+
uses: actions/cache@v4
31+
with:
32+
path: vendor
33+
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }}
34+
restore-keys: |
35+
${{ runner.os }}-php-${{ matrix.php-version }}-
36+
37+
- name: Install dependencies
38+
run: composer install --prefer-dist --no-progress
39+
40+
- name: Cache PHPStan results
41+
uses: actions/cache@v4
42+
with:
43+
path: /tmp/phpstan
44+
key: ${{ runner.os }}-phpstan-${{ matrix.php-version }}-${{ hashFiles('phpstan.neon*') }}-${{ hashFiles('**/*.php') }}
45+
restore-keys: |
46+
${{ runner.os }}-phpstan-${{ matrix.php-version }}-${{ hashFiles('phpstan.neon*') }}-
47+
${{ runner.os }}-phpstan-${{ matrix.php-version }}-
48+
49+
- name: Run PHPStan
50+
run: |
51+
if [ -f "phpstan.neon" ] || [ -f "phpstan.neon.dist" ]; then
52+
vendor/bin/phpstan analyse --memory-limit=1G
53+
else
54+
vendor/bin/phpstan analyse src tests --memory-limit=1G
55+
fi
56+
57+
- name: Upload PHPStan results
58+
if: failure()
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: phpstan-results-php-${{ matrix.php-version }}
62+
path: |
63+
phpstan-report.json
64+
/tmp/phpstan

.github/workflows/lint.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
name: Lint
3+
4+
on:
5+
push:
6+
7+
jobs:
8+
yaml-lint:
9+
name: YAML Lint
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Run yamllint
17+
uses: ibiqlik/action-yamllint@v3
18+
with:
19+
file_or_dir: .github/
20+
config_file: .yamllint.yml
21+
strict: true
22+
23+
json-lint:
24+
name: JSON Lint
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Validate JSON files
32+
run: |
33+
echo "Validating JSON files..."
34+
find . -name "*.json" -not -path "./vendor/*" -not -path "./node_modules/*" | while read -r file; do
35+
echo "Validating $file"
36+
if ! python3 -m json.tool "$file" > /dev/null; then
37+
echo "❌ Invalid JSON: $file"
38+
exit 1
39+
else
40+
echo "✅ Valid JSON: $file"
41+
fi
42+
done
43+
echo "All JSON files are valid!"
44+
45+
markdown-lint:
46+
name: Markdown Lint
47+
runs-on: ubuntu-latest
48+
49+
steps:
50+
- name: Checkout code
51+
uses: actions/checkout@v4
52+
53+
- name: Run markdownlint
54+
uses: DavidAnson/markdownlint-cli2-action@v16
55+
with:
56+
globs: '**/*.md'
57+
58+

0 commit comments

Comments
 (0)