Skip to content

Commit

Permalink
refactor: Add $version for manifest_path (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash258 committed May 22, 2021
1 parent b864889 commit 484f4ad
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,6 @@ function app_status($app, $global) {
return $status
}

# TODO: YAML
function appname_from_url($url) { return (Split-Path $url -Leaf) -replace '\.json$' }

# paths
function fname($path) { return Split-Path $path -Leaf }
function strip_ext($fname) { return $fname -replace '\.[^\.]*$' }
Expand Down Expand Up @@ -1157,6 +1154,9 @@ $SCOOP_GLOBAL_ROOT_DIRECTORY = $env:SCOOP_GLOBAL, "$env:ProgramData\scoop" | Whe
# Use at your own risk.
$SCOOP_CACHE_DIRECTORY = $env:SCOOP_CACHE, "$SCOOP_ROOT_DIRECTORY\cache" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1

# Directory for downloaded manifests (mainly)
$SHOVEL_GENERAL_MANIFESTS_DIRECTORY = Join-Path $SCOOP_ROOT_DIRECTORY 'manifests'

# Load Scoop config
$configHome = $env:XDG_CONFIG_HOME, "$env:USERPROFILE\.config" | Where-Object { -not [String]::IsNullOrEmpty($_) } | Select-Object -First 1
$SCOOP_CONFIGURATION_FILE = Join-Path $configHome 'scoop\config.json'
Expand Down
22 changes: 21 additions & 1 deletion lib/manifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,14 @@ function ConvertTo-Manifest {
}
}

