blob: b6fbeea29810097c1b45f6130d167a4d6bbe4a39 [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.
Steve Dower21a92f82019-06-14 08:29:20 -070018.Parameter doc_htmlhelp
19 Optional path besides -build to locate CHM files.
20.Parameter embed
21 Optional path besides -build to locate ZIP files.
Steve Dowere1c54f42018-05-30 22:13:43 -070022.Parameter skipupload
23 Skip uploading
24.Parameter skippurge
25 Skip purging the CDN
26.Parameter skiptest
27 Skip the download tests
28.Parameter skiphash
29 Skip displaying hashes
30#>
31param(
32 [Parameter(Mandatory=$true)][string]$build,
33 [Parameter(Mandatory=$true)][string]$user,
34 [string]$server="python-downloads",
35 [string]$target="/srv/www.python.org/ftp/python",
36 [string]$tests=${env:TEMP},
Steve Dower21a92f82019-06-14 08:29:20 -070037 [string]$doc_htmlhelp=$null,
38 [string]$embed=$null,
Steve Dowere1c54f42018-05-30 22:13:43 -070039 [switch]$skipupload,
40 [switch]$skippurge,
41 [switch]$skiptest,
42 [switch]$skiphash
43)
44
45if (-not $build) { throw "-build option is required" }
46if (-not $user) { throw "-user option is required" }
47
Steve Dowera486a472018-10-13 10:10:42 -070048$tools = $script:MyInvocation.MyCommand.Path | Split-Path -parent;
49
Steve Dower74e4aee2018-06-27 08:11:13 -070050if (-not ((Test-Path "$build\win32\python-*.exe") -or (Test-Path "$build\amd64\python-*.exe"))) {
51 throw "-build argument does not look like a 'build' directory"
52}
53
Steve Dowere1c54f42018-05-30 22:13:43 -070054function find-putty-tool {
55 param ([string]$n)
56 $t = gcm $n -EA 0
57 if (-not $t) { $t = gcm ".\$n" -EA 0 }
58 if (-not $t) { $t = gcm "${env:ProgramFiles}\PuTTY\$n" -EA 0 }
59 if (-not $t) { $t = gcm "${env:ProgramFiles(x86)}\PuTTY\$n" -EA 0 }
60 if (-not $t) { throw "Unable to locate $n.exe. Please put it on $PATH" }
61 return gi $t.Path
62}
63
64$p = gci -r "$build\python-*.exe" | `
65 ?{ $_.Name -match '^python-(\d+\.\d+\.\d+)((a|b|rc)\d+)?-.+' } | `
66 select -first 1 | `
67 %{ $Matches[1], $Matches[2] }
68
69"Uploading version $($p[0]) $($p[1])"
70" from: $build"
71" to: $($server):$target/$($p[0])"
Steve Dowere1c54f42018-05-30 22:13:43 -070072""
73
74if (-not $skipupload) {
75 # Upload files to the server
76 $pscp = find-putty-tool "pscp"
77 $plink = find-putty-tool "plink"
78
Steve Dower74e4aee2018-06-27 08:11:13 -070079 "Upload using $pscp and $plink"
80 ""
81
Steve Dower21a92f82019-06-14 08:29:20 -070082 if ($doc_htmlhelp) {
83 pushd $doc_htmlhelp
84 } else {
85 pushd $build
86 }
87 $chm = gci python*.chm, python*.chm.asc
Steve Dowere1c54f42018-05-30 22:13:43 -070088 popd
89
90 $d = "$target/$($p[0])/"
Steve Dowereeb99bd2018-06-12 14:35:11 -070091 & $plink -batch $user@$server mkdir $d
92 & $plink -batch $user@$server chgrp downloads $d
93 & $plink -batch $user@$server chmod g-x,o+rx $d
Steve Dower21a92f82019-06-14 08:29:20 -070094 & $pscp -batch $chm.FullName "$user@${server}:$d"
Steve Dowere1c54f42018-05-30 22:13:43 -070095
Steve Dower21a92f82019-06-14 08:29:20 -070096 $dirs = gci "$build" -Directory
97 if ($embed) {
98 $dirs = ($dirs, (gi $embed)) | %{ $_ }
99 }
100
101 foreach ($a in $dirs) {
Steve Dowere1c54f42018-05-30 22:13:43 -0700102 "Uploading files from $($a.FullName)"
103 pushd "$($a.FullName)"
104 $exe = gci *.exe, *.exe.asc, *.zip, *.zip.asc
105 $msi = gci *.msi, *.msi.asc, *.msu, *.msu.asc
106 popd
107
Steve Dower21a92f82019-06-14 08:29:20 -0700108 if ($exe) {
109 & $pscp -batch $exe.FullName "$user@${server}:$d"
110 }
Steve Dowere1c54f42018-05-30 22:13:43 -0700111
Steve Dower21a92f82019-06-14 08:29:20 -0700112 if ($msi) {
113 $sd = "$d$($a.Name)$($p[1])/"
114 & $plink -batch $user@$server mkdir $sd
115 & $plink -batch $user@$server chgrp downloads $sd
116 & $plink -batch $user@$server chmod g-x,o+rx $sd
117 & $pscp -batch $msi.FullName "$user@${server}:$sd"
118 & $plink -batch $user@$server chgrp downloads $sd*
119 & $plink -batch $user@$server chmod g-x,o+r $sd*
120 }
Steve Dowere1c54f42018-05-30 22:13:43 -0700121 }
122
Steve Dowereeb99bd2018-06-12 14:35:11 -0700123 & $plink -batch $user@$server chgrp downloads $d*
124 & $plink -batch $user@$server chmod g-x,o+r $d*
Steve Dowere1c54f42018-05-30 22:13:43 -0700125}
126
127if (-not $skippurge) {
128 # Run a CDN purge
Steve Dowera486a472018-10-13 10:10:42 -0700129 py $tools\purge.py "$($p[0])$($p[1])"
Steve Dowere1c54f42018-05-30 22:13:43 -0700130}
131
132if (-not $skiptest) {
133 # Use each web installer to produce a layout. This will download
134 # each referenced file and validate their signatures/hashes.
135 gci "$build\*-webinstall.exe" -r -File | %{
136 $d = mkdir "$tests\$($_.BaseName)" -Force
137 gci $d -r -File | del
138 $ic = copy $_ $d -PassThru
139 "Checking layout for $($ic.Name)"
140 Start-Process -wait $ic "/passive", "/layout", "$d\layout", "/log", "$d\log\install.log"
141 if (-not $?) {
142 Write-Error "Failed to validate layout of $($inst.Name)"
143 }
144 }
145}
146
147if (-not $skiphash) {
148 # Display MD5 hash and size of each downloadable file
149 pushd $build
Steve Dower21a92f82019-06-14 08:29:20 -0700150 $files = gci python*.chm, *\*.exe, *\*.zip
151 if ($doc_htmlhelp) {
152 cd $doc_htmlhelp
153 $files = ($files, (gci python*.chm)) | %{ $_ }
154 }
155 if ($embed) {
156 cd $embed
157 $files = ($files, (gci *.zip)) | %{ $_ }
158 }
159 popd
160
161 $hashes = $files | `
Steve Dowere1c54f42018-05-30 22:13:43 -0700162 Sort-Object Name | `
Steve Dowera486a472018-10-13 10:10:42 -0700163 Format-Table Name, @{Label="MD5"; Expression={(Get-FileHash $_ -Algorithm MD5).Hash}}, Length -AutoSize | `
164 Out-String -Width 4096
165 $hashes | clip
166 $hashes
Steve Dowere1c54f42018-05-30 22:13:43 -0700167 popd
168}