blob: 3e01d1e45312f6eb9abde1c616dcb70519f718df [file] [log] [blame]
Steve Dowere1c54f42018-05-30 22:13:43 -07001<#
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#>
27param(
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
39if (-not $build) { throw "-build option is required" }
40if (-not $user) { throw "-user option is required" }
41
Steve Dower74e4aee2018-06-27 08:11:13 -070042if (-not ((Test-Path "$build\win32\python-*.exe") -or (Test-Path "$build\amd64\python-*.exe"))) {
43 throw "-build argument does not look like a 'build' directory"
44}
45
Steve Dowere1c54f42018-05-30 22:13:43 -070046function find-putty-tool {
47 param ([string]$n)
48 $t = gcm $n -EA 0
49 if (-not $t) { $t = gcm ".\$n" -EA 0 }
50 if (-not $t) { $t = gcm "${env:ProgramFiles}\PuTTY\$n" -EA 0 }
51 if (-not $t) { $t = gcm "${env:ProgramFiles(x86)}\PuTTY\$n" -EA 0 }
52 if (-not $t) { throw "Unable to locate $n.exe. Please put it on $PATH" }
53 return gi $t.Path
54}
55
56$p = gci -r "$build\python-*.exe" | `
57 ?{ $_.Name -match '^python-(\d+\.\d+\.\d+)((a|b|rc)\d+)?-.+' } | `
58 select -first 1 | `
59 %{ $Matches[1], $Matches[2] }
60
61"Uploading version $($p[0]) $($p[1])"
62" from: $build"
63" to: $($server):$target/$($p[0])"
Steve Dowere1c54f42018-05-30 22:13:43 -070064""
65
66if (-not $skipupload) {
67 # Upload files to the server
68 $pscp = find-putty-tool "pscp"
69 $plink = find-putty-tool "plink"
70
Steve Dower74e4aee2018-06-27 08:11:13 -070071 "Upload using $pscp and $plink"
72 ""
73
Steve Dowere1c54f42018-05-30 22:13:43 -070074 pushd $build
75 $doc = gci python*.chm, python*.chm.asc
76 popd
77
78 $d = "$target/$($p[0])/"
Steve Dowereeb99bd2018-06-12 14:35:11 -070079 & $plink -batch $user@$server mkdir $d
80 & $plink -batch $user@$server chgrp downloads $d
81 & $plink -batch $user@$server chmod g-x,o+rx $d
Steve Dowere1c54f42018-05-30 22:13:43 -070082 & $pscp -batch $doc.FullName "$user@${server}:$d"
83
84 foreach ($a in gci "$build" -Directory) {
85 "Uploading files from $($a.FullName)"
86 pushd "$($a.FullName)"
87 $exe = gci *.exe, *.exe.asc, *.zip, *.zip.asc
88 $msi = gci *.msi, *.msi.asc, *.msu, *.msu.asc
89 popd
90
91 & $pscp -batch $exe.FullName "$user@${server}:$d"
92
93 $sd = "$d$($a.Name)$($p[1])/"
Steve Dowereeb99bd2018-06-12 14:35:11 -070094 & $plink -batch $user@$server mkdir $sd
95 & $plink -batch $user@$server chgrp downloads $sd
96 & $plink -batch $user@$server chmod g-x,o+rx $sd
Steve Dowere1c54f42018-05-30 22:13:43 -070097 & $pscp -batch $msi.FullName "$user@${server}:$sd"
Steve Dowereeb99bd2018-06-12 14:35:11 -070098 & $plink -batch $user@$server chgrp downloads $sd*
99 & $plink -batch $user@$server chmod g-x,o+r $sd*
Steve Dowere1c54f42018-05-30 22:13:43 -0700100 }
101
Steve Dowereeb99bd2018-06-12 14:35:11 -0700102 & $plink -batch $user@$server chgrp downloads $d*
103 & $plink -batch $user@$server chmod g-x,o+r $d*
Steve Dowere1c54f42018-05-30 22:13:43 -0700104}
105
106if (-not $skippurge) {
107 # Run a CDN purge
108 py purge.py "$($p[0])$($p[1])"
109}
110
111if (-not $skiptest) {
112 # Use each web installer to produce a layout. This will download
113 # each referenced file and validate their signatures/hashes.
114 gci "$build\*-webinstall.exe" -r -File | %{
115 $d = mkdir "$tests\$($_.BaseName)" -Force
116 gci $d -r -File | del
117 $ic = copy $_ $d -PassThru
118 "Checking layout for $($ic.Name)"
119 Start-Process -wait $ic "/passive", "/layout", "$d\layout", "/log", "$d\log\install.log"
120 if (-not $?) {
121 Write-Error "Failed to validate layout of $($inst.Name)"
122 }
123 }
124}
125
126if (-not $skiphash) {
127 # Display MD5 hash and size of each downloadable file
128 pushd $build
129 gci python*.chm, *\*.exe, *\*.zip | `
130 Sort-Object Name | `
131 Format-Table Name, @{Label="MD5"; Expression={(Get-FileHash $_ -Algorithm MD5).Hash}}, Length
132 popd
133}