diff --git a/.github/workflows/validate-json-schema.yml b/.github/workflows/validate-json-schema.yml index 4d35acea4..6ac19e202 100644 --- a/.github/workflows/validate-json-schema.yml +++ b/.github/workflows/validate-json-schema.yml @@ -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 diff --git a/helpers/CheckJsonSchema.ps1 b/helpers/CheckJsonSchema.ps1 new file mode 100644 index 000000000..f38eafda2 --- /dev/null +++ b/helpers/CheckJsonSchema.ps1 @@ -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" diff --git a/helpers/CheckPinnedDetails.ps1 b/helpers/CheckPinnedDetails.ps1 new file mode 100755 index 000000000..03b573e6a --- /dev/null +++ b/helpers/CheckPinnedDetails.ps1 @@ -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 "" + } + } + } +} diff --git a/helpers/pinned-details-chech.sh b/helpers/pinned-details-chech.sh deleted file mode 100755 index 1874e3b81..000000000 --- a/helpers/pinned-details-chech.sh +++ /dev/null @@ -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