forked from axmolengine/axmol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolv-url.ps1
61 lines (53 loc) · 2.13 KB
/
resolv-url.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# resolve artifact url
param(
[Alias('artifact')]
$name,
$manifest,
$target,
$build_id,
$branch,
$out_var
)
$artifact_url = $null
if ($manifest -eq 'gcloud') {
function Get-LatestGoodBuild {
param (
[string]$branch,
[string]$target
)
$apiURL = "https://androidbuildinternal.googleapis.com/android/internal/build/v3/builds?branches=$([uri]::EscapeDataString($branch))&buildAttemptStatus=complete&buildType=submitted&maxResults=1&successful=true&target=$([uri]::EscapeDataString($target))"
$body = Invoke-WebRequest -Uri $apiURL
$buildData = $body | ConvertFrom-Json
if ($buildData.builds.Count -eq 0) {
throw "No build ID is found"
}
return $buildData.builds[0].buildId
}
# Validate input parameters
$artifact = $name
if (-not $target) { throw "Missing target." }
if (-not $artifact) { throw "Missing artifact." }
if (-not $build_id -and -not $branch) { throw "Missing build_id or branch." }
if (-not $build_id -and $branch) {
$build_id = Get-LatestGoodBuild -branch $branch -target $target
}
$artifact_url = "https://androidbuildinternal.googleapis.com/android/internal/build/v3/builds/$([uri]::EscapeDataString($build_id))/$([uri]::EscapeDataString($target))/attempts/latest/artifacts/$([uri]::EscapeDataString($artifact))/url"
}
else {
if (Test-Path $manifest -PathType Leaf) {
$mirror = if (!(Test-Path (Join-Path $PSScriptRoot '.gitee') -PathType Leaf)) { 'github' } else { 'gitee' }
$manifest_map = ConvertFrom-Json (Get-Content $manifest -raw)
$ver = $manifest_map.versions.PSObject.Properties[$name].Value
$mirror_current = $manifest_map.mirrors.PSObject.Properties[$mirror].Value.PSObject.Properties
$url_base = "https://$($mirror_current['host'].Value)/"
$url_path = $mirror_current[$name].Value
$artifact_url = "$url_base$url_path#$ver"
}
}
if($artifact_url) {
if(!$out_var) {
Write-Host $artifact_url -NoNewline
} else {
Write-Information $artifact_url -InformationVariable $out_var
}
}