Merge pull request #152 from Sridhar-MS/publish-index
Automatically update the index in the blob storage for windows.
This commit is contained in:
commit
75ef96aaf8
2 changed files with 134 additions and 53 deletions
|
@ -35,14 +35,68 @@ function CheckRequiredVariables
|
||||||
|
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
|
|
||||||
$Result = CheckRequiredVariables
|
|
||||||
|
|
||||||
|
function UploadFile($Upload_URI, $Uploadfile)
|
||||||
|
{
|
||||||
|
Write-Host "Uploading $Uploadfile to dotnet feed to.."
|
||||||
|
|
||||||
if(!$Result)
|
$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
|
||||||
|
|
||||||
|
if($statusCode -eq 201)
|
||||||
|
{
|
||||||
|
Write-Host "Successfully uploaded $Uploadfile to dotnet feed."
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Host "Failed to upload $Uploadfile to dotnet feed."
|
||||||
|
return $false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function UploadBinaries($zipFile)
|
||||||
|
{
|
||||||
|
$result = -1
|
||||||
|
$fileName = [System.IO.Path]::GetFileName($zipFile)
|
||||||
|
$Upload_URI = "https://$env:STORAGE_ACCOUNT.blob.core.windows.net/$env:STORAGE_CONTAINER/$env:CHANNEL/Binaries/$env:DOTNET_BUILD_VERSION/$fileName$env:SASTOKEN"
|
||||||
|
|
||||||
|
if(UploadFile $Upload_URI $zipFile)
|
||||||
|
{
|
||||||
|
# update the index file too
|
||||||
|
$indexContent = "Binaries/$env:DOTNET_BUILD_VERSION/$fileName"
|
||||||
|
$indexFile = "$env:TEMP\latest.win.index"
|
||||||
|
$indexContent | Out-File -FilePath $indexFile
|
||||||
|
|
||||||
|
# upload the index file
|
||||||
|
$Upload_URI = "https://$env:STORAGE_ACCOUNT.blob.core.windows.net/$env:STORAGE_CONTAINER/$env:CHANNEL/dnvm/latest.win.index$env:SASTOKEN"
|
||||||
|
|
||||||
|
if(UploadFile $Upload_URI $indexFile)
|
||||||
|
{
|
||||||
|
$result = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
|
||||||
|
function UploadInstallers($msiFile)
|
||||||
|
{
|
||||||
|
$result = -1
|
||||||
|
$fileName = [System.IO.Path]::GetFileName($msiFile)
|
||||||
|
$Upload_URI = "https://$env:STORAGE_ACCOUNT.blob.core.windows.net/$env:STORAGE_CONTAINER/$env:CHANNEL/Installers/$env:DOTNET_BUILD_VERSION/$fileName$env:SASTOKEN"
|
||||||
|
|
||||||
|
if(UploadFile $Upload_URI $msiFile)
|
||||||
|
{
|
||||||
|
$result = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!(CheckRequiredVariables))
|
||||||
{
|
{
|
||||||
# fail silently if the required variables are not available for publishing the file
|
# fail silently if the required variables are not available for publishing the file
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if(![System.IO.File]::Exists($file))
|
if(![System.IO.File]::Exists($file))
|
||||||
|
@ -50,33 +104,15 @@ if(![System.IO.File]::Exists($file))
|
||||||
throw "$file not found"
|
throw "$file not found"
|
||||||
}
|
}
|
||||||
|
|
||||||
$fileName = [System.IO.Path]::GetFileName($file)
|
$result = $false
|
||||||
|
|
||||||
if([System.IO.Path]::GetExtension($file).ToLower() -eq ".zip")
|
if([System.IO.Path]::GetExtension($file).ToLower() -eq ".zip")
|
||||||
{
|
{
|
||||||
$Folder = "Binaries"
|
$result = UploadBinaries $file
|
||||||
}
|
}
|
||||||
elseif([System.IO.Path]::GetExtension($file).ToLower() -eq ".msi")
|
elseif([System.IO.Path]::GetExtension($file).ToLower() -eq ".msi")
|
||||||
{
|
{
|
||||||
$Folder = "Installers"
|
$result = UploadInstallers $file
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit $result
|
||||||
Write-Host "Uploading $fileName to dotnet feed.."
|
|
||||||
|
|
||||||
$Upload_URI = "https://$env:STORAGE_ACCOUNT.blob.core.windows.net/$env:STORAGE_CONTAINER/$env:CHANNEL/$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
|
|
||||||
|
|
||||||
|
|
|
@ -26,24 +26,23 @@ banner "Publishing package"
|
||||||
execute(){
|
execute(){
|
||||||
if ! validate_env_variables; then
|
if ! validate_env_variables; then
|
||||||
# fail silently if the required variables are not available for publishing the file.
|
# fail silently if the required variables are not available for publishing the file.
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$UPLOAD_FILE" ]]; then
|
if [[ ! -f "$UPLOAD_FILE" ]]; then
|
||||||
echo "Error: \"$UPLOAD_FILE\" file does not exist"
|
error "\"$UPLOAD_FILE\" file does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! upload_file_to_blob_storage; then
|
if [[ $UPLOAD_FILE == *.deb || $UPLOAD_FILE == *.pkg ]]; then
|
||||||
exit 1
|
upload_installers_to_blob_storage $UPLOAD_FILE
|
||||||
|
result=$?
|
||||||
|
elif [[ $UPLOAD_FILE == *.tar.gz ]]; then
|
||||||
|
upload_binaries_to_blob_storage $UPLOAD_FILE
|
||||||
|
result=$?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# debain packages need to be uploaded to the PPA feed too
|
exit $result
|
||||||
if [[ $UPLOAD_FILE == *.deb ]]; then
|
|
||||||
DEB_FILE=$UPLOAD_FILE
|
|
||||||
generate_repoclient_json
|
|
||||||
call_repo_client
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
validate_env_variables(){
|
validate_env_variables(){
|
||||||
|
@ -70,7 +69,7 @@ validate_env_variables(){
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$CHANNEL" ]]; then
|
if [[ -z "$CHANNEL" ]]; then
|
||||||
echo "CHANNEL environment variable not set"
|
warning "CHANNEL environment variable not set"
|
||||||
ret=1
|
ret=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -78,28 +77,74 @@ validate_env_variables(){
|
||||||
}
|
}
|
||||||
|
|
||||||
upload_file_to_blob_storage(){
|
upload_file_to_blob_storage(){
|
||||||
local filename=$(basename $UPLOAD_FILE)
|
local upload_URL=$1
|
||||||
|
local file=$2
|
||||||
|
|
||||||
banner "Uploading $filename to blob storage"
|
banner "Uploading $file to blob storage"
|
||||||
|
|
||||||
if [[ $filename == *.deb || $filename == *.pkg ]]; then
|
statusCode=$(curl -s -w "%{http_code}" -L -H "x-ms-blob-type: BlockBlob" -H "x-ms-date: 2015-10-21" -H "x-ms-version: 2013-08-15" $upload_URL -T $file)
|
||||||
FOLDER="Installers"
|
|
||||||
elif [[ $filename == *.tar.gz ]]; then
|
|
||||||
FOLDER="Binaries"
|
|
||||||
fi
|
|
||||||
|
|
||||||
UPLOAD_URL="https://$STORAGE_ACCOUNT.blob.core.windows.net/$STORAGE_CONTAINER/$CHANNEL/$FOLDER/$DOTNET_BUILD_VERSION/$filename$SASTOKEN"
|
if [ "$statusCode" -eq "201" ]; then
|
||||||
|
|
||||||
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
|
|
||||||
error "uploading the $filename to blob storage - $result"
|
|
||||||
else
|
|
||||||
info "successfully uploaded $filename to blob storage."
|
info "successfully uploaded $filename to blob storage."
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
error "uploading the $filename to blob storage - $statusCode"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
update_file_in_blob_storage(){
|
||||||
|
local update_URL=$1
|
||||||
|
local file=$2
|
||||||
|
local filecontent=$3
|
||||||
|
|
||||||
|
banner "Updating $file in blob storage"
|
||||||
|
|
||||||
|
statusCode=$(curl -s -w "%{http_code}" -L -H "x-ms-blob-type: BlockBlob" -H "x-ms-date: 2015-10-21" -H "x-ms-version: 2013-08-15" $update_URL --data $filecontent --request PUT )
|
||||||
|
|
||||||
|
if [ "$statusCode" -eq "201" ]; then
|
||||||
|
info "successfully updated $file in blob storage."
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
error "updating the $file in blob storage - $statusCode"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
upload_binaries_to_blob_storage(){
|
||||||
|
local tarfile=$1
|
||||||
|
local filename=$(basename $tarfile)
|
||||||
|
local upload_URL="https://$STORAGE_ACCOUNT.blob.core.windows.net/$STORAGE_CONTAINER/$CHANNEL/Binaries/$DOTNET_BUILD_VERSION/$filename$SASTOKEN"
|
||||||
|
|
||||||
|
if upload_file_to_blob_storage $upload_URL $tarfile; then
|
||||||
|
# update the index file
|
||||||
|
local indexContent="Binaries/$DOTNET_BUILD_VERSION/$filename"
|
||||||
|
local indexfile="latest.$OSNAME.index"
|
||||||
|
local update_URL="https://$STORAGE_ACCOUNT.blob.core.windows.net/$STORAGE_CONTAINER/$CHANNEL/dnvm/$indexfile$SASTOKEN"
|
||||||
|
update_file_in_blob_storage $update_URL $indexfile $indexContent
|
||||||
|
return $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return $result
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
upload_installers_to_blob_storage(){
|
||||||
|
local installfile=$1
|
||||||
|
local filename=$(basename $installfile)
|
||||||
|
local upload_URL="https://$STORAGE_ACCOUNT.blob.core.windows.net/$STORAGE_CONTAINER/$CHANNEL/Installers/$DOTNET_BUILD_VERSION/$filename$SASTOKEN"
|
||||||
|
|
||||||
|
if ! upload_file_to_blob_storage $upload_URL $installfile; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# debain packages need to be uploaded to the PPA feed too
|
||||||
|
if [[ $installfile == *.deb ]]; then
|
||||||
|
DEB_FILE=$installfile
|
||||||
|
generate_repoclient_json
|
||||||
|
call_repo_client
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_repoclient_json(){
|
generate_repoclient_json(){
|
||||||
|
|
Loading…
Reference in a new issue