kiwix-js-pwa/scripts/Push-KiwixRelease.ps1
renaud gaudin 3de5c2d3a2 Fixed build uploads
Changes the destination of uploads to master.download.kiwix.org on port 30022
As this service doesn't offer a shell anymore, converted the folder creation
and file renamings to more verbose, SFTP-based scripts.
---


Former-commit-id: 4173c0fa0b793931d5e15a7d39e3a2d14063f3c2 [formerly b0cf21f9ed35aa38c1cd0270f9a6ca3ed7f61caf] [formerly ff9a715eca41430f60697e57f284e3b64523e9f3] [formerly 58f9e5893e5d47ffbf0ee2a99253320945a3537b [formerly 6e468b5130bbb35f098121b6095987c59d77f634 [formerly 9f6018b27ee96d7f86e583aab170ea7babdf09cc]]]
Former-commit-id: c23f42c726cfdc8430661f093e63f4ecadfc74a8 [formerly 98f54ef911581b8927e29b59780dc79f11da0155 [formerly 84b32b2148c8db3e936c243c1dd795e04a4f68ae]]
Former-commit-id: 4732e5bfd600646015d9ddc5598ef76487103c97 [formerly c906eb55103256bfaaa8e7b83bd63d1f7df84025]
Former-commit-id: ab83883aa1edddc293cf823ceefb150517fc44b2
2022-04-06 10:56:23 +00:00

92 lines
3.6 KiB
PowerShell

param (
[string]$filename = "",
[switch]$tag = $false,
[switch]$dryrun = $false,
[switch]$yes = $false,
[switch]$help = $false
)
function Main {
# Deal with cases where no directory or filename is entered
if (($filename -eq "") -and (!$help)) {
$filename = Read-Host "Enter the filename to upload to download.kiwix.org/releases/ or ? for help"
if ($filename -eq "") {
exit
}
' '
}
# Check whether user asked for help
if (($filename -eq "?") -or ($help)) {
Get-PushHelp
exit
}
# Construct the filename if a tag was entered
if ($tag) {
$tagname = $filename -replace '^v', ''
$filename = dir "$PSScriptRoot/../AppPackages/*_$tagname*_Test/*_$tagname*.appx*"
if ($filename -and $filename.count -eq 1) {
"Setting file to $filename..."
} elseif ($filename.count -ge 2) {
"More than one file matches that tag!"
return
} else {
"No package matching that tag was found. Aborting."
return
}
}
# If the path is a file of the right type, ask for confirmation
if ((Test-Path $filename -PathType leaf) -and ($filename -imatch '(.*)\.(?:appx|appxbundle|appxupload)$')) {
$newfilename = $filename -ireplace '^.*\\[^\d]+([\d.]+?)\.0_[^\d]+?(\.appx(?:bundle|upload))$', 'kiwix-js-windows_$1$2'
$filename = $filename -ireplace '[\\/]', '/'
$file = $filename -ireplace '^.*/([^/]+$)', '$1'
$target = '/data/download/release/kiwix-js-windows'
"$filename is ready to upload to $target ..."
if ($dryrun) { "DRY RUN: no upload will be made" }
if (! $yes) {
$response = Read-Host "Do you wish to proceed? Y/N"
if ($response -ne "Y") {
"Aborting upload because user cancelled."
exit
}
}
$keyfile = "$PSScriptRoot\ssh_key"
$keyfile = $keyfile -ireplace '[\\/]', '/'
if ($dryrun) {
"C:\Program Files\Git\usr\bin\scp.exe -P 30022 -o StrictHostKeyChecking=no -i $keyfile $filename ci@master.download.kiwix.org:$target"
"echo 'rename $target/$file $target/$newfilename' | C:\Program Files\Git\usr\bin\sftp.exe -P 30022 -o StrictHostKeyChecking=no -i $keyfile ci@master.download.kiwix.org"
"Aborting because this is a dry run."
exit
}
# Uploading file
# Move-Item $filename $originalpath/$newfilename
& "C:\Program Files\Git\usr\bin\scp.exe" @('-P', '30022', '-o', 'StrictHostKeyChecking=no', '-i', "$keyfile", "$filename", "ci@master.download.kiwix.org:$target")
echo "rename $target/$file $target/$newfilename" | & "C:\Program Files\Git\usr\bin\sftp.exe" @('-P', '30022', '-o', 'StrictHostKeyChecking=no', '-i', "$keyfile", 'ci@master.download.kiwix.org')
"Done."
} else {
"You can only upload a file of type .appx, .appxbundle or .appxupload"
exit
}
}
function Get-PushHelp {
@"
Usage: .\Push-KiwixRelease FILENAME|TAG or ? [-dryrun] [-tag] [-yes] [-help]
Uploads a UWP app release to download.kiwix.org/releases/
FILENAME|TAG the filename to upload (must be .appx, .appxupload, .appxbundle),
or ? or the TAG name (if -tag is set), or ? for help
-dryrun tests that the file exists and is of the right type, but does not
upload it
-tag indicates that a tag name has been supplied rather than a file
-yes skip confirmation of upload
-help prints these instructions
"@
}
Main