Merge pull request #105 from Sridhar-MS/ci-publish-to-feeds
Changes to push windows artifacts into the dotnet blob storage
This commit is contained in:
commit
92edf782a2
7 changed files with 152 additions and 24 deletions
|
@ -1,5 +1,12 @@
|
|||
|
||||
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'))}"
|
||||
|
|
4
build.sh
4
build.sh
|
@ -12,5 +12,9 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
|
|||
done
|
||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||
|
||||
# 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.
|
||||
LAST_COMMIT_TIMESTAMP=$(git log -1 --format=%ct)
|
||||
export DOTNET_BUILD_VERSION=0.0.1-alpha-$(date -ud @$LAST_COMMIT_TIMESTAMP "+%Y%m%d-%H%M%S")
|
||||
|
||||
$DIR/scripts/bootstrap.sh
|
||||
$DIR/scripts/package.sh $1
|
||||
|
|
|
@ -67,3 +67,6 @@ test_debian_package(){
|
|||
}
|
||||
|
||||
execute
|
||||
|
||||
DEBIAN_FILE=$(find $PACKAGE_OUTPUT_DIR -iname "*.deb")
|
||||
$DIR/publish.sh $DEBIAN_FILE
|
||||
|
|
|
@ -63,4 +63,6 @@ find . -type f ! -name "*.*" | xargs chmod 755
|
|||
# Tar up the stage2 artifacts
|
||||
tar -czf $PACKAGE_NAME *
|
||||
|
||||
echo "Packaged stage2 to $PACKAGE_NAME"
|
||||
echo "Packaged stage2 to $PACKAGE_NAME"
|
||||
|
||||
$DIR/publish.sh $PACKAGE_NAME
|
||||
|
|
|
@ -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
|
||||
|
|
76
scripts/publish.ps1
Normal file
76
scripts/publish.ps1
Normal file
|
@ -0,0 +1,76 @@
|
|||
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
|
||||
}
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
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.."
|
||||
|
||||
$Upload_URI = "https://$env:STORAGE_ACCOUNT.blob.core.windows.net/$env:STORAGE_CONTAINER/$Folder/$env:DOTNET_BUILD_VERSION/$fileName$env:SASTOKEN"
|
||||
|
||||
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 $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
|
||||
|
|
@ -1,59 +1,89 @@
|
|||
#!/bin/bash
|
||||
# This is a simple script to push the deb package to our private corpnet feed
|
||||
#
|
||||
# Usage: publish_package.sh [deb file]
|
||||
# Requires: Azure Cli installed (for uploading to blob storage)
|
||||
# Usage: publish.sh [file to be uploaded]
|
||||
#
|
||||
# Environment Dependencies:
|
||||
# $STORAGE_CONTAINER_NAME
|
||||
# $STORAGE_CONTAINER
|
||||
# $STORAGE_ACCOUNT
|
||||
# $STORAGE_KEY
|
||||
# $SASTOKEN
|
||||
# $REPO_ID
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
DEB_FILE=$1
|
||||
UPLOAD_FILE=$1
|
||||
UPLOAD_JSON_FILE="package_upload.json"
|
||||
|
||||
execute(){
|
||||
if ! validate_inputs; then
|
||||
if ! validate_env_variables; then
|
||||
# fail silently if the required variables are not available for publishing the file.
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ ! -f "$UPLOAD_FILE" ]]; then
|
||||
echo "Error: \"$UPLOAD_FILE\" file does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
upload_deb_to_blob_storage
|
||||
generate_repoclient_json
|
||||
call_repo_client
|
||||
if ! upload_file_to_blob_storage; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# debain packages need to be uploaded to the PPA feed too
|
||||
if [[ $UPLOAD_FILE == *.deb ]]; then
|
||||
DEB_FILE=$UPLOAD_FILE
|
||||
generate_repoclient_json
|
||||
call_repo_client
|
||||
fi
|
||||
}
|
||||
|
||||
validate_inputs(){
|
||||
validate_env_variables(){
|
||||
local ret=0
|
||||
if [[ ! -f "$DEB_FILE" ]]; then
|
||||
echo "Error: .deb file does not exist"
|
||||
|
||||
if [[ -z "$DOTNET_BUILD_VERSION" ]]; then
|
||||
echo "DOTNET_BUILD_VERSION environment variable not set"
|
||||
ret=1
|
||||
fi
|
||||
if [[ -z "$STORAGE_CONTAINER" ]]; then
|
||||
echo "Error: STORAGE_CONTAINER environment variable not set"
|
||||
|
||||
if [[ -z "$SASTOKEN" ]]; then
|
||||
echo "SASTOKEN environment variable not set"
|
||||
ret=1
|
||||
fi
|
||||
|
||||
if [[ -z "$STORAGE_ACCOUNT" ]]; then
|
||||
echo "Error: STORAGE_ACCOUNT environment variable not set"
|
||||
echo "STORAGE_ACCOUNT environment variable not set"
|
||||
ret=1
|
||||
fi
|
||||
|
||||
if [[ -z "$STORAGE_KEY" ]]; then
|
||||
echo "Error: STORAGE_KEY environment variable not set"
|
||||
if [[ -z "$STORAGE_CONTAINER" ]]; then
|
||||
echo "STORAGE_CONTAINER environment variable not set"
|
||||
ret=1
|
||||
fi
|
||||
|
||||
return $ret
|
||||
}
|
||||
|
||||
upload_deb_to_blob_storage(){
|
||||
local deb_filename=$(basename $DEB_FILE)
|
||||
azure storage blob upload $DEB_FILE $STORAGE_CONTAINER $deb_filename -a $STORAGE_ACCOUNT -k $STORAGE_KEY
|
||||
upload_file_to_blob_storage(){
|
||||
|
||||
UPLOAD_URL="http://$STORAGE_ACCOUNT.blob.core.windows.net/$STORAGE_CONTAINER/$deb_filename"
|
||||
local filename=$(basename $UPLOAD_FILE)
|
||||
|
||||
if [[ $filename == *.deb || $filename == *.pkg ]]; then
|
||||
FOLDER="Installers"
|
||||
elif [[ $filename == *.tar.gz ]]; then
|
||||
FOLDER="Binaries"
|
||||
fi
|
||||
|
||||
UPLOAD_URL="https://$STORAGE_ACCOUNT.blob.core.windows.net/$STORAGE_CONTAINER/$FOLDER/$DOTNET_BUILD_VERSION/$filename$SASTOKEN"
|
||||
|
||||
curl -L -H "x-ms-blob-type: BlockBlob" -H "x-ms-date: 2015-10-21" -H "x-ms-version: 2013-08-15" $UPLOAD_URL -T $UPLOAD_FILE
|
||||
result=$?
|
||||
|
||||
if [ "$result" -gt "0" ]; then
|
||||
echo "Error: Uploading the $filename to blob storage - $result"
|
||||
else
|
||||
echo "Successfully uploaded $filename to blob storage."
|
||||
fi
|
||||
|
||||
return $result
|
||||
}
|
||||
|
||||
generate_repoclient_json(){
|
||||
|
@ -89,4 +119,4 @@ _get_package_version(){
|
|||
echo $package_version
|
||||
}
|
||||
|
||||
execute
|
||||
execute
|
||||
|
|
Loading…
Reference in a new issue