Skip to content

Commit d39bc5f

Browse files
committed
github actions para code style y calidad de codigo
1 parent 5c90e10 commit d39bc5f

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Style & Static Analysis
2+
3+
on:
4+
pull_request:
5+
branches: [ develop, main ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
style_static:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: read
14+
pull-requests: read
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: '8.1'
26+
coverage: none
27+
tools: composer:v2
28+
29+
- name: Cache Composer
30+
uses: actions/cache@v4
31+
with:
32+
path: |
33+
~/.composer/cache
34+
vendor
35+
key: ${{ runner.os }}-php81-composer-${{ hashFiles('**/composer.lock') }}
36+
restore-keys: |
37+
${{ runner.os }}-php81-composer-
38+
39+
- name: Install dependencies
40+
run: |
41+
composer install --no-interaction --prefer-dist --no-progress
42+
43+
# ------- Detect changed files in the PR -------
44+
- name: Detectar archivos PHP modificados
45+
id: changed
46+
run: |
47+
# Base ref of the PR (e.g., develop/main)
48+
echo "BASE_REF=${{ github.base_ref }}" >> $GITHUB_OUTPUT
49+
# List of changed files vs base
50+
git fetch origin ${{ github.base_ref }} --depth=1
51+
git diff --name-only origin/${{ github.base_ref }}...HEAD > all_changed.txt
52+
# PHP files only
53+
grep -E '\.php$' all_changed.txt > changed_php.txt || true
54+
# Config files that force full analysis
55+
grep -E '(^|/)(phpstan(\.neon|\.neon\.dist)?|composer\.json|composer\.lock)$' all_changed.txt && echo "force_full=1" >> $GITHUB_OUTPUT || echo "force_full=0" >> $GITHUB_OUTPUT
56+
# For visibility
57+
echo "Changed PHP files:"
58+
cat changed_php.txt || true
59+
60+
# ------- Run Pint on changed PHP files -------
61+
- name: Ejecutar Laravel Pint a los archivos PHP modificados
62+
run: |
63+
if [ -s changed_php.txt ]; then
64+
# Use --test to fail if formatting is off (no auto-fix in CI)
65+
xargs -a changed_php.txt vendor/bin/pint --test
66+
else
67+
echo "No PHP files changed; skipping Pint."
68+
fi
69+
70+
# ------- Run PHPStan (smart: full or changed) -------
71+
- name: Ejecutar PHPStan
72+
env:
73+
FORCE_FULL: ${{ steps.changed.outputs.force_full }}
74+
run: |
75+
set -e
76+
# Default args: GitHub-friendly output; adjust level/config as needed
77+
PHPSTAN_ARGS="--error-format=github"
78+
79+
if [ "$FORCE_FULL" = "1" ]; then
80+
echo "Config/composer changed → running FULL PHPStan analysis."
81+
vendor/bin/phpstan analyse $PHPSTAN_ARGS
82+
exit $?
83+
fi
84+
85+
if [ -s changed_php.txt ]; then
86+
echo "Running PHPStan on changed PHP files."
87+
# Some shells limit arg length; feed via xargs safely
88+
xargs -a changed_php.txt vendor/bin/phpstan analyse $PHPSTAN_ARGS
89+
else
90+
echo "No PHP files changed; running a minimal bootstrap check to ensure config is valid."
91+
# Tiny fallback (fast) – analyse a common directory. Adjust if needed.
92+
vendor/bin/phpstan analyse app $PHPSTAN_ARGS || true
93+
fi

0 commit comments

Comments
 (0)