blob: b9b3f08ee125ea703b6e427e18d7cf16a0455306 (
plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
& {
Function myExit($code){
if($code -is [int] -and $code -ne 0){
throw $Error[0]
}else{
break
}
}
Function writeErrorTip($msg){
Write-Host $msg -BackgroundColor Red -ForegroundColor White
}
Function writeLogoLine($msg){
Write-Host $msg -BackgroundColor White -ForegroundColor DarkBlue
}
Function Get-AppVeyorArtifacts{
param(
[parameter(Mandatory = $true)]
[string]$Account,
[parameter(Mandatory = $true)]
[string]$Project,
[parameter(Mandatory = $true)]
[string]$DownloadDirectory)
$apiUrl = 'https://ci.appveyor.com/api'
$headers = @{
'Content-type' = 'application/json'
}
$obj = Invoke-RestMethod -Method Get -Uri "$apiUrl/projects/$Account/$Project/history?recordsNumber=13" -Headers $headers
$job = $null
if([environment]::Is64BitOperatingSystem){
$job = 1
}else{
$job = 0
}
ForEach($_ in $obj.builds){
$version = $_.version
$build = Invoke-RestMethod -Method Get -Uri "$apiUrl/projects/$Account/$Project/build/$version" -Headers $headers
$jobId = $build.build.jobs[$job].jobId
$artifacts = Invoke-RestMethod -Method Get -Uri "$apiUrl/buildjobs/$jobId/artifacts" -Headers $headers
$artifactFileName = $artifacts[0].fileName
if($artifactFileName -eq "xmake.exe"){
$localArtifactPath = "$DownloadDirectory\$artifactFileName"
Invoke-RestMethod -Method Get -Uri "$apiUrl/buildjobs/$jobId/artifacts/$artifactFileName" -OutFile $localArtifactPath
return
}
}
throw 'artifact not found'
}
writeLogoLine ' _ '
writeLogoLine ' __ ___ __ __ __ _| | ______ '
writeLogoLine ' \ \/ / | \/ |/ _ | |/ / __ \ '
writeLogoLine ' > < | \__/ | /_| | < ___/ '
writeLogoLine ' /_/\_\_|_| |_|\__ \|_|\_\____| getter '
writeLogoLine ' '
writeLogoLine ' '
if($PSVersionTable.PSVersion.Major -lt 5){
writeErrorTip 'Sorry but PowerShell v5+ is required'
throw 'PowerShell''s version too low'
}
try{
$installdir="$HOME\xmake"
try{Remove-Item -Recurse -Force $installdir}catch{}
New-Item $installdir -ItemType directory
try{
Get-AppVeyorArtifacts waruqi xmake $installdir
}catch{
Get-AppVeyorArtifacts TitanSnow "xmake-90ua9" $installdir
}
if($branch -eq $null){ $branch='master' }
Invoke-Webrequest "https://github.com/tboox/xmake/archive/$branch.zip" -OutFile "$installdir\temp.zip"
Expand-Archive "$installdir\temp.zip" "$installdir\temp" -Force
Move-Item "$installdir\temp\xmake-$branch\xmake\*" $installdir
Remove-Item "$installdir\temp","$installdir\temp.zip" -Recurse -Force
try{
xmake --version | Out-Null
}catch{
$env:Path+=";$installdir"
[Environment]::SetEnvironmentVariable("Path",[Environment]::GetEnvironmentVariable("Path",[System.EnvironmentVariableTarget]::User)+";$installdir",[System.EnvironmentVariableTarget]::User)
}
xmake --version
}catch{
writeErrorTip 'Error!'
myExit 1
}
}
|