Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Manifest): Support bucket lookup in Resolve #137

Merged
merged 30 commits into from
May 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6e0dd4e
refactor: Reimplement parse_app
Ash258 Apr 4, 2021
cb51610
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into refactorParseApp
Ash258 Apr 5, 2021
487437d
basic implementation of local path and local path versioned
Ash258 Apr 5, 2021
203ec36
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into refactorParseApp
Ash258 Apr 10, 2021
4091060
typos [ci skip]
Ash258 Apr 10, 2021
3c7401b
mv
Ash258 Apr 10, 2021
f4036bd
all possible implementation/test cases with simle not implemented throw
Ash258 Apr 10, 2021
df12c55
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into refactorParseApp
Ash258 Apr 24, 2021
e1c8325
docs
Ash258 Apr 24, 2021
1db7b36
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into refactorParseApp
Ash258 Apr 24, 2021
4193c58
Remote manifests
Ash258 Apr 24, 2021
6409052
export to function
Ash258 Apr 24, 2021
bf1097a
extract lookup
Ash258 Apr 24, 2021
3cf4e93
skeleton implementation of lookup
Ash258 Apr 24, 2021
2ac9257
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into refactorParseApp
Ash258 May 8, 2021
8f399d1
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into refactorParseApp
Ash258 May 8, 2021
5a3e2d2
wip [ci skip]
Ash258 May 9, 2021
9700095
additional debug
Ash258 May 15, 2021
b02e799
ci fix?
Ash258 May 15, 2021
5caa2c5
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into refactorParseApp
Ash258 May 22, 2021
7e0e5e2
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into refactorParseApp
Ash258 May 23, 2021
a3b546d
test re-org
Ash258 May 23, 2021
37aedc3
l
Ash258 May 23, 2021
8b664bb
move
Ash258 May 23, 2021
6b1ae5f
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into refactorParseApp
Ash258 May 23, 2021
1585c37
fix
Ash258 May 23, 2021
af3a1e5
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into refactorParseApp
Ash258 May 27, 2021
d7ac46e
test preparation
Ash258 May 27, 2021
ad83dd7
first implementation draft
Ash258 May 27, 2021
698fb3d
Merge branch 'NEW' of github.com:Ash258/Scoop-Core into refactorParseApp
Ash258 May 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 90 additions & 1 deletion lib/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function New-VersionedManifest {
throw [ScoopException] "Invalid manifest '$Path'"
}

$name = "$($Path.BaseName)-$(Get-Random)-$(Get-Random)$($Path.Extension)"
$name = "$($Path.BaseName)-$_localAdditionalSeed$(Get-Random)-$(Get-Random)$($Path.Extension)"
$outPath = Confirm-DirectoryExistence -LiteralPath $SHOVEL_GENERAL_MANIFESTS_DIRECTORY | Join-Path -ChildPath $name

try {
Expand Down Expand Up @@ -256,6 +256,88 @@ function Get-RemoteManifest {
}
}
}

