|
| 1 | +Param( |
| 2 | + [switch]$verbose = $False |
| 3 | +) |
| 4 | + |
| 5 | +Set-StrictMode -Version Latest |
| 6 | +$ErrorActionPreference = "Stop" |
| 7 | + |
| 8 | +function Invoke-RestMethod-Ex($url, $downloadLocation) { |
| 9 | + |
| 10 | + $irmParams = @{ |
| 11 | + } |
| 12 | + |
| 13 | + Write-Host -ForegroundColor "White" "-> Get $url" |
| 14 | + |
| 15 | + $proxy = [System.Net.WebRequest]::GetSystemWebProxy() |
| 16 | + if ($proxy) { |
| 17 | + $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials |
| 18 | + $proxyUri = $proxy.GetProxy("$url") |
| 19 | + |
| 20 | + if ("$proxyUri" -ne "$url") { |
| 21 | + $irmParams.Proxy = "$proxyUri" |
| 22 | + $irmParams.ProxyUseDefaultCredentials = $true |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + if ($downloadLocation) { |
| 27 | + $irmParams.OutFile = "$downloadLocation" |
| 28 | + } |
| 29 | + |
| 30 | + $output = Invoke-RestMethod @irmParams -ContentType "application/json" -Method "Get" -Uri "$url" |
| 31 | + |
| 32 | + if ($verbose) { |
| 33 | + Write-Host -ForegroundColor "Gray" "output = $(ConvertTo-Json $output)" |
| 34 | + } |
| 35 | + |
| 36 | + return $output |
| 37 | +} |
| 38 | + |
| 39 | +function Extract-BuildIdentifier($statuses, $forContext) { |
| 40 | + |
| 41 | + $status = $statuses | where { $_.context -eq $forContext } | select -First 1 |
| 42 | + |
| 43 | + if (($status -eq $null) -or ("success".CompareTo($status.state) -ne 0)) { |
| 44 | + throw "No successful status has been found for context `"$forContext`"." |
| 45 | + } |
| 46 | + |
| 47 | + $buildNumber = $status.target_url.Split("/")[-1] |
| 48 | + |
| 49 | + return $buildNumber |
| 50 | +} |
| 51 | + |
| 52 | +function Download-AppVeyor-Artifacts($statuses, $downloadLocation) { |
| 53 | + |
| 54 | + $buildIdentifier = Extract-BuildIdentifier $statuses "continuous-integration/appveyor" |
| 55 | + |
| 56 | + Write-Host -ForegroundColor "Yellow" "Retrieving AppVeyor build `"$buildIdentifier`"" |
| 57 | + $build = Invoke-RestMethod-Ex "https://ci.appveyor.com/api/projects/libgit2/libgit2sharp-nativebinaries/build/$buildIdentifier" |
| 58 | + |
| 59 | + $jobId = $build.build.jobs[0].jobId |
| 60 | + |
| 61 | + Write-Host -ForegroundColor "Yellow" "Retrieving AppVeyor job `"$jobId`" artifacts" |
| 62 | + $artifacts = Invoke-RestMethod-Ex "https://ci.appveyor.com/api/buildjobs/$jobId/artifacts" |
| 63 | + |
| 64 | + ForEach ($artifact in $artifacts) { |
| 65 | + $artifactFileName = $artifacts[0].fileName |
| 66 | + $localArtifactPath = "$downloadLocation\$artifactFileName" |
| 67 | + |
| 68 | + Write-Host -ForegroundColor "Yellow" "Downloading `"$artifactFileName`"" |
| 69 | + Invoke-RestMethod-Ex "https://ci.appveyor.com/api/buildjobs/$jobId/artifacts/$artifactFileName" $localArtifactPath |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +function Download-Travis-Artifacts($statuses, $downloadLocation) { |
| 74 | + |
| 75 | + $buildIdentifier = Extract-BuildIdentifier $statuses "continuous-integration/travis-ci/push" |
| 76 | + |
| 77 | + Write-Host -ForegroundColor "Yellow" "Retrieving Travis build `"$buildIdentifier`"" |
| 78 | + $build = Invoke-RestMethod-Ex "https://api.travis-ci.org/builds/$buildIdentifier" |
| 79 | + |
| 80 | + $buildNumber = $build.number |
| 81 | + |
| 82 | + ForEach ($platform in @("linux", "osx")) { |
| 83 | + $artifactFileName = "binaries-$platform-$buildNumber.zip" |
| 84 | + $localArtifactPath = "$downloadLocation\$artifactFileName" |
| 85 | + |
| 86 | + Write-Host -ForegroundColor "Yellow" "Downloading `"$artifactFileName`"" |
| 87 | + Invoke-RestMethod-Ex "https://dl.bintray.com/libgit2/compiled-binaries/$artifactFileName" $localArtifactPath |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +###################################################### |
| 92 | + |
| 93 | +$root = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition |
| 94 | + |
| 95 | +$path = [System.IO.Path]::Combine($env:Temp, [System.IO.Path]::GetRandomFileName()) |
| 96 | +Write-Host -ForegroundColor "Yellow" "Creating temporary folder at `"$path`"" |
| 97 | +New-Item "$path" -type Directory > $null |
| 98 | + |
| 99 | +$ref = "master" |
| 100 | +Write-Host -ForegroundColor "Yellow" "Retrieving LibGit2Sharp.NativeBinaries latest CI statuses of `"$ref`"" |
| 101 | +$statuses = Invoke-RestMethod-Ex "https://api.github.com/repos/libgit2/libgit2sharp.nativebinaries/commits/$ref/statuses" |
| 102 | + |
| 103 | +Download-AppVeyor-Artifacts $statuses $path |
| 104 | +Download-Travis-Artifacts $statuses $path |
| 105 | + |
| 106 | +Write-Host -ForegroundColor "Yellow" "Build artifacts have been downloaded at `"$path`"" |
| 107 | + |
| 108 | +$package = Get-ChildItem -Path $path -Filter "*.nupkg" |
| 109 | +$linuxBins = Get-ChildItem -Path $path -Filter "binaries-linux-*.zip" |
| 110 | +$osxBins = Get-ChildItem -Path $path -Filter "binaries-osx-*.zip" |
| 111 | + |
| 112 | +Write-Host -ForegroundColor "Yellow" "Extracting build artifacts" |
| 113 | +Add-Type -assembly "System.Io.Compression.Filesystem" |
| 114 | +[Io.Compression.ZipFile]::ExtractToDirectory("$($package.FullName)", "$($package.FullName).ext") |
| 115 | +Remove-Item "$($package.FullName)" |
| 116 | +[Io.Compression.ZipFile]::ExtractToDirectory("$($linuxBins.FullName)", "$($linuxBins.FullName).ext") |
| 117 | +Remove-Item "$($linuxBins.FullName)" |
| 118 | +[Io.Compression.ZipFile]::ExtractToDirectory("$($osxBins.FullName)", "$($osxBins.FullName).ext") |
| 119 | +Remove-Item "$($osxBins.FullName)" |
| 120 | + |
| 121 | +Write-Host -ForegroundColor "Yellow" "Including non Windows build artifacts" |
| 122 | +Move-Item "$($linuxBins.FullName).ext\libgit2\linux\amd64\*.so" "$($package.FullName).ext\libgit2\linux\amd64" |
| 123 | +Remove-Item "$($package.FullName).ext\libgit2\linux\amd64\addbinaries.here" |
| 124 | +Move-Item "$($osxBins.FullName).ext\libgit2\osx\*.dylib" "$($package.FullName).ext\libgit2\osx" |
| 125 | +Remove-Item "$($package.FullName).ext\libgit2\osx\addbinaries.here" |
| 126 | + |
| 127 | +Write-Host -ForegroundColor "Yellow" "Listing binaries to be packaged" |
| 128 | +Foreach ($item in (Get-ChildItem "$path" -Filter "*git2-*.*" -Recurse)) |
| 129 | +{ |
| 130 | + Write-Host -ForegroundColor "White" "-> $($item.FullName)" |
| 131 | +} |
| 132 | + |
| 133 | +Write-Host -ForegroundColor "Yellow" "Building final NuGet package" |
| 134 | +Push-location "$($package.FullName).ext" |
| 135 | +& "$root/Nuget.exe" pack "LibGit2Sharp.NativeBinaries.nuspec" -OutputDirectory "$path" |
| 136 | +Pop-Location |
| 137 | +Remove-Item "$path\*.ext" -Recurse |
| 138 | + |
| 139 | +explorer "$path" |
0 commit comments