Skip to content

Commit d43d8de

Browse files
authored
Merge pull request #5 from mubbi/feature/ci-github-action
ci(updated ci action): added linter, code analysis, unit tests
2 parents 2c22766 + 88642ea commit d43d8de

File tree

1 file changed

+158
-0
lines changed

1 file changed

+158
-0
lines changed

.github/workflows/ci.yml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,161 @@ jobs:
2929
run: |
3030
# Validate all commits in the PR
3131
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
32+
33+
lint:
34+
runs-on: ubuntu-latest
35+
needs: validate-commits
36+
if: always() && (needs.validate-commits.result == 'success' || needs.validate-commits.result == 'skipped')
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v4
40+
41+
- name: Setup PHP
42+
uses: shivammathur/setup-php@v2
43+
with:
44+
php-version: '8.2'
45+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
46+
coverage: none
47+
48+
- name: Cache Composer packages
49+
id: composer-cache
50+
uses: actions/cache@v4
51+
with:
52+
path: vendor
53+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
54+
restore-keys: |
55+
${{ runner.os }}-php-
56+
57+
- name: Install Composer dependencies
58+
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader
59+
60+
- name: Run Laravel Pint
61+
uses: aglipanci/[email protected]
62+
with:
63+
preset: laravel
64+
verboseMode: true
65+
66+
analyze:
67+
runs-on: ubuntu-latest
68+
needs: lint
69+
steps:
70+
- name: Checkout
71+
uses: actions/checkout@v4
72+
73+
- name: Setup PHP
74+
uses: shivammathur/setup-php@v2
75+
with:
76+
php-version: '8.2'
77+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
78+
coverage: none
79+
80+
- name: Cache Composer packages
81+
id: composer-cache
82+
uses: actions/cache@v4
83+
with:
84+
path: vendor
85+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
86+
restore-keys: |
87+
${{ runner.os }}-php-
88+
89+
- name: Install Composer dependencies
90+
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader
91+
92+
- name: Copy environment file
93+
run: cp .env.docker.example .env
94+
95+
- name: Generate application key
96+
run: php artisan key:generate
97+
98+
- name: Run Larastan (PHPStan)
99+
run: ./vendor/bin/phpstan analyse --memory-limit=2G --error-format=github
100+
101+
test:
102+
runs-on: ubuntu-latest
103+
needs: analyze
104+
105+
services:
106+
mysql:
107+
image: mysql:8.0
108+
env:
109+
MYSQL_ROOT_PASSWORD: root
110+
MYSQL_DATABASE: laravel_blog_test
111+
ports:
112+
- 3306:3306
113+
options: --health-cmd="mysqladmin ping -h localhost -u root -proot" --health-interval=10s --health-timeout=5s --health-retries=5
114+
115+
redis:
116+
image: redis:7-alpine
117+
ports:
118+
- 6379:6379
119+
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=3
120+
121+
steps:
122+
- name: Checkout
123+
uses: actions/checkout@v4
124+
125+
- name: Setup PHP
126+
uses: shivammathur/setup-php@v2
127+
with:
128+
php-version: '8.2'
129+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
130+
coverage: xdebug
131+
132+
- name: Cache Composer packages
133+
id: composer-cache
134+
uses: actions/cache@v4
135+
with:
136+
path: vendor
137+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
138+
restore-keys: |
139+
${{ runner.os }}-php-
140+
141+
- name: Install Composer dependencies
142+
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader
143+
144+
- name: Copy environment file
145+
run: cp .env.docker.example .env
146+
147+
- name: Generate application key
148+
run: php artisan key:generate
149+
150+
- name: Set testing environment variables
151+
run: |
152+
echo "APP_ENV=testing" >> .env
153+
echo "DB_CONNECTION=mysql" >> .env
154+
echo "DB_HOST=127.0.0.1" >> .env
155+
echo "DB_PORT=3306" >> .env
156+
echo "DB_DATABASE=laravel_blog_test" >> .env
157+
echo "DB_USERNAME=root" >> .env
158+
echo "DB_PASSWORD=root" >> .env
159+
echo "CACHE_STORE=array" >> .env
160+
echo "SESSION_DRIVER=array" >> .env
161+
echo "QUEUE_CONNECTION=sync" >> .env
162+
163+
- name: Wait for MySQL to be ready
164+
run: |
165+
for i in {1..60}; do
166+
if mysqladmin ping -h 127.0.0.1 -P 3306 -u root -proot --silent; then
167+
echo "MySQL is ready"
168+
# Verify the database exists
169+
mysql -h 127.0.0.1 -P 3306 -u root -proot -e "SHOW DATABASES;" | grep laravel_blog_test || exit 1
170+
echo "Database laravel_blog_test confirmed"
171+
break
172+
fi
173+
echo "Waiting for MySQL... ($i/60)"
174+
sleep 3
175+
done
176+
if [ $i -eq 60 ]; then
177+
echo "MySQL failed to start within 3 minutes"
178+
exit 1
179+
fi
180+
181+
- name: Run database migrations
182+
run: php artisan migrate:fresh --seed --env=testing --force
183+
184+
- name: Run tests with Pest (parallel)
185+
env:
186+
DB_HOST: 127.0.0.1
187+
DB_USERNAME: root
188+
DB_PASSWORD: root
189+
run: php artisan test --parallel --recreate-databases --stop-on-failure

0 commit comments

Comments
 (0)