blob: d3673b4582983c9c7c54646638ce49aebfb89a12 [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 Dowerfe330fc2019-07-29 11:22:27 -070095 if (-not $?) { throw "Failed to upload $chm" }
Steve Dowere1c54f42018-05-30 22:13:43 -070096
Steve Dower21a92f82019-06-14 08:29:20 -070097 $dirs = gci "$build" -Directory
98 if ($embed) {
99 $dirs = ($dirs, (gi $embed)) | %{ $_ }
100 }
101
102 foreach ($a in $dirs) {
Steve Dowere1c54f42018-05-30 22:13:43 -0700103 "Uploading files from $($a.FullName)"
104 pushd "$($a.FullName)"
105 $exe = gci *.exe, *.exe.asc, *.zip, *.zip.asc
106 $msi = gci *.msi, *.msi.asc, *.msu, *.msu.asc
107 popd
108
Steve Dower21a92f82019-06-14 08:29:20 -0700109 if ($exe) {
110 & $pscp -batch $exe.FullName "$user@${server}:$d"
Steve Dowerfe330fc2019-07-29 11:22:27 -0700111 if (-not $?) { throw "Failed to upload $exe" }
Steve Dower21a92f82019-06-14 08:29:20 -0700112 }
Steve Dowere1c54f42018-05-30 22:13:43 -0700113
Steve Dower21a92f82019-06-14 08:29:20 -0700114 if ($msi) {
115 $sd = "$d$($a.Name)$($p[1])/"
116 & $plink -batch $user@$server mkdir $sd
117 & $plink -batch $user@$server chgrp downloads $sd
118 & $plink -batch $user@$server chmod g-x,o+rx $sd
119 & $pscp -batch $msi.FullName "$user@${server}:$sd"
Steve Dowerfe330fc2019-07-29 11:22:27 -0700120 if (-not $?) { throw "Failed to upload $msi" }
Steve Dower21a92f82019-06-14 08:29:20 -0700121 & $plink -batch $user@$server chgrp downloads $sd*
122 & $plink -batch $user@$server chmod g-x,o+r $sd*
123 }
Steve Dowere1c54f42018-05-30 22:13:43 -0700124 }
125
Steve Dowereeb99bd2018-06-12 14:35:11 -0700126 & $plink -batch $user@$server chgrp downloads $d*
127 & $plink -batch $user@$server chmod g-x,o+r $d*
Steve Dowerfe330fc2019-07-29 11:22:27 -0700128 & $pscp -ls "$user@${server}:$d"
Steve Dowere1c54f42018-05-30 22:13:43 -0700129}
130
131if (-not $skippurge) {
132 # Run a CDN purge
Steve Dowera486a472018-10-13 10:10:42 -0700133 py $tools\purge.py "$($p[0])$($p[1])"
Steve Dowere1c54f42018-05-30 22:13:43 -0700134}
135
136if (-not $skiptest) {
137 # Use each web installer to produce a layout. This will download
138 # each referenced file and validate their signatures/hashes.
139 gci "$build\*-webinstall.exe" -r -File | %{
140 $d = mkdir "$tests\$($_.BaseName)" -Force
141 gci $d -r -File | del
142 $ic = copy $_ $d -PassThru
143 "Checking layout for $($ic.Name)"
144 Start-Process -wait $ic "/passive", "/layout", "$d\layout", "/log", "$d\log\install.log"
145 if (-not $?) {
146 Write-Error "Failed to validate layout of $($inst.Name)"
147 }
148 }
149}
150
151if (-not $skiphash) {
152 # Display MD5 hash and size of each downloadable file
153 pushd $build
Steve Dower21a92f82019-06-14 08:29:20 -0700154 $files = gci python*.chm, *\*.exe, *\*.zip
155 if ($doc_htmlhelp) {
156 cd $doc_htmlhelp
157 $files = ($files, (gci python*.chm)) | %{ $_ }
158 }
159 if ($embed) {
160 cd $embed
161 $files = ($files, (gci *.zip)) | %{ $_ }
162 }
163 popd
164
165 $hashes = $files | `
Steve Dowere1c54f42018-05-30 22:13:43 -0700166 Sort-Object Name | `
Steve Dowera486a472018-10-13 10:10:42 -0700167 Format-Table Name, @{Label="MD5"; Expression={(Get-FileHash $_ -Algorithm MD5).Hash}}, Length -AutoSize | `
168 Out-String -Width 4096
169 $hashes | clip
170 $hashes
Steve Dowere1c54f42018-05-30 22:13:43 -0700171}