-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwindows_fetch_github_workflow_logs.ps1
More file actions
35 lines (27 loc) · 1.07 KB
/
Copy pathwindows_fetch_github_workflow_logs.ps1
File metadata and controls
35 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Install GitHub CLI
winget install --id GitHub.cli
# Authenticate
gh auth login
# Replace with your repo info
OWNER="your-org-or-username"
REPO="your-repo"
SINCE="2025-03-01T00:00:00Z"
# GitHub token from gh (must be authenticated)
$token = (gh auth token)
# Create logs directory
New-Item -ItemType Directory -Force -Path $LogFolder | Out-Null
# Fetch workflow runs
$workflowRunsJson = gh api "repos/$Owner/$Repo/actions/runs?per_page=100" --paginate
$workflowRuns = ($workflowRunsJson -join "`n" | ConvertFrom-Json).workflow_runs
foreach ($run in $workflowRuns) {
$createdAt = Get-Date $run.created_at
if ($createdAt -ge $Since) {
$runId = $run.id
$logUrl = "https://api.github.com/repos/$Owner/$Repo/actions/runs/$runId/logs"
$zipPath = Join-Path $LogFolder "logs_$runId.zip"
Write-Host "Downloading logs for run $runId ($createdAt)..."
Invoke-WebRequest -Uri $logUrl `
-Headers @{ Authorization = "Bearer $token"; Accept = "application/vnd.github+json" } `
-OutFile $zipPath
}
}