Skip to content

Commit

Permalink
refactor: Add New-VersionedManifest function (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 committed May 22, 2021
1 parent 484f4ad commit 7010d33
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,52 @@ function manifest_path($app, $bucket, $version = $null) {
return $path
}

function New-VersionedManifest {
<#
.SYNOPSIS
Generate new manifest with specified version.
.DESCRIPTION
Path to the new manifest will be returned.
Generated manifests will be saved into $env:SCOOP\manifests and named as '<OriginalName>-<Random>-<Random>.<OriginalExtension>'
.PARAMETER Path
Specifies the path to the original manifest.
.PARAMETER Version
Specifies the version to which manifest should be updated.
#>
[CmdletBinding()]
[OutputType([String])]
param(
[Parameter(Mandatory, ValueFromPipeline)]
[Alias('LiteralPath')]
[System.IO.FileInfo] $Path,
[Parameter(Mandatory)]
[String] $Version
)

process {
$manifest = $newManifest = $null
try {
$manifest = ConvertFrom-Manifest -LiteralPath $Path
} catch {
throw [ScoopException] "Invalid manifest '$Path'"
}

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

try {
$newManifest = Invoke-Autoupdate $Path.Basename $null $manifest $Version $(${ }) $Path.Extension -IgnoreArchive
if ($null -eq $newManifest) { throw 'trigger' }
} catch {
throw [ScoopException] "Cannot generate manifest with version '$Version'"
}

ConvertTo-Manifest -Path $outpath -Manifest $newManifest

return $outPath
}
}

function parse_json {
param([Parameter(Mandatory, ValueFromPipeline)] [System.IO.FileInfo] $Path)

Expand Down
20 changes: 20 additions & 0 deletions test/Shovel-Manifest.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,24 @@ Describe 'Resolve-ManifestInformation' -Tag 'Scoop' {
{ manifest_path 'wget' 'ash258.ash258' '2222' } | Should -Throw 'Bucket ''ash258.ash258'' does not contain archived version ''2222'' for ''wget'''
$path = $null
}

It 'New-VersionedManifest' {
$path = manifest_path 'pwsh' 'ash258.ash258'
$new = New-VersionedManifest -LiteralPath $path -Version '7.1.0' 6>$null
$new | Should -BeLike "$env:SCOOP\manifests\pwsh-*.json"
(ConvertFrom-Manifest -LiteralPath $new).version | Should -Be '7.1.0'
$path = $null

$path = manifest_path 'cosi' 'main'
$new = New-VersionedManifest -LiteralPath $path -Version '6.2.3' 6>$null
$new | Should -BeLike "$env:SCOOP\manifests\cosi-*.yaml"
(ConvertFrom-Manifest -LiteralPath $new).version | Should -Be '6.2.3'
$path = $null

{ manifest_path 'cosi' 'main' | New-VersionedManifest -Version '22222' 6>$null } | Should -Throw 'Cannot generate manifest with version ''22222'''

$path = manifest_path 'broken_wget' 'main'
{ New-VersionedManifest -LiteralPat $path -Version '22222' 6>$null } | Should -Throw "Invalid manifest '$path'"
$path = $null
}
}

0 comments on commit 7010d33

Please sign in to comment.