blob: 6dcd7525e17f30e349f38dcc857465bd5b595a57 [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
42function 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
63if (-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])/"
Steve Dowereeb99bd2018-06-12 14:35:11 -070073 & $plink -batch $user@$server mkdir $d
74 & $plink -batch $user@$server chgrp downloads $d
75 & $plink -batch $user@$server chmod g-x,o+rx $d
Steve Dowere1c54f42018-05-30 22:13:43 -070076 & $pscp -batch $doc.FullName "$user@${server}:$d"
77
78 foreach ($a in gci "$build" -Directory) {
79 "Uploading files from $($a.FullName)"
80 pushd "$($a.FullName)"
81 $exe = gci *.exe, *.exe.asc, *.zip, *.zip.asc
82 $msi = gci *.msi, *.msi.asc, *.msu, *.msu.asc
83 popd
84
85 & $pscp -batch $exe.FullName "$user@${server}:$d"
86
87 $sd = "$d$($a.Name)$($p[1])/"
Steve Dowereeb99bd2018-06-12 14:35:11 -070088 & $plink -batch $user@$server mkdir $sd
89 & $plink -batch $user@$server chgrp downloads $sd
90 & $plink -batch $user@$server chmod g-x,o+rx $sd
Steve Dowere1c54f42018-05-30 22:13:43 -070091 & $pscp -batch $msi.FullName "$user@${server}:$sd"
Steve Dowereeb99bd2018-06-12 14:35:11 -070092 & $plink -batch $user@$server chgrp downloads $sd*
93 & $plink -batch $user@$server chmod g-x,o+r $sd*
Steve Dowere1c54f42018-05-30 22:13:43 -070094 }
95
Steve Dowereeb99bd2018-06-12 14:35:11 -070096 & $plink -batch $user@$server chgrp downloads $d*
97 & $plink -batch $user@$server chmod g-x,o+r $d*
Steve Dowere1c54f42018-05-30 22:13:43 -070098}
99
100if (-not $skippurge) {
101 # Run a CDN purge
102 py purge.py "$($p[0])$($p[1])"
103}
104
105if (-not $skiptest) {
106 # Use each web installer to produce a layout. This will download
107 # each referenced file and validate their signatures/hashes.
108 gci "$build\*-webinstall.exe" -r -File | %{
109 $d = mkdir "$tests\$($_.BaseName)" -Force
110 gci $d -r -File | del
111 $ic = copy $_ $d -PassThru
112 "Checking layout for $($ic.Name)"
113 Start-Process -wait $ic "/passive", "/layout", "$d\layout", "/log", "$d\log\install.log"
114 if (-not $?) {
115 Write-Error "Failed to validate layout of $($inst.Name)"
116 }
117 }
118}
119
120if (-not $skiphash) {
121 # Display MD5 hash and size of each downloadable file
122 pushd $build
123 gci python*.chm, *\*.exe, *\*.zip | `
124 Sort-Object Name | `
125 Format-Table Name, @{Label="MD5"; Expression={(Get-FileHash $_ -Algorithm MD5).Hash}}, Length
126 popd
127}