-
Notifications
You must be signed in to change notification settings - Fork 26
/
Bucket.Tests.ps1
130 lines (110 loc) · 3.89 KB
/
Bucket.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
if (-not $env:SCOOP_HOME) { $env:SCOOP_HOME = Resolve-Path (scoop prefix scoop) }
# Don't install when not in CI
if (-not $env:CI) {
Write-Host 'Skipping installation.' -ForegroundColor Yellow
return
}
. "$env:SCOOP_HOME\lib\manifest.ps1" # Import for parse json function
. "$env:SCOOP_HOME\test\Import-Bucket-Tests.ps1" # run tests from scoop core
# region Install changed manifests
function log([String[]] $message = "============`r`n") {
Add-Content './INSTALL.log' ($message -join "`r`n") -Encoding 'Ascii'
}
function install() {
param(
[String] $manifest,
[ValidateSet('32bit', '64bit', 'arm64', 'URL')]
[String] $architecture
)
$command = "shovel install $manifest --no-cache --independent"
if ($architecture -ne 'URL') {
$command += " --arch $architecture"
}
$result = @(Invoke-Expression "$command *>&1")
$exit = $LASTEXITCODE
log
log "Manifest: $manifest"
log "Arch: $architecture"
log $result
log
return $exit
}
function uninstall($noExt) {
$log = @(shovel uninstall $noExt *>&1)
if ($LASTEXITCODE -eq 0) {
log
log 'Uninstallation'
log $log
log "$noExt`: Uninstall DONE"
log
}
}
Describe 'Changed manifests installation' {
# Duplicate check when test is manually executed.
if (-not $env:CI) {
# Do not install on powershell core
Write-Host 'This test should run only in CI environment.' -ForegroundColor Yellow
return
}
$INSTALL_FILES_EXCLUSIONS = @(
'.vscode',
'TODO',
'KMS',
'E2B',
'unlocker',
'Spotify',
'TrainerManager',
'TransMac'
) -join '|'
$INSTALL_FILES_EXCLUSIONS = ".*($INSTALL_FILES_EXCLUSIONS).*"
New-Item 'INSTALL.log' -Type File -Force
$commit = if ($env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT) { $env:APPVEYOR_PULL_REQUEST_HEAD_COMMIT } else { $env:APPVEYOR_REPO_COMMIT }
$allChanges = Get-GitChangedFile -Commit $commit |
Where-Object { $_ -inotmatch $INSTALL_FILES_EXCLUSIONS } |
Where-Object { $_ -imatch '[/\\]bucket[/\\]' }
$changedFiles = @()
$changedFiles += $allChanges | Where-Object { $_ -like '*.json' }
$changedFiles += $allChanges | Where-Object { $_ -like '*.yml' }
if ($changedFiles.Count -gt 0) {
Write-Host "Processing $($changedFiles.Count) changed manifests" -ForegroundColor 'Green'
log @(shovel install 7zip gsudo innounp dark lessmsi *>&1) # Install default apps for manifest manipultion / installation
foreach ($file in $changedFiles) {
# Skip deleted manifests
if (!(Test-Path $file)) { continue }
$mm = Get-Item $file
$man = $mm.Name
$noExt = $mm.BaseName
$toInstall = $mm.FullName
$64 = '64bit'
$32 = '32bit'
$arm64 = 'arm64'
$URL = 'URL'
Context $man {
$json = ConvertFrom-Manifest $toInstall
if ($json.architecture) {
if ($json.architecture.$64) {
It $64 {
install $toInstall $64 | Should -Be 0
}
uninstall $noExt
}
if ($json.architecture.$arm64) {
It $arm64 {
install $toInstall $arm64 | Should -Be 0
}
uninstall $noExt
}
if ($json.architecture.$32) {
It $32 {
install $toInstall $32 | Should -Be 0
}
uninstall $noExt
}
} else {
It $URL { install $toInstall $URL | Should -Be 0 }
}
}
}
}
}
# endregion Install changed manifests