Skip to content

Commit a07637b

Browse files
committed
Harden daily token close script for CI environments
1 parent ebfd520 commit a07637b

2 files changed

Lines changed: 68 additions & 2 deletions

File tree

.github/scripts/token-daily-close.ps1

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,44 @@ Set-Location $root
1111

1212
$jsonLog = '.github/reports/token-usage-history.json'
1313

14-
powershell -ExecutionPolicy Bypass -File .github/scripts/token-usage-report.ps1 `
14+
function Get-LatestCopilotTranscript {
15+
$roots = @()
16+
17+
if (-not [string]::IsNullOrWhiteSpace($env:APPDATA)) {
18+
$roots += (Join-Path $env:APPDATA 'Code\User\workspaceStorage')
19+
}
20+
if (-not [string]::IsNullOrWhiteSpace($env:HOME)) {
21+
$roots += (Join-Path $env:HOME '.config/Code/User/workspaceStorage')
22+
}
23+
24+
$roots = @($roots | Where-Object { -not [string]::IsNullOrWhiteSpace($_) -and (Test-Path $_) } | Select-Object -Unique)
25+
foreach ($workspaceRoot in $roots) {
26+
$latest = Get-ChildItem -Path $workspaceRoot -Recurse -File -Filter '*.jsonl' -ErrorAction SilentlyContinue |
27+
Where-Object { $_.FullName -match 'GitHub\.copilot-chat[\\/]transcripts' } |
28+
Sort-Object LastWriteTime -Descending |
29+
Select-Object -First 1
30+
31+
if ($latest) {
32+
return $latest.FullName
33+
}
34+
}
35+
36+
return $null
37+
}
38+
39+
$transcriptPath = Get-LatestCopilotTranscript
40+
if (-not $transcriptPath) {
41+
Write-Output 'No Copilot transcript found. Skipping daily token close without failing.'
42+
exit 0
43+
}
44+
45+
& .github/scripts/token-usage-report.ps1 `
46+
-TranscriptPath $transcriptPath `
1547
-IncludeDebugLogs `
1648
-JsonPath $jsonLog `
1749
-AppendHistory `
1850
-AppendDailyAggregateMarkdown `
51+
-DailyCloseMode `
1952
-DailyAggregateMdPath ".github/reports/token-usage-daily-aggregate.md" `
2053
-ModelName $ModelName `
2154
-InputCostPer1M $InputCostPer1M `

plugins/boostdba/.github/scripts/token-daily-close.ps1

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,44 @@ Set-Location $root
1111

1212
$jsonLog = '.github/reports/token-usage-history.json'
1313

14-
powershell -ExecutionPolicy Bypass -File .github/scripts/token-usage-report.ps1 `
14+
function Get-LatestCopilotTranscript {
15+
$roots = @()
16+
17+
if (-not [string]::IsNullOrWhiteSpace($env:APPDATA)) {
18+
$roots += (Join-Path $env:APPDATA 'Code\User\workspaceStorage')
19+
}
20+
if (-not [string]::IsNullOrWhiteSpace($env:HOME)) {
21+
$roots += (Join-Path $env:HOME '.config/Code/User/workspaceStorage')
22+
}
23+
24+
$roots = @($roots | Where-Object { -not [string]::IsNullOrWhiteSpace($_) -and (Test-Path $_) } | Select-Object -Unique)
25+
foreach ($workspaceRoot in $roots) {
26+
$latest = Get-ChildItem -Path $workspaceRoot -Recurse -File -Filter '*.jsonl' -ErrorAction SilentlyContinue |
27+
Where-Object { $_.FullName -match 'GitHub\.copilot-chat[\\/]transcripts' } |
28+
Sort-Object LastWriteTime -Descending |
29+
Select-Object -First 1
30+
31+
if ($latest) {
32+
return $latest.FullName
33+
}
34+
}
35+
36+
return $null
37+
}
38+
39+
$transcriptPath = Get-LatestCopilotTranscript
40+
if (-not $transcriptPath) {
41+
Write-Output 'No Copilot transcript found. Skipping daily token close without failing.'
42+
exit 0
43+
}
44+
45+
& .github/scripts/token-usage-report.ps1 `
46+
-TranscriptPath $transcriptPath `
1547
-IncludeDebugLogs `
1648
-JsonPath $jsonLog `
1749
-AppendHistory `
1850
-AppendDailyAggregateMarkdown `
51+
-DailyCloseMode `
1952
-DailyAggregateMdPath ".github/reports/token-usage-daily-aggregate.md" `
2053
-ModelName $ModelName `
2154
-InputCostPer1M $InputCostPer1M `

0 commit comments

Comments
 (0)