feat:setup CI/CD for SIG TPS Nganjuk

This commit is contained in:
Lutfi Hakim 2026-03-12 11:07:54 +07:00
parent 0671fdcbf8
commit 1aba739e67
1 changed files with 44 additions and 0 deletions

44
.github/workflows/deploy.yml vendored Normal file
View File

@ -0,0 +1,44 @@
name: Auto Deploy SIG TPS Nganjuk
on:
push:
branches:
- main
jobs:
deploy:
runs-on: self-hosted
steps:
- name: Deployment Logic SIG TPS Nganjuk
run: |
cd /www/wwwroot/sig-tps
# 1. Ambil ID commit lama untuk deteksi perubahan
OLD_COMMIT=$(git rev-parse HEAD)
# 2. Tarik kode terbaru
git fetch --all
git reset --hard origin/master
# 3. Ambil ID commit baru
NEW_COMMIT=$(git rev-parse HEAD)
# 4. Build dependencies (Container temporary)
docker run --rm -v $(pwd):/app -w /app composer:2 install --no-interaction --prefer-dist --optimize-autoloader --ignore-platform-reqs
# 5. Perbaikan permission untuk user www/docker (PUID 33)
# Sekalian fix untuk storage dan cache biar aman
chown -R 33:33 vendor/ storage/ bootstrap/cache/
chmod -R 775 storage/ bootstrap/cache/
# 6. Refresh cache Laravel
docker compose exec -T sig_php php artisan optimize:clear
# 7. Deteksi otomatis migrasi database
if [ "$OLD_COMMIT" != "$NEW_COMMIT" ] && git diff --name-only $OLD_COMMIT $NEW_COMMIT | grep -q "^database/migrations/"; then
echo "🚀 Perubahan database terdeteksi! Menjalankan migrate..."
docker compose exec -T sig_php php artisan migrate --force
else
echo "✅ Tidak ada file migrasi baru. Skip migrate."
fi