|
| 1 | +#!/usr/bin/env pwsh |
| 2 | +# Verify that generated files contain current dates (not stale [DATE] placeholders) |
| 3 | +# Usage: verify-dates.ps1 [-FeaturePath <path>] |
| 4 | +# verify-dates.ps1 # Checks current feature based on branch |
| 5 | +# verify-dates.ps1 -FeaturePath specs/001-feature # Checks specific feature directory |
| 6 | + |
| 7 | +[CmdletBinding()] |
| 8 | +param( |
| 9 | + [Parameter(Position = 0)] |
| 10 | + [string]$FeaturePath |
| 11 | +) |
| 12 | + |
| 13 | +$ErrorActionPreference = 'Stop' |
| 14 | + |
| 15 | +# Resolve repository root |
| 16 | +function Find-RepositoryRoot { |
| 17 | + param( |
| 18 | + [string]$StartDir, |
| 19 | + [string[]]$Markers = @('.git', '.specify') |
| 20 | + ) |
| 21 | + $current = Resolve-Path $StartDir |
| 22 | + while ($true) { |
| 23 | + foreach ($marker in $Markers) { |
| 24 | + if (Test-Path (Join-Path $current $marker)) { |
| 25 | + return $current |
| 26 | + } |
| 27 | + } |
| 28 | + $parent = Split-Path $current -Parent |
| 29 | + if ($parent -eq $current) { |
| 30 | + return $null |
| 31 | + } |
| 32 | + $current = $parent |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +# Determine repo root |
| 37 | +try { |
| 38 | + $repoRoot = git rev-parse --show-toplevel 2>$null |
| 39 | + if ($LASTEXITCODE -ne 0) { |
| 40 | + throw "Git not available" |
| 41 | + } |
| 42 | +} catch { |
| 43 | + $repoRoot = Find-RepositoryRoot -StartDir $PSScriptRoot |
| 44 | + if (-not $repoRoot) { |
| 45 | + Write-Error "Error: Could not determine repository root." |
| 46 | + exit 1 |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +# Determine feature directory |
| 51 | +if ($FeaturePath) { |
| 52 | + if ([System.IO.Path]::IsPathRooted($FeaturePath)) { |
| 53 | + $featureDir = $FeaturePath |
| 54 | + } else { |
| 55 | + $featureDir = Join-Path $repoRoot $FeaturePath |
| 56 | + } |
| 57 | +} else { |
| 58 | + # Auto-detect from current branch or SPECIFY_FEATURE env var |
| 59 | + if ($env:SPECIFY_FEATURE) { |
| 60 | + $featureDir = Join-Path $repoRoot "specs/$($env:SPECIFY_FEATURE)" |
| 61 | + } else { |
| 62 | + try { |
| 63 | + $branch = git rev-parse --abbrev-ref HEAD 2>$null |
| 64 | + if ($LASTEXITCODE -eq 0 -and $branch) { |
| 65 | + $featureDir = Join-Path $repoRoot "specs/$branch" |
| 66 | + } else { |
| 67 | + throw "Could not determine branch" |
| 68 | + } |
| 69 | + } catch { |
| 70 | + Write-Error "Error: Could not determine feature directory. Please provide a path." |
| 71 | + exit 1 |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +if (-not (Test-Path $featureDir -PathType Container)) { |
| 77 | + Write-Error "Error: Feature directory not found: $featureDir" |
| 78 | + exit 1 |
| 79 | +} |
| 80 | + |
| 81 | +# Get current date in ISO format |
| 82 | +$currentDate = Get-Date -Format "yyyy-MM-dd" |
| 83 | +$currentYear = (Get-Date).Year |
| 84 | + |
| 85 | +# Track issues found |
| 86 | +$issuesFound = 0 |
| 87 | +$filesChecked = 0 |
| 88 | + |
| 89 | +Write-Host "==============================================" |
| 90 | +Write-Host "Date Verification Report" |
| 91 | +Write-Host "==============================================" |
| 92 | +Write-Host "Feature Directory: $featureDir" |
| 93 | +Write-Host "Current Date: $currentDate" |
| 94 | +Write-Host "==============================================" |
| 95 | +Write-Host "" |
| 96 | + |
| 97 | +# Function to check a file for date issues |
| 98 | +function Test-FileDate { |
| 99 | + param([string]$FilePath) |
| 100 | + |
| 101 | + $fileName = Split-Path $FilePath -Leaf |
| 102 | + |
| 103 | + if (-not (Test-Path $FilePath)) { |
| 104 | + return 0 |
| 105 | + } |
| 106 | + |
| 107 | + $script:filesChecked++ |
| 108 | + |
| 109 | + $content = Get-Content -Path $FilePath -Raw |
| 110 | + |
| 111 | + # Check for remaining [DATE] placeholders |
| 112 | + if ($content -match '\[DATE\]') { |
| 113 | + Write-Host "X FAIL: $fileName contains unresolved [DATE] placeholder" -ForegroundColor Red |
| 114 | + $script:issuesFound++ |
| 115 | + return 1 |
| 116 | + } |
| 117 | + |
| 118 | + # Check if file contains any date in ISO format |
| 119 | + if ($content -match '(\d{4})-(\d{2})-(\d{2})') { |
| 120 | + $foundDate = $Matches[0] |
| 121 | + $foundYear = [int]$Matches[1] |
| 122 | + |
| 123 | + # Check if date is in the future (more than current year) - likely incorrect |
| 124 | + if ($foundYear -gt $currentYear) { |
| 125 | + Write-Host "! WARN: $fileName contains future date: $foundDate" -ForegroundColor Yellow |
| 126 | + $script:issuesFound++ |
| 127 | + return 1 |
| 128 | + } |
| 129 | + |
| 130 | + # Check if date matches current date (ideal case) |
| 131 | + if ($foundDate -eq $currentDate) { |
| 132 | + Write-Host "V PASS: $fileName has current date ($foundDate)" -ForegroundColor Green |
| 133 | + } else { |
| 134 | + Write-Host "i INFO: $fileName has date: $foundDate (not today, but valid)" -ForegroundColor Cyan |
| 135 | + } |
| 136 | + } else { |
| 137 | + Write-Host "i INFO: $fileName has no ISO date (may be okay depending on template)" -ForegroundColor Cyan |
| 138 | + } |
| 139 | + |
| 140 | + return 0 |
| 141 | +} |
| 142 | + |
| 143 | +Write-Host "Checking files..." |
| 144 | +Write-Host "" |
| 145 | + |
| 146 | +# Check all relevant files |
| 147 | +Test-FileDate -FilePath (Join-Path $featureDir "spec.md") | Out-Null |
| 148 | +Test-FileDate -FilePath (Join-Path $featureDir "plan.md") | Out-Null |
| 149 | +Test-FileDate -FilePath (Join-Path $featureDir "context.md") | Out-Null |
| 150 | +Test-FileDate -FilePath (Join-Path $featureDir "tasks.md") | Out-Null |
| 151 | +Test-FileDate -FilePath (Join-Path $featureDir "checklist.md") | Out-Null |
| 152 | + |
| 153 | +Write-Host "" |
| 154 | +Write-Host "==============================================" |
| 155 | +Write-Host "Summary" |
| 156 | +Write-Host "==============================================" |
| 157 | +Write-Host "Files Checked: $filesChecked" |
| 158 | +Write-Host "Issues Found: $issuesFound" |
| 159 | + |
| 160 | +if ($issuesFound -eq 0) { |
| 161 | + Write-Host "" |
| 162 | + Write-Host "V All dates verified successfully!" -ForegroundColor Green |
| 163 | + exit 0 |
| 164 | +} else { |
| 165 | + Write-Host "" |
| 166 | + Write-Host "X Found $issuesFound issue(s) that need attention." -ForegroundColor Red |
| 167 | + exit 1 |
| 168 | +} |
0 commit comments