From 1aba739e67217304c8db21a341b65a5ea9e55cfb Mon Sep 17 00:00:00 2001 From: Lutfi Hakim Date: Thu, 12 Mar 2026 11:07:54 +0700 Subject: [PATCH] feat:setup CI/CD for SIG TPS Nganjuk --- .github/workflows/deploy.yml | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..7973d21 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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