test: Phase 3 添加 smoke test、CI 与 run-daily 去重锁
离线 mock 测试 generate 产出,GitHub Actions 跑 pytest,30 分钟内重复调度自动 skip。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,16 +3,21 @@
|
||||
# .\run-daily.ps1
|
||||
# .\run-daily.ps1 -SkipPush
|
||||
# .\run-daily.ps1 -SkipGenerate
|
||||
# .\run-daily.ps1 -Force # bypass duplicate-run lock
|
||||
|
||||
param(
|
||||
[switch]$SkipPush,
|
||||
[switch]$SkipGenerate
|
||||
[switch]$SkipGenerate,
|
||||
[switch]$Force
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
Set-Location $Root
|
||||
|
||||
$LockFile = Join-Path $Root ".cache\run-daily.lock"
|
||||
$LockMaxMinutes = 30
|
||||
|
||||
function Import-DotEnvFile {
|
||||
param([string]$Path)
|
||||
if (-not (Test-Path $Path)) { return }
|
||||
@@ -29,30 +34,61 @@ function Import-DotEnvFile {
|
||||
}
|
||||
}
|
||||
|
||||
Import-DotEnvFile (Join-Path $Root ".env")
|
||||
Import-DotEnvFile (Join-Path $Root ".env.local")
|
||||
function Test-RunDailyLock {
|
||||
if (-not (Test-Path $LockFile)) { return $false }
|
||||
$age = (Get-Date) - (Get-Item $LockFile).LastWriteTime
|
||||
return $age.TotalMinutes -lt $LockMaxMinutes
|
||||
}
|
||||
|
||||
$python = "python"
|
||||
$date = Get-Date -Format "yyyy-MM-dd"
|
||||
$reportWecom = Join-Path $Root "output\$date.wecom.md"
|
||||
function Set-RunDailyLock {
|
||||
$dir = Split-Path $LockFile -Parent
|
||||
if (-not (Test-Path $dir)) {
|
||||
New-Item -ItemType Directory -Path $dir -Force | Out-Null
|
||||
}
|
||||
Set-Content -Path $LockFile -Value (Get-Date -Format "o") -Encoding UTF8
|
||||
}
|
||||
|
||||
if (-not $SkipGenerate) {
|
||||
Write-Host "Generating daily report: $date"
|
||||
& $python -m daily generate
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "daily generate failed with exit code $LASTEXITCODE"
|
||||
function Clear-RunDailyLock {
|
||||
if (Test-Path $LockFile) {
|
||||
Remove-Item $LockFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $SkipPush) {
|
||||
if (-not (Test-Path $reportWecom)) {
|
||||
throw "Report not found: $reportWecom"
|
||||
}
|
||||
Write-Host "Pushing to WeCom webhook..."
|
||||
& $python -m daily push $reportWecom
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "daily push failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
if (-not $Force -and (Test-RunDailyLock)) {
|
||||
Write-Host "Skip: run-daily already ran within ${LockMaxMinutes} minutes (lock: $LockFile). Use -Force to override."
|
||||
exit 0
|
||||
}
|
||||
|
||||
Write-Host "Done: $date"
|
||||
Set-RunDailyLock
|
||||
try {
|
||||
Import-DotEnvFile (Join-Path $Root ".env")
|
||||
Import-DotEnvFile (Join-Path $Root ".env.local")
|
||||
|
||||
$python = "python"
|
||||
$date = Get-Date -Format "yyyy-MM-dd"
|
||||
$reportWecom = Join-Path $Root "output\$date.wecom.md"
|
||||
|
||||
if (-not $SkipGenerate) {
|
||||
Write-Host "Generating daily report: $date"
|
||||
& $python -m daily generate
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "daily generate failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $SkipPush) {
|
||||
if (-not (Test-Path $reportWecom)) {
|
||||
throw "Report not found: $reportWecom"
|
||||
}
|
||||
Write-Host "Pushing to WeCom webhook..."
|
||||
& $python -m daily push $reportWecom
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "daily push failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Done: $date"
|
||||
}
|
||||
finally {
|
||||
Clear-RunDailyLock
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user