function manifest_path($app, $bucket) {
# TODO: YAML
function appname_from_url($url) { return (Split-Path $url -Leaf) -replace '\.json$' }

function manifest_path($app, $bucket, $version = $null) {
$name = sanitary_path $app
$buc = Find-BucketDirectory -Bucket $bucket
$path = $file = $null

try {
$file = Get-ChildItem -LiteralPath $buc -Filter "$name.*" -ErrorAction 'Stop'
} catch {
Expand All @@ -110,6 +114,22 @@ function manifest_path($app, $bucket) {
if ($file) {
if ($file.Count -gt 1) { $file = $file[0] }
$path = $file.FullName

# Look for archived version only if manifest exists
if ($version) {
$path = $null
$versions = @()

try {
$versions = Get-ChildItem -LiteralPath "$buc\old\$name" -Filter "$version.*" -ErrorAction 'Stop'
} catch {
throw [ScoopException] "Bucket '$bucket' does not contain archived version '$version' for '$app'"
}

if ($versions.Count -gt 1) { $versions = $versions[0] }

$path = $versions.FullName
}
}

return $path
Expand Down
58 changes: 58 additions & 0 deletions test/Shovel-Manifest.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

. "$PSScriptRoot\Scoop-TestLib.ps1"
. "$PSScriptRoot\..\lib\core.ps1"
. "$PSScriptRoot\..\lib\manifest.ps1"

Describe 'Resolve-ManifestInformation' -Tag 'Scoop' {
BeforeAll {
$working_dir = (setup_working 'manifest' | Resolve-Path).Path
Move-Item "$working_dir\*.*" "$working_dir\bucket"
$SCOOP_BUCKETS_DIRECTORY = $working_dir | Split-Path

Copy-Item $working_dir "$SCOOP_BUCKETS_DIRECTORY\ash258.ash258" -Force -Recurse
Copy-Item $working_dir "$SCOOP_BUCKETS_DIRECTORY\main" -Force -Recurse
}

It 'manifest_path' {
$path = manifest_path 'cosi' 'manifest'
$path | Should -Be "$working_dir\bucket\cosi.yaml"
$path = $null

$path = manifest_path 'wget' 'manifest'
$path | Should -Be "$working_dir\bucket\wget.json"
$path = $null

$path = manifest_path 'pwsh' 'ash258.ash258'
$path | Should -Be "$SCOOP_BUCKETS_DIRECTORY\ash258.ash258\bucket\pwsh.json"
$path = $null

$path = manifest_path 'cosi' 'main'
$path | Should -Be "$SCOOP_BUCKETS_DIRECTORY\main\bucket\cosi.yaml"
$path = $null

$path = manifest_path 'pwsh' 'alfa'
$path | Should -Be $null
$path = $null

$path = manifest_path 'ahoj' 'main'
$path | Should -Be $null
$path = $null
}

It 'manifest_path with version' {
$path = manifest_path 'cosi' 'main' '7.1.0'
$path | Should -Be "$SCOOP_BUCKETS_DIRECTORY\main\bucket\old\cosi\7.1.0.yaml"
$path = $null

$path = manifest_path 'pwsh' 'ash258.ash258' '6.2.3'
$path | Should -Be "$SCOOP_BUCKETS_DIRECTORY\ash258.ash258\bucket\old\pwsh\6.2.3.yml"
$path = $null

$path = manifest_path 'pwsh' 'ash258.ash258' '2222'
$path | Should -Be $null
$path = $null

{ manifest_path 'wget' 'ash258.ash258' '2222' } | Should -Throw 'Bucket ''ash258.ash258'' does not contain archived version ''2222'' for ''wget'''
$path = $null
}
}
26 changes: 26 additions & 0 deletions test/fixtures/manifest/bucket/cosi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 7.1.3
description: Cross-platform automation and configuration tool/framework, known as Powershell Core, that works well with existing tools and is optimized for dealing with structured data.
homepage: https://github.com/PowerShell/PowerShell
license: MIT
architecture:
64bit:
url: https://github.com/PowerShell/PowerShell/releases/download/v7.1.3/PowerShell-7.1.3-win-x64.zip
hash: 47475f1d4015704f3fb5f6d2cf61196d121aba60c19592b04be818317ce01039
32bit:
url: https://github.com/PowerShell/PowerShell/releases/download/v7.1.3/PowerShell-7.1.3-win-x86.zip
hash: ecfd51545084d9b791874062c39eb0c7c7dd2991265ee7f4dc5064995a614e6c
bin: pwsh.exe
shortcuts:
- - pwsh.exe
- PowerShell Core
checkver: github
autoupdate:
archive: true
architecture:
64bit:
url: https://github.com/PowerShell/PowerShell/releases/download/v$version/PowerShell-$version-win-x64.zip
32bit:
url: https://github.com/PowerShell/PowerShell/releases/download/v$version/PowerShell-$version-win-x86.zip
hash:
url: https://github.com/PowerShell/PowerShell/releases/tag/v$version/
regex: $basename\s*<ul>\s*<li>$sha256
15 changes: 15 additions & 0 deletions test/fixtures/manifest/bucket/old/cosi/7.1.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 7.1.0
description: Cross-platform automation and configuration tool/framework, known as Powershell Core, that works well with existing tools and is optimized for dealing with structured data.
homepage: https://github.com/PowerShell/PowerShell
license: MIT
architecture:
64bit:
url: https://github.com/PowerShell/PowerShell/releases/download/v7.1.0/PowerShell-7.1.0-win-x64.zip
hash: c86f260f92b31d4e8e30b1ebbeb09e13364fc095ecf1538d9a8cec18d21d5d32
32bit:
url: https://github.com/PowerShell/PowerShell/releases/download/v7.1.0/PowerShell-7.1.0-win-x86.zip
hash: 3d0f768573317a0f69dab4f924b772ee947828d89cbf6bf5c7242b45a3800fbc
bin: pwsh.exe
shortcuts:
- - pwsh.exe
- PowerShell Core
15 changes: 15 additions & 0 deletions test/fixtures/manifest/bucket/old/pwsh/6.2.3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 6.2.3
description: Cross-platform automation and configuration tool/framework, known as Powershell Core, that works well with existing tools and is optimized for dealing with structured data.
homepage: https://github.com/PowerShell/PowerShell
license: MIT
architecture:
64bit:
url: https://github.com/PowerShell/PowerShell/releases/download/v6.2.3/PowerShell-6.2.3-win-x64.zip
hash: af171ed197b167e2630044dba6344af8b291e8646f7276b63f1d84c166a41d33
32bit:
url: https://github.com/PowerShell/PowerShell/releases/download/v6.2.3/PowerShell-6.2.3-win-x86.zip
hash: 6b9f1c54755aa51678e56a6059c2747801b3e0c72e678b800b15c8e084129c66
bin: pwsh.exe
shortcuts:
- - pwsh.exe
- PowerShell Core
39 changes: 39 additions & 0 deletions test/fixtures/manifest/bucket/pwsh.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"version": "7.1.3",
"description": "Cross-platform automation and configuration tool/framework, known as Powershell Core, that works well with existing tools and is optimized for dealing with structured data.",
"homepage": "https://github.com/PowerShell/PowerShell",
"license": "MIT",
"architecture": {
"64bit": {
"url": "https://github.com/PowerShell/PowerShell/releases/download/v7.1.3/PowerShell-7.1.3-win-x64.zip",
"hash": "47475f1d4015704f3fb5f6d2cf61196d121aba60c19592b04be818317ce01039"
},
"32bit": {
"url": "https://github.com/PowerShell/PowerShell/releases/download/v7.1.3/PowerShell-7.1.3-win-x86.zip",
"hash": "ecfd51545084d9b791874062c39eb0c7c7dd2991265ee7f4dc5064995a614e6c"
}
},
"bin": "pwsh.exe",
"shortcuts": [
[
"pwsh.exe",
"PowerShell Core"
]
],
"checkver": "github",
"autoupdate": {
"archive": true,
"architecture": {
"64bit": {
"url": "https://github.com/PowerShell/PowerShell/releases/download/v$version/PowerShell-$version-win-x64.zip"
},
"32bit": {
"url": "https://github.com/PowerShell/PowerShell/releases/download/v$version/PowerShell-$version-win-x86.zip"
}
},
"hash": {
"url": "https://github.com/PowerShell/PowerShell/releases/tag/v$version/",
"regex": "$basename\\s*<ul>\\s*<li>$sha256"
}
}
}

0 comments on commit 484f4ad

Please sign in to comment.