/utils/BuildPackages.ps1

https://gitlab.com/0072016/dotnet-corex · Powershell · 171 lines · 121 code · 28 blank · 22 comment · 18 complexity · 5dc2b6407f8065de497b1ed2013cc8cf MD5 · raw file

  1. <#
  2. .SYNOPSIS
  3. Builds and publishes the cross-platform and combined pacakges for RyuJit. Cross-platform binaries
  4. are sourced from Azure Blob Storage.
  5. #>
  6. [CmdletBinding()]
  7. Param(
  8. # The feed to publish to.
  9. [string]$feed,
  10. # The API key to use during publishing.
  11. [string]$apiKey,
  12. # The Azure account to use.
  13. [string]$storageAccount,
  14. # The Azure account key to use.
  15. [string]$storageKey,
  16. # The Azure container to use.
  17. [string]$storageContainer,
  18. # The path to NuGet. Defaults to "nuget.exe".
  19. [string]$nugetPath = "nuget.exe",
  20. # The output directory for the cross-platform binaries.
  21. [string]$binariesDir,
  22. # The package output directory.
  23. [string]$packageOutputDir,
  24. # The directory that contains the .nuspec files that will be used to create the
  25. # cross-platform and combined packages.
  26. [string]$nuspecDir
  27. )
  28. function Get-Latest-Blob-Name
  29. {
  30. Param([array]$blobs, [string]$expectedSuffix)
  31. $chosenBlob = $null
  32. $chosenDate = $null
  33. foreach ($blob in $blobs)
  34. {
  35. if ($blob.name -notlike "*$expectedSuffix")
  36. {
  37. continue
  38. }
  39. $date = [datetime]($blob.properties."last-modified")
  40. if (!$chosenBlob -or ($chosenDate -and $date -ge $chosenDate))
  41. {
  42. $chosenBlob = $blob.name
  43. $chosenDate = $date
  44. }
  45. }
  46. return $chosenBlob
  47. }
  48. # Get the list of blobs in storage
  49. $json = (azure storage blob list -a $storageAccount -k $storageKey $storageContainer --json) -join ""
  50. $blobs = ConvertFrom-Json $json
  51. # Find, fetch, and extract the latest Ubuntu and OSX blobs
  52. [System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
  53. $ubuntuBlob = Get-Latest-Blob-Name $blobs "Ubuntu.14.04_LLILC_x64_Release_Enu.zip"
  54. $osxBlob = Get-Latest-Blob-Name $blobs "OSX_LLILC_x64_Release_Enu.zip"
  55. if (!$ubuntuBlob)
  56. {
  57. Write-Error "Could not locate an Ubuntu drop in Azure."
  58. exit 1
  59. }
  60. if (!$osxBlob)
  61. {
  62. Write-Error "Could not locate an OS X drop in Azure."
  63. exit 1
  64. }
  65. azure storage blob download -m -q -a $storageAccount -k $storageKey $storageContainer $ubuntuBlob
  66. if ($LastExitCode -ne 0)
  67. {
  68. Write-Error "Failed to fetch Ubuntu drop $ubuntuDrop from Azure."
  69. exit 1
  70. }
  71. azure storage blob download -m -q -a $storageAccount -k $storageKey $storageContainer $osxBlob
  72. if ($LastExitCode -ne 0)
  73. {
  74. Write-Error "Failed to fetch OS X drop $osxBlob from Azure."
  75. exit 1
  76. }
  77. $ubuntuDirectory = [System.IO.Path]::GetFileNameWithoutExtension($ubuntuBlob)
  78. try
  79. {
  80. [System.IO.Compression.ZipFile]::ExtractToDirectory($ubuntuBlob, $ubuntuDirectory)
  81. }
  82. catch
  83. {
  84. Write-Error "Failed to extract Ubuntu drop to $ubuntuDirectory`: $_.Exception.Message"
  85. exit 1
  86. }
  87. $osxDirectory = [System.IO.Path]::GetFileNameWithoutExtension($osxBlob)
  88. try
  89. {
  90. [System.IO.Compression.ZipFile]::ExtractToDirectory($osxBlob, $osxDirectory)
  91. }
  92. catch
  93. {
  94. Write-Error "Failed to extract OS X drop to $osxDirectory`: $_.Exception.Message"
  95. exit 1
  96. }
  97. # Gather the bits from the Ubuntu and OSX blobs into the bin directory
  98. $items = @(
  99. "$ubuntuDirectory\libobjwriter.so",
  100. "$osxDirectory\libobjwriter.dylib",
  101. )
  102. Copy-Item -Path $items -Destination $binariesDir
  103. if ($LastExitCode -ne 0)
  104. {
  105. Write-Error "Failed to copy cross-platform bits to $binariesDir."
  106. exit 1
  107. }
  108. if (!(Test-Path $packageOutputDir))
  109. {
  110. New-Item $packageOutputDir -Type Directory
  111. if ($LastExitCode -ne 0)
  112. {
  113. Write-Error "Failed to create $packageOutputDir"
  114. exit 1
  115. }
  116. }
  117. # Gather the .nuspecs and their dependencies into the package output directory
  118. $files = @(
  119. "$nuspecDir\Microsoft.DotNet.ObjectWriter.nuspec",
  120. "$nuspecDir\runtime.json",
  121. "$nuspecDir\toolchain.osx.10.10-x64.Microsoft.DotNet.ObjectWriter.nuspec",
  122. "$nuspecDir\toolchain.ubuntu.14.04-x64.Microsoft.DotNet.ObjectWriter.nuspec",
  123. "$nuspecDir\toolchain.win7-x64.Microsoft.DotNet.ObjectWriter.nuspec"
  124. )
  125. Copy-Item -Path $files -Destination $packageOutputDir
  126. if ($LastExitCode -ne 0)
  127. {
  128. Write-Error "Failed to copy nuspecs to $packageOutputDir."
  129. exit 1
  130. }
  131. # Create the packages.
  132. $packages = @(
  133. "Microsoft.DotNet.ObjectWriter",
  134. "toolchain.osx.10.10-x64.Microsoft.DotNet.ObjectWriter",
  135. "toolchain.ubuntu.14.04-x64.Microsoft.DotNet.ObjectWriter",
  136. "toolchain.win7-x64.Microsoft.DotNet.ObjectWriter"
  137. )
  138. # Note: nuget appears to exit with code 0 in every case, so there's no way to detect failure here
  139. # other than looking at the output.
  140. foreach ($package in $packages) {
  141. Invoke-Expression "$nugetPath pack $packageOutputDir\$package.nuspec -NoPackageAnalysis -NoDefaultExludes -OutputDirectory $packageOutputDir"
  142. Invoke-Expression "$nugetPath push -NonInteractive $packageOutputDir\$package.nupkg -s $feed $apiKey"
  143. }