From 995aab004d75475fcea620c78ba7780237e39f24 Mon Sep 17 00:00:00 2001 From: Lutfi Hakim Date: Sun, 12 Apr 2026 11:12:07 +0700 Subject: [PATCH] add CI CD setup --- .github/workflows/deploy.yml | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 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..a1affb8 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,46 @@ +name: Auto Deploy Mancontani + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: self-hosted + + steps: + - name: Deployment Logic Mancontani + run: | + cd /www/wwwroot/mancontani + + # 1. Ambil ID commit lama untuk deteksi perubahan + OLD_COMMIT=$(git rev-parse HEAD) + + # 2. Tarik kode terbaru + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/sayasilvi/web-pertanian.git + git fetch -4 --all + git reset --hard origin/main + + # 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 + # REVISI: Menggunakan docker exec langsung ke nama container yang sedang jalan + docker exec mancontani-php-container 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 exec mancontani-php-container php artisan migrate --force + else + echo "✅ Tidak ada file migrasi baru. Skip migrate." + fi