Skip to content

Commit aba3221

Browse files
committed
Added helper scripts
1 parent 8844de8 commit aba3221

File tree

3 files changed

+279
-0
lines changed

3 files changed

+279
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ x64
4747
/out
4848
/CMakeUserPresets.json
4949
/build/vcpkg_installed
50+
/build/*.exe

build/downloadbuild.ps1

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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+
}

build/promotenuget.ps1

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<#
2+
3+
.NOTES
4+
Copyright (c) Microsoft Corporation.
5+
Licensed under the MIT License.
6+
7+
.SYNOPSIS
8+
This promotes the NuGet packages on the project-scoped feed.
9+
10+
.DESCRIPTION
11+
This script promotes the views of the DirectXTex NuGet packages on the project-scoped feed. It always promotes to Prerelease view, and if the Release switch is set, it also promotes to Release view.
12+
13+
.PARAMETER Version
14+
Indicates which version of the packages to promote.
15+
16+
.PARAMETER PAT
17+
Requires an ADO PAT with 'Packaging > Read, write, and manage' scope. Can be provided via the ADO_PERSONAL_ACCESS_TOKEN environment variable or as a parameter.
18+
19+
.PARAMETER Release
20+
By default promotes to prerelease. If this switch is set, promotes to release as well.
21+
22+
.LINK
23+
https://github.com/microsoft/DirectXTex/wiki
24+
25+
#>
26+
27+
param(
28+
[Parameter(Mandatory)]
29+
[string]$Version,
30+
[string]$PAT = "",
31+
[switch]$Release
32+
)
33+
34+
# Parse PAT
35+
if ($PAT.Length -eq 0) {
36+
$PAT = $env:ADO_PERSONAL_ACCESS_TOKEN
37+
38+
if ($PAT.Length -eq 0) {
39+
Write-Error "##[error]This script requires a valid ADO Personal Access Token!" -ErrorAction Stop
40+
}
41+
}
42+
43+
# Project-scoped feed root (package name and version to be filled in later)
44+
$uriFormat = "https://pkgs.dev.azure.com/MSCodeHub/ca4f06c8-d88d-40fb-ada3-b70b24a98714/_apis/packaging/feeds/17d602ae-444a-46e6-ac3b-bb124bd0afa8/nuget/packages/{0}/versions/{1}?api-version=7.1"
45+
46+
$headers = @{
47+
"Content-Type" = "application/json"
48+
Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$PAT"))
49+
}
50+
51+
$bodyPrerelease = @{
52+
views = @{
53+
op = "add"
54+
path = "/views/-"
55+
value = "Prerelease"
56+
}
57+
} | ConvertTo-Json
58+
59+
$bodyRelease = @{
60+
views = @{
61+
op = "add"
62+
path = "/views/-"
63+
value = "Release"
64+
}
65+
} | ConvertTo-Json
66+
67+
$packages = @('directxtex_desktop_2019', 'directxtex_desktop_win10', 'directxtex_uwp')
68+
69+
# Check if all packages exist
70+
$allPackagesSucceeded = $true
71+
foreach ($package in $packages) {
72+
$uri = $uriFormat -f $package, $Version
73+
74+
try
75+
{
76+
Write-Host "Checking if $package version $Version exists..."
77+
$response = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers
78+
}
79+
catch
80+
{
81+
Write-Error "##[error]Package $package version $Version not found!" -ErrorAction Continue
82+
$allPackagesSucceeded = $false
83+
}
84+
}
85+
86+
if (-not $allPackagesSucceeded) {
87+
Write-Error "##[error]Not all packages found. Aborting promotion." -ErrorAction Stop
88+
}
89+
90+
# Promote package to Prerelease view
91+
foreach ($package in $packages) {
92+
$uri = $uriFormat -f $package, $Version
93+
94+
try
95+
{
96+
# Promote to Prerelease view
97+
Write-Host "Promoting $package version $Version to Prerelease view..."
98+
Invoke-RestMethod -Uri $uri -Method Patch -Headers $headers -Body $bodyPrerelease
99+
}
100+
catch
101+
{
102+
Write-Error "##[error]Package $package version $Version failed to promote" -ErrorAction Continue
103+
$allPackagesSucceeded = $false
104+
}
105+
}
106+
107+
if (-not $allPackagesSucceeded) {
108+
Write-Error "##[error]Not all packages promoted to Prerelease." -ErrorAction Stop
109+
}
110+
111+
# Optionally promote package to Release view
112+
if ($Release.IsPresent) {
113+
foreach ($package in $packages) {
114+
$uri = $uriFormat -f $package, $Version
115+
116+
try
117+
{
118+
# Promote to Release view
119+
Write-Host "Promoting $package version $Version to Release view..."
120+
Invoke-RestMethod -Uri $uri -Method Patch -Headers $headers -Body $bodyRelease
121+
}
122+
catch
123+
{
124+
Write-Error "##[error]Package $package version $Version failed to promote" -ErrorAction Continue
125+
$allPackagesSucceeded = $false
126+
}
127+
}
128+
129+
if (-not $allPackagesSucceeded) {
130+
Write-Error "##[error]Not all packages promoted to Release." -ErrorAction Stop
131+
}
132+
}

0 commit comments

Comments
 (0)