function Get-ManifestFromLookup {
<#
.SYNOPSIS
Lookup for manifest in all local buckets and return required information.
.PARAMETER Query
Specifies the lookup query.
#>
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param([Parameter(Mandatory, ValueFromPipeline)] [String] $Query)

process {
# Get all requested information
$requestedBucket, $requestedName = $Query -split '/'
if ($null -eq $requestedName) {
$requestedName = $requestedBucket
$requestedBucket = $null
}
$requestedName, $requestedVersion = $requestedName -split '@'

# Local manifest with specific name in all buckets
$found = @()
$buckets = Get-LocalBucket

if ($requestedBucket -and ($requestedBucket -notin $buckets)) { throw [ScoopException] "'$requestedBucket' cannot be found" }

foreach ($b in $buckets) {
$really = manifest_path $requestedName $b
if ($really) {
$found += @{
'Bucket' = $b
'Path' = $really
}
}
}

# Pick the first one (as vanilla implementation)
# TODO: Let user pick which bucket if there are more
$valid = $found[0]
if ($requestedBucket) { $valid = $found | Where-Object -Property 'Bucket' -EQ -Value $requestedBucket }

if (!$valid) { throw [ScoopException] "No manifest found for '$Query'" }

$manifestBucket = $valid.Bucket
$manifestPath = $valid.Path

# Select versioned manifest or generate it
if ($requestedVersion) {
try {
$path = manifest_path -app $requestedName -bucket $requestedBucket -version $requestedVersion
if ($null -eq $path) { throw 'trigger' }
$manifestPath = $path
} catch {
$mess = if ($requestedBucket) { " in '$requestedBucket'" } else { '' }
Write-UserMessage -Message "There is no archived version of manifest '$requestedName'$mes. Trying to generate the manifest" -Warning

$generated = $null
try {
$generated = New-VersionedManifest -Path $manifestPath -Version $requestedVersion
} catch {
throw [ScoopException] $_.Exception.Message
}

# This should not happen.
if (!(Test-Path -LiteralPath $generated)) { throw [ScoopException] 'Generated manifest cannot be found' }

$manifestPath = $generated
}
}

$name = $requestedName
$manifest = ConvertFrom-Manifest -LiteralPath $manifestPath

return @{
'Name' = $name
'Bucket' = $manifestBucket
'Manifest' = $manifest
'Path' = (Get-Item -LiteralPath $manifestPath)
}
}
}
#endregion Resolve Helpers

function Resolve-ManifestInformation {
Expand Down Expand Up @@ -297,6 +379,13 @@ function Resolve-ManifestInformation {
$manifest = $res.Manifest
$localPath = $res.Path
$url = $ApplicationQuery
} elseif ($ApplicationQuery -match $_lookupRegex) {
$res = Get-ManifestFromLookup -Query $ApplicationQuery
$applicationName = $res.Name
$applicationVersion = $res.Manifest.version
$manifest = $res.Manifest
$localPath = $res.Path
$bucket = $res.Bucket
} else {
throw 'Not supported way how to provide manifest'
}
Expand Down
116 changes: 116 additions & 0 deletions test/Shovel-Manifest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,122 @@ Describe 'Manifests operations' -Tag 'Scoop' {
}
}

