tambah webhook

This commit is contained in:
Saufi
2026-05-22 21:57:33 +08:00
parent f2f0a2405f
commit c5b5e6069d
3 changed files with 213 additions and 0 deletions

77
scripts/deploy.ps1 Normal file
View File

@@ -0,0 +1,77 @@
# =============================================================================
# Deploy Script — myEventPostMortem (Laravel)
# Windows Server 2019
#
# Dipanggil oleh public/webhook.php apabila Gitea push event diterima.
# Pastikan user yang menjalankan IIS/PHP ada akses ke git, composer, npm, php.
# =============================================================================
$AppRoot = Split-Path -Parent $PSScriptRoot
$ErrorActionPreference = "Stop"
function Write-Log {
param([string]$Message)
$ts = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Write-Output "[$ts] $Message"
}
function Invoke-Step {
param([string]$Label, [scriptblock]$Action)
Write-Log ">>> $Label"
& $Action
if ($LASTEXITCODE -ne 0) {
throw "$Label gagal dengan exit code $LASTEXITCODE"
}
}
# ── Masuk ke direktori aplikasi ──────────────────────────────────────────────
Set-Location $AppRoot
Write-Log "=== Deployment Bermula ==="
Write-Log "App Root : $AppRoot"
Write-Log "User : $env:USERNAME"
Write-Log "Masa : $(Get-Date)"
# ── Git pull ─────────────────────────────────────────────────────────────────
Invoke-Step "Git pull" {
git pull origin master
}
# ── Composer install ─────────────────────────────────────────────────────────
Invoke-Step "Composer install" {
composer install --no-dev --optimize-autoloader --no-interaction --no-progress
}
# ── NPM install & build ──────────────────────────────────────────────────────
Invoke-Step "NPM install" {
npm ci --prefer-offline
}
Invoke-Step "NPM build" {
npm run build
}
# ── Laravel: cache config & migrate ─────────────────────────────────────────
Invoke-Step "Artisan down (maintenance mode)" {
php artisan down --retry=10
}
try {
Invoke-Step "Database migrate" {
php artisan migrate --force
}
Invoke-Step "Optimize Laravel" {
php artisan optimize
}
Invoke-Step "Queue restart" {
php artisan queue:restart
}
}
finally {
# Pastikan aplikasi dibuka semula walaupun ada ralat
Write-Log ">>> Artisan up"
php artisan up
}
Write-Log "=== Deployment Berjaya ==="