Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1c54f4

Browse files
authored
Adds new upload script for Windows releases (GH-7268)
1 parent 0a36ac1 commit e1c54f4

1 file changed

Lines changed: 121 additions & 0 deletions

File tree

Tools/msi/uploadrelease.ps1

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<#
2+
.Synopsis
3+
Uploads from a VSTS release build layout to python.org
4+
.Description
5+
Given the downloaded/extracted build artifact from a release
6+
build run on python.visualstudio.com, this script uploads
7+
the files to the correct locations.
8+
.Parameter build
9+
The location on disk of the extracted build artifact.
10+
.Parameter user
11+
The username to use when logging into the host.
12+
.Parameter server
13+
The host or PuTTY session name.
14+
.Parameter target
15+
The subdirectory on the host to copy files to.
16+
.Parameter tests
17+
The path to run download tests in.
18+
.Parameter skipupload
19+
Skip uploading
20+
.Parameter skippurge
21+
Skip purging the CDN
22+
.Parameter skiptest
23+
Skip the download tests
24+
.Parameter skiphash
25+
Skip displaying hashes
26+
#>
27+
param(
28+
[Parameter(Mandatory=$true)][string]$build,
29+
[Parameter(Mandatory=$true)][string]$user,
30+
[string]$server="python-downloads",
31+
[string]$target="/srv/www.python.org/ftp/python",
32+
[string]$tests=${env:TEMP},
33+
[switch]$skipupload,
34+
[switch]$skippurge,
35+
[switch]$skiptest,
36+
[switch]$skiphash
37+
)
38+
39+
if (-not $build) { throw "-build option is required" }
40+
if (-not $user) { throw "-user option is required" }
41+
42+
function find-putty-tool {
43+
param ([string]$n)
44+
$t = gcm $n -EA 0
45+
if (-not $t) { $t = gcm ".\$n" -EA 0 }
46+
if (-not $t) { $t = gcm "${env:ProgramFiles}\PuTTY\$n" -EA 0 }
47+
if (-not $t) { $t = gcm "${env:ProgramFiles(x86)}\PuTTY\$n" -EA 0 }
48+
if (-not $t) { throw "Unable to locate $n.exe. Please put it on $PATH" }
49+
return gi $t.Path
50+
}
51+
52+
$p = gci -r "$build\python-*.exe" | `
53+
?{ $_.Name -match '^python-(\d+\.\d+\.\d+)((a|b|rc)\d+)?-.+' } | `
54+
select -first 1 | `
55+
%{ $Matches[1], $Matches[2] }
56+
57+
"Uploading version $($p[0]) $($p[1])"
58+
" from: $build"
59+
" to: $($server):$target/$($p[0])"
60+
" using: $plink and $pscp"
61+
""
62+
63+
if (-not $skipupload) {
64+
# Upload files to the server
65+
$pscp = find-putty-tool "pscp"
66+
$plink = find-putty-tool "plink"
67+
68+
pushd $build
69+
$doc = gci python*.chm, python*.chm.asc
70+
popd
71+
72+
$d = "$target/$($p[0])/"
73+
& $plink -batch $user@$server mkdir $d "&&" chgrp downloads $d "&&" chmod g-x,o+rx $d
74+
& $pscp -batch $doc.FullName "$user@${server}:$d"
75+
76+
foreach ($a in gci "$build" -Directory) {
77+
"Uploading files from $($a.FullName)"
78+
pushd "$($a.FullName)"
79+
$exe = gci *.exe, *.exe.asc, *.zip, *.zip.asc
80+
$msi = gci *.msi, *.msi.asc, *.msu, *.msu.asc
81+
popd
82+
83+
& $pscp -batch $exe.FullName "$user@${server}:$d"
84+
85+
$sd = "$d$($a.Name)$($p[1])/"
86+
& $plink -batch $user@$server mkdir $sd "&&" chgrp downloads $sd "&&" chmod g-x,o+rx $sd
87+
& $pscp -batch $msi.FullName "$user@${server}:$sd"
88+
& $plink -batch $user@$server chgrp downloads $sd* "&&" chmod g-x,o+rx $sd*
89+
}
90+
91+
& $plink -batch $user@$server chgrp downloads $d* "&&" chmod g-x,o+rx $d*
92+
}
93+
94+
if (-not $skippurge) {
95+
# Run a CDN purge
96+
py purge.py "$($p[0])$($p[1])"
97+
}
98+
99+
if (-not $skiptest) {
100+
# Use each web installer to produce a layout. This will download
101+
# each referenced file and validate their signatures/hashes.
102+
gci "$build\*-webinstall.exe" -r -File | %{
103+
$d = mkdir "$tests\$($_.BaseName)" -Force
104+
gci $d -r -File | del
105+
$ic = copy $_ $d -PassThru
106+
"Checking layout for $($ic.Name)"
107+
Start-Process -wait $ic "/passive", "/layout", "$d\layout", "/log", "$d\log\install.log"
108+
if (-not $?) {
109+
Write-Error "Failed to validate layout of $($inst.Name)"
110+
}
111+
}
112+
}
113+
114+
if (-not $skiphash) {
115+
# Display MD5 hash and size of each downloadable file
116+
pushd $build
117+
gci python*.chm, *\*.exe, *\*.zip | `
118+
Sort-Object Name | `
119+
Format-Table Name, @{Label="MD5"; Expression={(Get-FileHash $_ -Algorithm MD5).Hash}}, Length
120+
popd
121+
}

0 commit comments

Comments
 (0)