mirror of
https://github.com/actions/runner-images.git
synced 2025-12-11 11:37:00 +00:00
Update checker
This commit is contained in:
8
.github/workflows/validate-json-schema.yml
vendored
8
.github/workflows/validate-json-schema.yml
vendored
@@ -9,8 +9,6 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Run JSON Schema validation
|
||||
run: |
|
||||
wget -q https://github.com/neilpa/yajsv/releases/download/v1.4.1/yajsv.linux.amd64
|
||||
chmod +x yajsv.linux.amd64
|
||||
./yajsv.linux.amd64 -s ./schemas/toolset-schema.json $(find . -name 'toolset-*.json' | tr '\n' ' ')
|
||||
- name: Validate JSON Schema
|
||||
shell: pwsh
|
||||
run: ./helpers/CheckJsonSchema.ps1
|
||||
|
||||
29
helpers/CheckJsonSchema.ps1
Normal file
29
helpers/CheckJsonSchema.ps1
Normal file
@@ -0,0 +1,29 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
# A JSON schema validator which supports outputting line numbers for errors
|
||||
Install-Module -Name GripDevJsonSchemaValidator -Force -Scope CurrentUser
|
||||
|
||||
# Find all toolset JSON files
|
||||
$toolsetFiles = Get-ChildItem -Recurse -Filter "toolset-*.json" | Where-Object { $_.Name -notlike "*schema.json" }
|
||||
$schemaFilePath = "./schemas/toolset-schema.json"
|
||||
|
||||
foreach ($file in $toolsetFiles) {
|
||||
Write-Host "🔍 Validating $($file.FullName)" -ForegroundColor Cyan
|
||||
|
||||
$validationResult = Test-JsonSchema -SchemaPath $schemaFilePath -JsonPath $file.FullName
|
||||
|
||||
if ($validationResult.Valid) {
|
||||
Write-Host "✅ JSON is valid." -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "`n❌ JSON validation failed!" -ForegroundColor Red
|
||||
Write-Host " Found the following errors:`n" -ForegroundColor Yellow
|
||||
$validationResult.Errors | ForEach-Object {
|
||||
Write-Host $_.UserMessage
|
||||
if ($env:GITHUB_ACTIONS -eq 'true') {
|
||||
Write-Host "::error file=$($file.Name),line=$($_.LineNumber)::$($_.UserMessage)"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "Schema validation completed successfully"
|
||||
69
helpers/CheckPinnedDetails.ps1
Executable file
69
helpers/CheckPinnedDetails.ps1
Executable file
@@ -0,0 +1,69 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
function Get-PinnedDetailsRecursive($obj) {
|
||||
$pinnedDetails = @()
|
||||
|
||||
if ($obj -is [System.Management.Automation.PSCustomObject]) {
|
||||
if ($obj.PSObject.Properties.Name -contains "review-at") {
|
||||
$pinnedDetails += $obj
|
||||
}
|
||||
foreach ($prop in $obj.PSObject.Properties) {
|
||||
Get-PinnedDetailsRecursive $prop.Value
|
||||
}
|
||||
}
|
||||
elseif ($obj -is [Array]) {
|
||||
foreach ($item in $obj) {
|
||||
Get-PinnedDetailsRecursive $item
|
||||
}
|
||||
}
|
||||
|
||||
return $pinnedDetails
|
||||
}
|
||||
|
||||
Write-Host "Checking pinned details for overdue review dates"
|
||||
|
||||
# Find all toolset JSON files in the current directory and subdirectories
|
||||
$toolsetFiles = Get-ChildItem -Recurse -Filter "toolset-*.json"
|
||||
|
||||
foreach ($toolsetFile in $toolsetFiles) {
|
||||
Write-Host "Checking $toolsetFile"
|
||||
|
||||
# Skip schema file
|
||||
if ($toolsetFile.Name -like "*toolset-schema.json") {
|
||||
continue
|
||||
}
|
||||
|
||||
# Get all objects with 'review-at' property from the JSON file
|
||||
$jsonContent = Get-Content $toolsetFile.FullName | ConvertFrom-Json
|
||||
|
||||
$pinnedDetails = Get-PinnedDetailsRecursive $jsonContent | Where-Object { $_ -ne $null }
|
||||
|
||||
foreach ($pinnedDetail in $pinnedDetails) {
|
||||
$reviewDate = $pinnedDetail.'review-at'
|
||||
$reason = $pinnedDetail.reason
|
||||
|
||||
Write-Host "Info: Review date $reviewDate, reason $reason"
|
||||
|
||||
if (![string]::IsNullOrEmpty($reviewDate)) {
|
||||
$reviewDateTime = [DateTime]::Parse($reviewDate)
|
||||
$currentTime = Get-Date
|
||||
$sevenDaysAgo = $currentTime.AddDays(-7)
|
||||
|
||||
Write-Host "Info: Review date $reviewDate, current time $currentTime"
|
||||
|
||||
# Check if review date is in the past
|
||||
if ($reviewDateTime -lt $currentTime) {
|
||||
Write-Host "ERROR: Overdue review date: $reviewDate for tool in $($toolsetFile.Name)"
|
||||
Write-Host " Pinned for '$reason'"
|
||||
Write-Host ""
|
||||
}
|
||||
|
||||
# Check if review date is within the next 7 days
|
||||
if ($reviewDateTime -gt $sevenDaysAgo -and $reviewDateTime -le $currentTime) {
|
||||
Write-Host "WARNING: Review date is coming up within the next 7 days: $reviewDate for tool in $($toolsetFile.Name)"
|
||||
Write-Host " Pinned for '$reason'"
|
||||
Write-Host ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
toolset_files=$(find . -name 'toolset-*.json')
|
||||
|
||||
for toolset_file in $toolset_files; do
|
||||
if [[ "$toolset_file" == *"toolset-schema.json" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
readarray -t pinned_details < <(jq --compact-output '.. | objects | select(has("review-at"))' "$toolset_file")
|
||||
|
||||
for pinned_detail in "${pinned_details[@]}"; do
|
||||
review_date=$(jq -r '.["review-at"]' <<< "$pinned_detail")
|
||||
reason=$(jq -r '.["reason"]' <<< "$pinned_detail")
|
||||
|
||||
if [ -n "$review_date" ]; then
|
||||
if [ "$(date -d "$review_date" +%s)" -gt "$(date +%s)" ]; then
|
||||
echo "ERROR: Overdue review date: $review_date for tool in $toolset_file"
|
||||
echo " Pinned for '$reason'"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
if [ "$(date -d "$review_date" +%s)" -le $(( $(date +%s) - 7*24*60*60 )) ]; then
|
||||
echo "WARNING: Review date is coming up within the next 7 days: $review_date for tool in $toolset_file"
|
||||
echo " Pinned for '$reason'"
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
done
|
||||
done
|
||||
Reference in New Issue
Block a user