|
| 1 | +<# |
| 2 | +
|
| 3 | +.NOTES |
| 4 | +Copyright (c) Microsoft Corporation. |
| 5 | +Licensed under the MIT License. |
| 6 | +
|
| 7 | +.SYNOPSIS |
| 8 | +Downloads build artifacts from Azure DevOps for DirectXTex. |
| 9 | +
|
| 10 | +.DESCRIPTION |
| 11 | +This script is used as part of the internal release process for DirectXTex. |
| 12 | +
|
| 13 | +.PARAMETER BuildId |
| 14 | +This is the specific build to get artifacts from. |
| 15 | +
|
| 16 | +.PARAMETER PAT |
| 17 | +Requires an ADO PAT with 'Build > Read' scope. Can be provided via the ADO_PERSONAL_ACCESS_TOKEN environment variable or as a parameter. |
| 18 | +
|
| 19 | +.LINK |
| 20 | +https://github.com/microsoft/DirectXTex/wiki |
| 21 | +
|
| 22 | +#> |
| 23 | + |
| 24 | +param( |
| 25 | + [Parameter(Mandatory)] |
| 26 | + [int]$BuildId, |
| 27 | + [string]$PAT = "" |
| 28 | +) |
| 29 | + |
| 30 | +# Parse PAT |
| 31 | +if ($PAT.Length -eq 0) { |
| 32 | + $PAT = $env:ADO_PERSONAL_ACCESS_TOKEN |
| 33 | + |
| 34 | + if ($PAT.Length -eq 0) { |
| 35 | + Write-Error "##[error]This script requires a valid ADO Personal Access Token!" -ErrorAction Stop |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +# Initial REST query |
| 40 | +$headers = @{ |
| 41 | + "Content-Type" = "application/json" |
| 42 | + Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$PAT")) |
| 43 | +} |
| 44 | + |
| 45 | +$uriFormat = "https://dev.azure.com/MSCodeHub/ca4f06c8-d88d-40fb-ada3-b70b24a98714/_apis/build/builds/{0}/artifacts?artifactName={1}&api-version=7.1" |
| 46 | + |
| 47 | +$uriarm64 = $uriFormat -f $BuildId, "DirectXTex_Binaries_Release_ARM64" |
| 48 | +$uriamd64 = $uriFormat -f $BuildId, "DirectXTex_Binaries_Release_x64" |
| 49 | + |
| 50 | +try |
| 51 | +{ |
| 52 | + Write-Host "Checking if build and artifacts exist..." |
| 53 | + $responseamd64 = Invoke-RestMethod -Uri $uriamd64 -Method Get -Headers $headers |
| 54 | + $responsearm64 = Invoke-RestMethod -Uri $uriarm64 -Method Get -Headers $headers |
| 55 | +} |
| 56 | +catch |
| 57 | +{ |
| 58 | + Write-Error "##[error]Build $BuildId not found!" -ErrorAction Continue |
| 59 | +} |
| 60 | + |
| 61 | +$ProgressPreference = 'SilentlyContinue' |
| 62 | + |
| 63 | +$tempFolderPath = Join-Path $Env:Temp $(New-Guid) |
| 64 | +New-Item -Type Directory -Path $tempFolderPath | Out-Null |
| 65 | + |
| 66 | +Write-Host $tempFolderPath |
| 67 | + |
| 68 | +$headers = @{ |
| 69 | + Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$PAT")) |
| 70 | + Accept = "application/zip" |
| 71 | +} |
| 72 | + |
| 73 | +Add-Type -A System.IO.Compression.FileSystem |
| 74 | + |
| 75 | +# Download artifacts for ARM64 |
| 76 | +foreach ($artifact in $responsearm64) { |
| 77 | + $artifactName = $artifact.name |
| 78 | + $downloadUrl = $artifact.resource.downloadUrl |
| 79 | + $outputFile = Join-Path $tempFolderPath "$artifactName.zip" |
| 80 | + |
| 81 | + try |
| 82 | + { |
| 83 | + Write-Host "Downloading $artifactName to $outputFile..." |
| 84 | + Invoke-WebRequest -Uri $downloadUrl -Headers $headers -OutFile $outputFile |
| 85 | + } |
| 86 | + catch |
| 87 | + { |
| 88 | + Write-Error "##[error]Failed to download $artifactName!" -ErrorAction Continue |
| 89 | + } |
| 90 | + |
| 91 | + try |
| 92 | + { |
| 93 | + Write-Host "Extracting $artifactName..." |
| 94 | + [IO.Compression.ZipFile]::ExtractToDirectory($outputFile, $tempFolderPath) |
| 95 | + } |
| 96 | + catch |
| 97 | + { |
| 98 | + Write-Error "##[error]Failed to extract $artifactName!" -ErrorAction Continue |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +# Download artifacts for X64 |
| 103 | +foreach ($artifact in $responseamd64) { |
| 104 | + $artifactName = $artifact.name |
| 105 | + $downloadUrl = $artifact.resource.downloadUrl |
| 106 | + $outputFile = Join-Path $tempFolderPath "$artifactName.zip" |
| 107 | + |
| 108 | + try |
| 109 | + { |
| 110 | + Write-Host "Downloading $artifactName to $outputFile..." |
| 111 | + Invoke-WebRequest -Uri $downloadUrl -Headers $headers -OutFile $outputFile |
| 112 | + } |
| 113 | + catch |
| 114 | + { |
| 115 | + Write-Error "##[error]Failed to download $artifactName!" -ErrorAction Continue |
| 116 | + } |
| 117 | + |
| 118 | + try |
| 119 | + { |
| 120 | + Write-Host "Extracting $artifactName..." |
| 121 | + [IO.Compression.ZipFile]::ExtractToDirectory($outputFile, $tempFolderPath) |
| 122 | + } |
| 123 | + catch |
| 124 | + { |
| 125 | + Write-Error "##[error]Failed to extract $artifactName!" -ErrorAction Continue |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +# Extract command-line tool binaries |
| 130 | +$exes = @( |
| 131 | + "Texassemble", |
| 132 | + "Texconv", |
| 133 | + "Texdiag" |
| 134 | +) |
| 135 | + |
| 136 | +$binPath = Join-Path $tempFolderPath "DirectXTex_Binaries_Release_ARM64" |
| 137 | +foreach ($exe in $exes) { |
| 138 | + $srcPath = "{0}\{1}\Bin\Desktop_2022_Win10\ARM64\Release\{1}_arm64.exe" -f $binPath, $exe |
| 139 | + Copy-Item -Path $srcPath -Destination "." -ErrorAction Stop |
| 140 | +} |
| 141 | + |
| 142 | +$binPath = Join-Path $tempFolderPath "DirectXTex_Binaries_Release_x64" |
| 143 | +foreach ($exe in $exes) { |
| 144 | + $srcPath = "{0}\{1}\Bin\Desktop_2022\x64\Release\{1}.exe" -f $binPath, $exe |
| 145 | + Copy-Item -Path $srcPath -Destination "." -ErrorAction Stop |
| 146 | +} |
0 commit comments