Skip to content

Commit 7bf4c79

Browse files
committed
T3: CI guardrail GitHub Actions (PHP 8.2/8.3 + MySQL + phpunit)
- .github/workflows/ci.yml: matrix PHP 8.2/8.3, service MySQL 8, cache composer - set DB creds ke .env (phpunit.xml cuma override DB_DATABASE) - pakai phpunit langsung + flag memory (artisan test OOM) - Tervalidasi lokal: migrate:fresh absensi_testing + 403/403 phpunit hijau
1 parent e425922 commit 7bf4c79

2 files changed

Lines changed: 113 additions & 14 deletions

File tree

.github/workflows/ci.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master, "upgrade/**" ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
phpunit:
11+
name: PHPUnit (PHP ${{ matrix.php }})
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php: ['8.2', '8.3']
18+
19+
services:
20+
mysql:
21+
image: mysql:8.0
22+
env:
23+
MYSQL_ROOT_PASSWORD: secret
24+
MYSQL_DATABASE: absensi_testing
25+
ports:
26+
- 3306:3306
27+
options: >-
28+
--health-cmd="mysqladmin ping -h 127.0.0.1 -u root --password=secret"
29+
--health-interval=10s
30+
--health-timeout=5s
31+
--health-retries=10
32+
33+
env:
34+
DB_CONNECTION: mysql
35+
DB_HOST: 127.0.0.1
36+
DB_PORT: 3306
37+
DB_DATABASE: absensi_testing
38+
DB_USERNAME: root
39+
DB_PASSWORD: secret
40+
41+
steps:
42+
- uses: actions/checkout@v4
43+
44+
- name: Setup PHP
45+
uses: shivammathur/setup-php@v2
46+
with:
47+
php-version: ${{ matrix.php }}
48+
extensions: mbstring, pdo_mysql, bcmath, gd, zip, intl, exif
49+
coverage: none
50+
tools: composer:v2
51+
52+
- name: Cache Composer packages
53+
uses: actions/cache@v4
54+
with:
55+
path: vendor
56+
key: composer-${{ matrix.php }}-${{ hashFiles('composer.lock') }}
57+
restore-keys: composer-${{ matrix.php }}-
58+
59+
- name: Install dependencies
60+
run: composer install --no-interaction --prefer-dist --no-progress
61+
62+
- name: Prepare environment
63+
run: |
64+
cp .env.example .env
65+
php artisan key:generate
66+
# phpunit.xml hanya override DB_DATABASE; host/port/user/password diambil
67+
# dari .env — set eksplisit agar cocok dengan MySQL service di atas.
68+
sed -i 's/^DB_HOST=.*/DB_HOST=127.0.0.1/' .env
69+
sed -i 's/^DB_PORT=.*/DB_PORT=3306/' .env
70+
sed -i 's/^DB_DATABASE=.*/DB_DATABASE=absensi_testing/' .env
71+
sed -i 's/^DB_USERNAME=.*/DB_USERNAME=root/' .env
72+
sed -i 's/^DB_PASSWORD=.*/DB_PASSWORD=secret/' .env
73+
74+
- name: Wait for MySQL
75+
run: |
76+
for i in $(seq 1 30); do
77+
if mysqladmin ping -h 127.0.0.1 -u root --password=secret --silent; then
78+
echo "MySQL is up"; break
79+
fi
80+
echo "waiting for mysql... ($i)"; sleep 2
81+
done
82+
83+
- name: Run migrations
84+
run: php artisan migrate --force --database=mysql
85+
env:
86+
DB_DATABASE: absensi_testing
87+
88+
- name: Run PHPUnit
89+
# artisan test OOM di app ini (render menu) — pakai phpunit langsung + flag memory.
90+
run: php -d memory_limit=2G -d xdebug.mode=off vendor/bin/phpunit --no-coverage
Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
# T3 — CI Guardrail (GitHub Actions)
22

3-
**Status:** [ ] TODO · Estimasi: 1–2 hari
3+
**Status:** [x] DONE · commit: `(uncommitted)` · Estimasi: 1–2 hari**aktual ~20 menit**
44
**Tujuan:** kunci hasil upgrade supaya tak diam-diam regres; jalankan test tiap PR.
55

6-
## Langkah
7-
- [ ] Buat `.github/workflows/ci.yml`:
8-
- Service MySQL 8 (port 3307 / atau default + env)
9-
- Matrix PHP: `8.2`, `8.3`
10-
- `composer install`
11-
- `php artisan migrate --force` ke `absensi_testing`
12-
- Jalankan `phpunit` dgn flag memory (bukan `artisan test` — OOM)
13-
- (Opsional job kedua) `php artisan serve` + Playwright `crud-suite.mjs`/`ui-test.mjs`
14-
- [ ] Cache composer & node_modules untuk kecepatan
15-
- [ ] Badge status CI di README (ganti/temani badge "tests 403 passing" statis)
6+
## Yang dikerjakan
7+
- [x] `.github/workflows/ci.yml`:
8+
- Trigger: push ke `master`/`upgrade/**`, PR ke `master`
9+
- Service **MySQL 8.0** (db `absensi_testing`, root/secret, health-check)
10+
- Matrix **PHP 8.2 & 8.3** (setup-php + ekstensi mbstring/pdo_mysql/bcmath/gd/zip/intl/exif)
11+
- Cache Composer (vendor by composer.lock hash)
12+
- `composer install``key:generate` → set DB creds ke `.env` (phpunit.xml hanya
13+
override DB_DATABASE; host/port/user/pass diambil dari `.env`)
14+
- `php artisan migrate --force`
15+
- **`php -d memory_limit=2G -d xdebug.mode=off vendor/bin/phpunit --no-coverage`**
16+
(bukan `artisan test` — OOM di app ini)
17+
18+
## Validasi lokal (bukti CI akan hijau)
19+
- [x] `CREATE DATABASE absensi_testing` + `migrate:fresh --force` → semua migrasi DONE
20+
(termasuk training/ter/salary-breakdown terbaru)
21+
- [x] PHPUnit penuh **403/403 hijau**
22+
23+
## Sisa (manual, butuh akses GitHub)
24+
- [ ] Push branch → cek run Actions hijau di PHP 8.2 & 8.3
25+
- [ ] Tambah badge CI ke README (ganti/temani badge "tests 403 passing" statis)
1626
- [ ] Branch protection `master`: wajib CI hijau sebelum merge
1727

1828
## Kriteria selesai
19-
- PR memicu CI otomatis, phpunit hijau di PHP 8.2 & 8.3
20-
- Badge CI tampil di README
21-
- Merge ke master butuh CI lulus
29+
- [x] Workflow ditulis + tervalidasi lokal (migrate + phpunit hijau)
30+
- [~] Run Actions nyata + badge + branch protection → saat push ke GitHub (F4)

0 commit comments

Comments
 (0)