podman
173 строки · 4.8 Кб
1function Copy-Artifact {
2param(
3[Parameter(Mandatory)]
4[string]$fileName
5)
6$file = Get-ChildItem -Recurse -Path . -Name $fileName
7if (!$file) {
8throw "Could not find $filename"
9}
10Write-Host "file:" $file
11Copy-Item -Path $file -Destination "..\artifacts\$filename" -ErrorAction Stop
12}
13
14function DownloadOrSkip {
15param(
16[Parameter(Mandatory)]
17[string]$url,
18[Parameter(Mandatory)]
19[string]$file
20)
21$ProgressPreference = 'SilentlyContinue';
22try {
23Invoke-WebRequest -UseBasicParsing -ErrorAction Stop -Uri $url -OutFile $file
24} Catch {
25if ($_.Exception.Response.StatusCode -eq 404) {
26Write-Host "URL not available, signaling skip:"
27Write-Host "URL: $url"
28Exit 2
29}
30
31throw $_.Exception
32}
33}
34
35function DownloadOptional {
36param(
37[Parameter(Mandatory)]
38[string]$url,
39[Parameter(Mandatory)]
40[string]$file
41)
42$ProgressPreference = 'SilentlyContinue';
43try {
44Invoke-WebRequest -UseBasicParsing -ErrorAction Stop -Uri $url -OutFile $file
45} Catch {
46}
47
48Return
49}
50
51
52if ($args.Count -lt 1) {
53Write-Host "Usage: " $MyInvocation.MyCommand.Name "<version> [release_dir]"
54Exit 1
55}
56
57$releaseDir = ""
58if ($args.Count -gt 1 -and $args[1].Length -gt 0) {
59$path = $args[1]
60$releaseDir = (Resolve-Path -Path "$path" -ErrorAction Stop).Path
61}
62
63
64$base_url = "$ENV:FETCH_BASE_URL"
65if ($base_url.Length -le 0) {
66$base_url = "https://github.com/containers/podman"
67}
68
69$version = $args[0]
70if ($version -notmatch '^v?([0-9]+\.[0-9]+\.[0-9]+)(-.*)?$') {
71Write-Host "Invalid version"
72Exit 1
73}
74
75# WiX burn requires a QWORD version only, numeric only
76$Env:INSTVER=$Matches[1]
77
78if ($version[0] -ne 'v') {
79$version = 'v' + $version
80}
81
82$restore = 0
83$exitCode = 0
84
85try {
86Write-Host "Cleaning up old artifacts"
87Remove-Item -Force -Recurse -Path .\docs -ErrorAction SilentlyContinue | Out-Null
88Remove-Item -Force -Recurse -Path .\artifacts -ErrorAction SilentlyContinue | Out-Null
89Remove-Item -Force -Recurse -Path .\fetch -ErrorAction SilentlyContinue | Out-Null
90
91New-Item fetch -ItemType Directory | Out-Null
92New-Item artifacts -ItemType Directory | Out-Null
93
94Write-Host "Fetching zip release"
95
96Push-Location fetch -ErrorAction Stop
97$restore = 1
98$ProgressPreference = 'SilentlyContinue';
99
100if ($releaseDir.Length -gt 0) {
101Copy-Item -Path "$releaseDir/podman-remote-release-windows_amd64.zip" "release.zip"
102} else {
103DownloadOrSkip "$base_url/releases/download/$version/podman-remote-release-windows_amd64.zip" "release.zip"
104DownloadOptional "$base_url/releases/download/$version/shasums" ..\shasums
105}
106Expand-Archive -Path release.zip
107$loc = Get-ChildItem -Recurse -Path . -Name win-sshproxy.exe
108if (!$loc) {
109if ($releaseDir.Length -gt 0) {
110throw "Release dir only supports zip which includes win-sshproxy.exe"
111}
112Write-Host "Old release, zip does not include win-sshproxy.exe, fetching via msi"
113DownloadOrSkip "$base_url/releases/download/$version/podman-$version.msi" "podman.msi"
114dark -x expand ./podman.msi
115if (!$?) {
116throw "Dark command failed"
117}
118$loc = Get-ChildItem -Recurse -Path expand -Name 4A2AD125-34E7-4BD8-BE28-B2A9A5EDBEB5
119if (!$loc) {
120throw "Could not obtain win-sshproxy.exe"
121}
122Copy-Item -Path "expand\$loc" -Destination "win-sshproxy.exe" -ErrorAction Stop
123Remove-Item -Recurse -Force -Path expand
124}
125
126Write-Host "Copying artifacts"
127Foreach ($fileName in "win-sshproxy.exe", "podman.exe") {
128Copy-Artifact($fileName)
129}
130
131$loc = Get-ChildItem -Recurse -Path . -Name gvproxy.exe
132if (!$loc) {
133Write-Host "Skipping gvproxy.exe artifact"
134} else {
135Copy-Artifact("gvproxy.exe")
136}
137
138# Retaining for future additions
139# $loc = Get-ChildItem -Recurse -Path . -Name policy.json
140# if (!$loc) {
141# Write-Host "Skipping policy.json artifact"
142# } else {
143# Copy-Artifact("policy.json")
144# }
145
146$docsloc = Get-ChildItem -Path . -Name docs -Recurse
147$loc = Get-ChildItem -Recurse -Path . -Name podman-for-windows.html
148if (!$loc) {
149Write-Host "Old release did not include welcome page, using podman-machine instead"
150$loc = Get-ChildItem -Recurse -Path . -Name podman-machine.html
151Copy-Item -Path $loc -Destination "$docsloc\podman-for-windows.html"
152}
153
154Write-Host "Copying docs"
155Copy-Item -Recurse -Path $docsloc -Destination ..\docs -ErrorAction Stop
156Write-Host "Done!"
157
158if (!$loc) {
159throw "Could not find docs"
160}
161}
162catch {
163Write-Host $_
164
165$exitCode = 1
166}
167finally {
168if ($restore) {
169Pop-Location
170}
171}
172
173exit $exitCode
174