From d2f7624e0017bcc2bd3452b483aaf518b053fcb4 Mon Sep 17 00:00:00 2001 From: Sridhar Periyasamy Date: Mon, 26 Oct 2015 18:31:06 -0700 Subject: [PATCH] Changes to push windows artifacts into the dotnet blob storage - Use timestamp of last git commit as build numbers - Push the generated zip/msi files into dotnet blob storage --- build.cmd | 7 +++++ scripts/package.ps1 | 6 +++++ scripts/publish.ps1 | 62 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 scripts/publish.ps1 diff --git a/build.cmd b/build.cmd index 63d7b155e..7a7bb7e96 100644 --- a/build.cmd +++ b/build.cmd @@ -1,6 +1,13 @@ @echo off setlocal EnableDelayedExpansion + +REM UTC Timestamp of the last commit is used as the build number. This is for easy synchronization of build number between Windows, OSX and Linux builds. +REM Using powershell is way easier to retrive and format the timestamp in any way we want. +set LAST_COMMIT_TIMESTAMP=powershell -Command "& { $timestamp = git log -1 --format=%%ct ; $origin = New-Object -Type DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0; $commitTime = $origin.AddSeconds($timestamp); echo $commitTime.ToString(\"yyyyMMdd-HHmmss\");}" + +for /f %%i in ('%LAST_COMMIT_TIMESTAMP%') do set DOTNET_BUILD_VERSION=0.0.1-alpha-%%i + where dnvm if %ERRORLEVEL% neq 0 ( @powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}" diff --git a/scripts/package.ps1 b/scripts/package.ps1 index 66d9bca67..1d221e70b 100644 --- a/scripts/package.ps1 +++ b/scripts/package.ps1 @@ -20,3 +20,9 @@ Add-Type -Assembly System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::CreateFromDirectory($Stage2Dir, $PackageName, "Optimal", $false) Write-Host "Packaged stage2 to $PackageName" + + +$PublishScript = Join-Path $PSScriptRoot "publish.ps1" +& $PublishScript -file $PackageName + +exit $LastExitCode diff --git a/scripts/publish.ps1 b/scripts/publish.ps1 new file mode 100644 index 000000000..01cb8c4c6 --- /dev/null +++ b/scripts/publish.ps1 @@ -0,0 +1,62 @@ +param( + [string]$file = $(throw "Specify the full path to the file to be uploaded") +) + +function CheckRequiredVariables +{ + if([string]::IsNullOrEmpty($env:DOTNET_BUILD_VERSION)) + { + return $false + } + + # this variable is set by the CI system + if([string]::IsNullOrEmpty($env:SASTOKEN)) + { + return $false + } + + return $true +} + +$Result = CheckRequiredVariables + + +if(!$Result) +{ + # fail silently if the required variables are not available for publishing the file. + exit 0 +} + +if(![System.IO.File]::Exists($file)) +{ + throw "$file not found" +} + +$fileName = [System.IO.Path]::GetFileName($file) + +if([System.IO.Path]::GetExtension($file).ToLower() -eq ".zip") +{ + $Folder = "Binaries" +} +elseif([System.IO.Path]::GetExtension($file).ToLower() -eq ".msi") +{ + $Folder = "Installers" +} + + +Write-Host "Uploading $fileName to dotnet feed.." + +Invoke-WebRequest -URI "https://dotnetcli.blob.core.windows.net/dotnet/$Folder/$env:DOTNET_BUILD_VERSION/$fileName$env:SASTOKEN" -Method PUT -Headers @{"x-ms-blob-type"="BlockBlob"; "x-ms-date"="2015-10-23";"x-ms-version"="2013-08-15"} -InFile $file + +$ReturnCode = $LASTEXITCODE + +if($ReturnCode -eq 0) +{ + Write-Host "Successfully uploaded $file to dotnet feed." +} +{ + Write-Host "Failed to upload $file to dotnet feed." +} + +exit $ReturnCode +