Describe 'Get-ManifestFromLookup' {
It 'Simple lookup' {
$result = Resolve-ManifestInformation 'pwsh'
$result.ApplicationName | Should -Be 'pwsh'
$result.Version | Should -Be '7.1.3'
$result.ManifestObject.bin | Should -Be 'pwsh.exe'
$result.Bucket | Should -Be 'ash258.ash258'
$result = $null

$result = Resolve-ManifestInformation 'cosi'
$result.ApplicationName | Should -Be 'cosi'
$result.Version | Should -Be '7.1.3'
$result.ManifestObject.checkver | Should -Be 'github'
$result = $null
}

It 'Simple versioned lookup' {
$result = Resolve-ManifestInformation 'pwsh@6.2.3'
$result.ApplicationName | Should -Be 'pwsh'
$result.Version | Should -Be '6.2.3'
$result.ManifestObject.bin | Should -Be 'pwsh.exe'
$result = $null

$result = Resolve-ManifestInformation 'cosi@7.1.0'
$result.ApplicationName | Should -Be 'cosi'
$result.Bucket | Should -Be 'ash258.ash258'
$result.Version | Should -Be '7.1.0'
$result.ManifestObject.homepage | Should -Be 'https://github.com/PowerShell/PowerShell'
$result = $null

{ Resolve-ManifestInformation 'tryharder' } | Should -Throw 'No manifest found for ''tryharder'''
}

It 'Specific bucket lookup' {
$result = Resolve-ManifestInformation 'main/pwsh'
$result.ApplicationName | Should -Be 'pwsh'
$result.Version | Should -Be '7.1.3'
$result.ManifestObject.bin | Should -Be 'pwsh.exe'
$result.Bucket | Should -Be 'main'
$result = $null

$result = Resolve-ManifestInformation 'ash258.ash258/cosi'
$result.ApplicationName | Should -Be 'cosi'
$result.Bucket | Should -Be 'ash258.ash258'
$result.Version | Should -Be '7.1.3'
$result.ManifestObject.checkver | Should -Be 'github'
$result = $null

{ Resolve-ManifestInformation 'nonexistent/cosi' } | Should -Throw '''nonexistent'' cannot be found'
{ Resolve-ManifestInformation 'main/tryharder' } | Should -Throw 'No manifest found for ''main/tryharder'''
}

It 'Specific bucket lookup with existing versioned manifest' {
$result = Resolve-ManifestInformation 'ash258.ash258/pwsh@6.2.3'
$result.ApplicationName | Should -Be 'pwsh'
$result.Version | Should -Be '6.2.3'
$result.ManifestObject.bin | Should -Be 'pwsh.exe'
$result.Bucket | Should -Be 'ash258.ash258'
$result = $null

$result = Resolve-ManifestInformation 'main/cosi@7.1.0'
$result.ApplicationName | Should -Be 'cosi'
$result.Bucket | Should -Be 'main'
$result.Version | Should -Be '7.1.0'
$result.ManifestObject.homepage | Should -Be 'https://github.com/PowerShell/PowerShell'
$result = $null

{ Resolve-ManifestInformation 'main/pwsh@6.8.0' 6>$null } | Should -Throw 'Cannot generate manifest with version ''6.8.0'''
{ Resolve-ManifestInformation 'ash258.ash258/cosi@8' 6>$null } | Should -Throw 'Cannot generate manifest with version ''8'''
}

It 'Simple lookup with version generation' {
$result = Resolve-ManifestInformation 'pwsh@7.0.6' 6>$null
$result.ApplicationName | Should -Be 'pwsh'
$result.Version | Should -Be '7.0.6'
$result.Bucket | Should -Be 'ash258.ash258'
$result.LocalPath.Extension | Should -BeLike '.json'
$result.LocalPath.BaseName | Should -BeLike 'pwsh-258258--*'
$result.LocalPath.Directory.BaseName | Should -BeLike 'manifests'
$result.ManifestObject.bin | Should -Be 'pwsh.exe'
$result = $null

$result = Resolve-ManifestInformation 'cosi@6.2.3' 6>$null
$result.ApplicationName | Should -Be 'cosi'
$result.Bucket | Should -Be 'ash258.ash258'
$result.LocalPath.Extension | Should -BeLike '.yaml'
$result.LocalPath.BaseName | Should -BeLike 'cosi-258258--*'
$result.LocalPath.Directory.BaseName | Should -BeLike 'manifests'
$result.Version | Should -Be '6.2.3'
$result.ManifestObject.homepage | Should -Be 'https://github.com/PowerShell/PowerShell'
$result = $null
}

It 'Specific bucket lookup with version generation' {
$result = Resolve-ManifestInformation 'main/pwsh@7.0.6' 6>$null
$result.ApplicationName | Should -Be 'pwsh'
$result.Version | Should -Be '7.0.6'
$result.Bucket | Should -Be 'main'
$result.LocalPath.Extension | Should -BeLike '.json'
$result.LocalPath.BaseName | Should -BeLike 'pwsh-258258--*'
$result.LocalPath.Directory.BaseName | Should -BeLike 'manifests'
$result.ManifestObject.bin | Should -Be 'pwsh.exe'
$result = $null

$result = Resolve-ManifestInformation 'ash258.ash258/pwsh@7.0.6' 6>$null
$result.ApplicationName | Should -Be 'pwsh'
$result.Bucket | Should -Be 'ash258.ash258'
$result.LocalPath.Extension | Should -BeLike '.json'
$result.LocalPath.BaseName | Should -BeLike 'pwsh-258258--*'
$result.LocalPath.Directory.BaseName | Should -BeLike 'manifests'
$result.Version | Should -Be '7.0.6'
$result.ManifestObject.homepage | Should -Be 'https://github.com/PowerShell/PowerShell'
$result = $null
}
}

It 'Not supported query' {
{ Resolve-ManifestInformation '@@cosi@@' } | Should -Throw 'Not supported way how to provide manifest'
{ Resolve-ManifestInformation '@1.2.5.8' } | Should -Throw 'Not supported way how to provide manifest'
Expand Down