2015-11-16 11:21:57 -08:00
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#
2015-10-26 18:31:06 -07:00
param (
2015-12-28 11:47:21 -08:00
[ Parameter ( Mandatory = $true ) ] [ string ] $file
2015-10-26 18:31:06 -07:00
)
2016-01-20 18:49:47 -08:00
. " $PSScriptRoot \..\common\_common.ps1 "
2015-10-26 18:31:06 -07:00
function CheckRequiredVariables
2015-11-11 21:54:58 -08:00
{
2016-01-12 15:27:02 -08:00
if ( [ string ] :: IsNullOrEmpty ( $env:DOTNET_CLI_VERSION ) )
2015-11-11 21:54:58 -08:00
{
2015-10-26 18:31:06 -07:00
return $false
2015-10-27 14:26:50 -07:00
}
2015-10-26 18:31:06 -07:00
# this variable is set by the CI system
if ( [ string ] :: IsNullOrEmpty ( $env:SASTOKEN ) )
2015-11-11 21:54:58 -08:00
{
2015-10-26 18:31:06 -07:00
return $false
}
2015-10-27 14:26:50 -07:00
# this variable is set by the CI system
if ( [ string ] :: IsNullOrEmpty ( $env:STORAGE_ACCOUNT ) )
{
return $false
}
# this variable is set by the CI system
if ( [ string ] :: IsNullOrEmpty ( $env:STORAGE_CONTAINER ) )
{
return $false
}
2015-10-28 17:11:32 -07:00
# this variable is set by the CI system
if ( [ string ] :: IsNullOrEmpty ( $env:CHANNEL ) )
{
return $false
}
2015-11-18 08:32:09 -08:00
# this variable is set by the CI system
if ( [ string ] :: IsNullOrEmpty ( $env:CONNECTION_STRING ) )
{
return $false
}
2015-10-26 18:31:06 -07:00
return $true
}
2015-11-18 08:32:09 -08:00
function UploadFile($Blob , $Uploadfile )
2015-10-26 18:31:06 -07:00
{
2015-11-04 19:13:50 -08:00
Write-Host " Uploading $Uploadfile to dotnet feed to.. "
2015-11-18 08:32:09 -08:00
# use azure cli to upload to blob storage. We cannot use Invoke-WebRequest to do this becuase azure has a max limit of 64mb that can be uploaded using REST
#$statusCode = (Invoke-WebRequest -URI "$Upload_URI" -Method PUT -Headers @{"x-ms-blob-type"="BlockBlob"; "x-ms-date"="2015-10-23";"x-ms-version"="2013-08-15"} -InFile $Uploadfile).StatusCode
2015-12-15 19:10:06 -08:00
azure storage blob upload - -quiet - -container $env:STORAGE_CONTAINER - -blob $Blob - -blobtype block - -connection -string " $env:CONNECTION_STRING " - -file $Uploadfile | Out-Host
2015-11-04 19:13:50 -08:00
2015-11-18 08:32:09 -08:00
if ( $LastExitCode -eq 0 )
2015-11-04 19:13:50 -08:00
{
Write-Host " Successfully uploaded $Uploadfile to dotnet feed. "
return $true
}
else
{
Write-Host " Failed to upload $Uploadfile to dotnet feed. "
return $false
}
2015-10-26 18:31:06 -07:00
}
2015-11-04 19:13:50 -08:00
function UploadBinaries($zipFile )
2015-10-26 18:31:06 -07:00
{
2015-11-04 19:13:50 -08:00
$result = -1
$fileName = [ System.IO.Path ] :: GetFileName ( $zipFile )
2016-01-12 15:27:02 -08:00
$zipBlob = " $env:CHANNEL /Binaries/ $env:DOTNET_CLI_VERSION / $fileName "
2015-10-26 18:31:06 -07:00
2015-11-18 08:32:09 -08:00
if ( -Not ( UploadFile $zipBlob $zipFile ) )
2015-11-04 19:13:50 -08:00
{
2015-11-06 17:06:55 -08:00
return -1
2015-11-04 19:13:50 -08:00
}
2015-10-26 18:31:06 -07:00
2015-11-06 17:06:55 -08:00
Write-Host " Updating the latest dotnet binaries for windows.. "
2015-11-18 08:32:09 -08:00
$zipBlobLatest = " $env:CHANNEL /Binaries/Latest/dotnet-win-x64.latest.zip "
2015-11-06 17:06:55 -08:00
2015-11-18 08:32:09 -08:00
if ( -Not ( UploadFile $zipBlobLatest $zipFile ) )
2015-11-06 17:06:55 -08:00
{
return -1
}
# update the index file too
2016-01-12 15:27:02 -08:00
$indexContent = " Binaries/ $env:DOTNET_CLI_VERSION / $fileName "
2015-11-06 17:06:55 -08:00
$indexFile = " $env:TEMP \latest.win.index "
$indexContent | Out-File -FilePath $indexFile
# upload the index file
2015-11-18 08:32:09 -08:00
$indexBlob = " $env:CHANNEL /dnvm/latest.win.index "
2015-11-06 17:06:55 -08:00
2015-11-18 08:32:09 -08:00
if ( -Not ( UploadFile $indexBlob $indexFile ) )
2015-11-06 17:06:55 -08:00
{
return -1
}
2015-11-11 13:37:55 -08:00
# update the version file
2015-11-10 17:30:01 -08:00
$versionFile = Convert-Path $PSScriptRoot \ . . \ . . \ artifacts \ win7-x64 \ stage2 \ . version
2015-11-18 08:32:09 -08:00
$versionBlob = " $env:CHANNEL /dnvm/latest.win.version "
2015-11-11 13:37:55 -08:00
2015-11-18 08:32:09 -08:00
if ( -Not ( UploadFile $versionBlob $versionFile ) )
2015-11-11 13:37:55 -08:00
{
return -1
}
2015-11-06 17:06:55 -08:00
return 0
2015-10-26 18:31:06 -07:00
}
2015-11-04 19:13:50 -08:00
function UploadInstallers($msiFile )
2015-10-26 18:31:06 -07:00
{
2015-11-04 19:13:50 -08:00
$fileName = [ System.IO.Path ] :: GetFileName ( $msiFile )
2016-01-12 15:27:02 -08:00
$msiBlob = " $env:CHANNEL /Installers/ $env:DOTNET_CLI_VERSION / $fileName "
2015-10-26 18:31:06 -07:00
2015-11-18 08:32:09 -08:00
if ( -Not ( UploadFile $msiBlob $msiFile ) )
2015-11-06 17:06:55 -08:00
{
return -1
}
Write-Host " Updating the latest dotnet installer for windows.. "
2015-11-18 08:32:09 -08:00
$msiBlobLatest = " $env:CHANNEL /Installers/Latest/dotnet-win-x64.latest.msi "
2015-11-06 17:06:55 -08:00
2015-11-18 08:32:09 -08:00
if ( -Not ( UploadFile $msiBlobLatest $msiFile ) )
2015-11-04 19:13:50 -08:00
{
2015-11-06 17:06:55 -08:00
return -1
2015-11-04 19:13:50 -08:00
}
2015-10-26 18:31:06 -07:00
2015-11-06 17:06:55 -08:00
return 0
2015-11-04 19:13:50 -08:00
}
2015-10-26 18:31:06 -07:00
2016-01-27 22:35:38 -08:00
function UploadVersionBadge($badgeFile )
{
2016-01-29 09:06:12 -08:00
$fileName = " windows_ $Configuration_ $( [ System.IO.Path ] :: GetFileName ( $badgeFile ) ) "
2016-01-27 22:35:38 -08:00
Write-Host " Uploading the version badge to Latest "
UploadFile " dev/Binaries/Latest/ $filename " $badgeFile
Write-Host " Uploading the version badge to $env:DOTNET_CLI_VERSION "
UploadFile " dev/Binaries/ $env:DOTNET_CLI_VERSION / $filename " $badgeFile
2016-01-28 07:03:41 -08:00
return 0
2016-01-27 22:35:38 -08:00
}
2015-11-04 19:13:50 -08:00
if ( ! ( CheckRequiredVariables ) )
{
# fail silently if the required variables are not available for publishing the file
exit 0
}
2015-10-27 14:26:50 -07:00
2015-11-04 19:13:50 -08:00
if ( ! [ System.IO.File ] :: Exists ( $file ) )
{
throw " $file not found "
}
2015-10-26 18:31:06 -07:00
2015-11-04 19:13:50 -08:00
$result = $false
2015-10-26 18:31:06 -07:00
2015-11-04 19:13:50 -08:00
if ( [ System.IO.Path ] :: GetExtension ( $file ) . ToLower ( ) -eq " .zip " )
2015-10-26 18:31:06 -07:00
{
2015-11-04 19:13:50 -08:00
$result = UploadBinaries $file
2015-10-26 18:31:06 -07:00
}
2015-11-04 19:13:50 -08:00
elseif ( [ System.IO.Path ] :: GetExtension ( $file ) . ToLower ( ) -eq " .msi " )
2015-10-26 18:31:06 -07:00
{
2015-11-04 19:13:50 -08:00
$result = UploadInstallers $file
2015-10-26 18:31:06 -07:00
}
2016-01-27 22:00:58 -08:00
elseif ( [ System.IO.Path ] :: GetExtension ( $file ) . ToLower ( ) -eq " .svg " )
{
2016-01-28 07:03:41 -08:00
$result = UploadVersionBadge $file
2016-01-27 22:00:58 -08:00
}
2015-10-26 18:31:06 -07:00
2015-11-04 19:13:50 -08:00
exit $result