diff --git a/CHANGELOG.md b/CHANGELOG.md index 12d6aa4739..079b124bd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [0.6.5](https://github.com/Ash258/Scoop-Core/milestone/5) +- **CI**: + - Support basic validation of yml typed manifests + - Support validation of all archived manifests - **scoop-cat**: Add `-f`, `--format` options - Adopt new resolve function for parameter passing - **scoop-home** diff --git a/test/Scoop-Manifest.Tests.ps1 b/test/Scoop-Manifest.Tests.ps1 index 6d4b1a99d0..964da3384a 100644 --- a/test/Scoop-Manifest.Tests.ps1 +++ b/test/Scoop-Manifest.Tests.ps1 @@ -20,6 +20,7 @@ Describe -Tag 'Manifests' 'manifest-validation' { Context 'parse_json function' { It 'fails with invalid json' { { parse_json "$working_dir\broken_wget.json" } | Should -Throw + { ConvertFrom-Manifest "$working_dir\broken_wget.json" } | Should -Throw } } @@ -27,21 +28,21 @@ Describe -Tag 'Manifests' 'manifest-validation' { It 'fails with broken schema' { $validator = New-Object Scoop.Validator("$working_dir/broken_schema.json", $true) $validator.Validate("$working_dir/wget.json") | Should -BeFalse - $validator.Errors.Count | Should -be 1 - $validator.Errors | Select-Object -First 1 | Should -match 'broken_schema.*(line 6).*(position 4)' + $validator.Errors.Count | Should -Be 1 + $validator.Errors | Select-Object -First 1 | Should -Match 'broken_schema.*(line 6).*(position 4)' } It 'fails with broken manifest' { $validator = New-Object Scoop.Validator($schema, $true) $validator.Validate("$working_dir/broken_wget.json") | Should -BeFalse - $validator.Errors.Count | Should -be 1 - $validator.Errors | Select-Object -First 1 | Should -match 'broken_wget.*(line 5).*(position 4)' + $validator.Errors.Count | Should -Be 1 + $validator.Errors | Select-Object -First 1 | Should -Match 'broken_wget.*(line 5).*(position 4)' } It 'fails with invalid manifest' { $validator = New-Object Scoop.Validator($schema, $true) $validator.Validate("$working_dir/invalid_wget.json") | Should -BeFalse - $validator.Errors.Count | Should -be 16 - $validator.Errors | Select-Object -First 1 | Should -match "Property 'randomproperty' has not been defined and the schema does not allow additional properties\." - $validator.Errors | Select-Object -Last 1 | Should -match 'Required properties are missing from object: version, description\.' + $validator.Errors.Count | Should -Be 16 + $validator.Errors | Select-Object -First 1 | Should -Match "Property 'randomproperty' has not been defined and the schema does not allow additional properties\." + $validator.Errors | Select-Object -Last 1 | Should -Match 'Required properties are missing from object: version, description\.' } } @@ -49,36 +50,50 @@ Describe -Tag 'Manifests' 'manifest-validation' { BeforeAll { if ($null -eq $bucketdir) { $bucketdir = "$PSScriptRoot\..\bucket\" } if (!(Test-Path $bucketdir)) { New-Item $bucketdir -ItemType 'Directory' -Force } + $changed_manifests = @() + $manifest_files = @() + $allFiles = Get-ChildItem $bucketdir -Recurse + if ($env:CI -eq $true) { $commit = if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) { $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT } else { $env:APPVEYOR_REPO_COMMIT } - $changed_manifests = (Get-GitChangedFile -Include '*.json' -Commit $commit) + if ($commit) { + $allChanged = Get-GitChangedFile -Commit $commit + + # Filter out valid manifests + foreach ($ext in $ALLOWED_MANIFEST_EXTENSION) { + $changed_manifests += $allChanged | Where-Object { $_ -like "*.$ext" } + } + } + } + + # Filter out valid manifests + foreach ($ext in $ALLOWED_MANIFEST_EXTENSION) { + $manifest_files += $allFiles | Where-Object { $_ -like "*.$ext" } } - $manifest_files = Get-ChildItem $bucketdir *.json + $validator = New-Object Scoop.Validator($schema, $true) } $quota_exceeded = $false - $manifest_files | ForEach-Object { - $skip_manifest = ($changed_manifests -inotcontains $_.FullName) - if ($env:CI -ne $true -or $changed_manifests -imatch 'schema.json') { - $skip_manifest = $false - } - It "$_" -Skip:$skip_manifest { - $file = $_ # exception handling may overwrite $_ + foreach ($file in $manifest_files) { + $skip_manifest = ($changed_manifests -inotcontains $file.FullName) + if (($env:CI -ne $true) -or ($changed_manifests -imatch 'schema.json')) { $skip_manifest = $false } - if (!($quota_exceeded)) { + It "$file" -Skip:$skip_manifest { + # TODO: Skip yml for now for schema validation + if (!$quota_exceeded -and ($file.Extension -notmatch '\.ya?ml$')) { try { - $validator.Validate($file.fullname) + $validator.Validate($file.FullName) if ($validator.Errors.Count -gt 0) { - Write-Host -f red " [-] $_ has $($validator.Errors.Count) Error$(If($validator.Errors.Count -gt 1) { 's' })!" + Write-Host -f red " [-] $file has $($validator.Errors.Count) Error$(If($validator.Errors.Count -gt 1) { 's' })!" Write-Host -f yellow $validator.ErrorsAsString } - $validator.Errors.Count | Should -be 0 + $validator.Errors.Count | Should -Be 0 } catch { - if ($_.exception.message -like '*The free-quota limit of 1000 schema validations per hour has been reached.*') { + if ($_.Exception.Message -like '*The free-quota limit of 1000 schema validations per hour has been reached.*') { $quota_exceeded = $true Write-Host -f darkyellow 'Schema validation limit exceeded. Will skip further validations.' } else { @@ -87,12 +102,12 @@ Describe -Tag 'Manifests' 'manifest-validation' { } } - $manifest = parse_json $file.fullname + $manifest = ConvertFrom-Manifest -LiteralPath $file.FullName $url = arch_specific 'url' $manifest '32bit' $url64 = arch_specific 'url' $manifest '64bit' - if (!$url) { - $url = $url64 - } + + if (!$url) { $url = $url64 } + $url | Should -Not -BeNullOrEmpty } }