-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
127 lines (98 loc) · 4.94 KB
/
build.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
$LatestJSON = ((Invoke-WebRequest "https://api.github.com/repos/codesenberg/bombardier/releases/latest").Content | ConvertFrom-Json)
$ReleaseNotes = $LatestJSON.body.Replace("`r`n`r`n", "`r`n").Replace("&", "&").Replace("<", "<").Replace(">", ">")
$LatestVersion = $LatestJSON.tag_name -replace "v" -replace ""
$LatestVersion | Out-File -FilePath LatestVersion.txt -Encoding UTF8
$LatestChocoVersion = "0.0.0"
$AllChocoVersions = (choco search bombardier -r --all | C:\Windows\System32\sort.exe /r)
Write-Output AllChocoVersions = $AllChocoVersions
if ($AllChocoVersions.GetType().FullName -eq 'System.String') {
$LatestChocoVersion = ($AllChocoVersions -split '\|')[1]
} else {
$LatestChocoVersion = ($AllChocoVersions[0] -split '\|')[1]
}
Write-Output LatestChocoVersion = $LatestChocoVersion
$LatestChocoVersion | Out-File -FilePath LatestChocoVersion.txt -Encoding UTF8
$x86_link = $LatestJSON.assets | ForEach-Object -Process { if ($_.name -eq 'bombardier-windows-386.exe'){ $_.browser_download_url } }
$x64_link = $LatestJSON.assets | ForEach-Object -Process { if ($_.name -eq 'bombardier-windows-amd64.exe'){ $_.browser_download_url } }
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -OutFile bombardier-windows-386.exe -Uri $x86_link
Invoke-WebRequest -OutFile bombardier-windows-amd64.exe -Uri $x64_link
$ProgressPreference = 'Continue'
$x86_sha256 = (Get-FileHash .\bombardier-windows-386.exe).Hash
$x64_sha256 = (Get-FileHash .\bombardier-windows-amd64.exe).Hash
Remove-Item .\bombardier-windows-386.exe
Remove-Item .\bombardier-windows-amd64.exe
@"
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
<metadata>
<id>bombardier</id>
<version>$LatestVersion</version>
<packageSourceUrl>https://github.com/doggy8088/bombardier-chocolatey</packageSourceUrl>
<owners>Will 保哥</owners>
<title>Bombardier</title>
<authors>Bombardier</authors>
<projectUrl>https://github.com/codesenberg/bombardier</projectUrl>
<iconUrl>https://avatars1.githubusercontent.com/u/6357982?s=40&v=4</iconUrl>
<copyright>The Bombardier Authors</copyright>
<licenseUrl>https://github.com/codesenberg/bombardier/blob/master/LICENSE</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<projectSourceUrl>https://github.com/codesenberg/bombardier</projectSourceUrl>
<docsUrl>https://github.com/codesenberg/bombardier/wiki</docsUrl>
<bugTrackerUrl>https://github.com/codesenberg/bombardier/issues</bugTrackerUrl>
<tags>bombardier http go</tags>
<summary>Fast cross-platform HTTP benchmarking tool written in Go</summary>
<description>Fast cross-platform HTTP benchmarking tool written in Go and published under the MIT license.</description>
<releaseNotes>$ReleaseNotes</releaseNotes>
</metadata>
<files>
<file src="tools\**" target="tools" />
</files>
</package>
"@ | Out-File -FilePath bombardier.nuspec -Encoding UTF8
@"
`$ErrorActionPreference = 'Stop';
`$packageName= 'bombardier'
`$toolsDir = "`$(Split-Path -parent `$MyInvocation.MyCommand.Definition)"
`$url = '$x86_link'
`$url64 = '$x64_link'
`$toolsDir = "`$(Split-Path -parent `$MyInvocation.MyCommand.Definition)"
`$packageArgs = @{
packageName = `$packageName
url = `$url
url64bit = `$url64
softwareName = 'bombardier'
checksum = '$x86_sha256'
checksumType = 'sha256'
checksum64 = '$x64_sha256'
checksumType64= 'sha256'
fileFullPath = "`$toolsDir\bombardier.exe"
validExitCodes= @(0)
}
Get-ChocolateyWebFile @packageArgs
"@ | Out-File -FilePath tools\chocolateyinstall.ps1 -Encoding UTF8
choco pack
# choco install bombardier -d -s . -y
# choco uninstall bombardier -d -s .
@"
Set-ExecutionPolicy Unrestricted -Force
Install-Module -Name PoshSemanticVersion -Force
`$LatestChocoVersion = Get-Content LatestChocoVersion.txt
`$LatestVersion = Get-Content LatestVersion.txt
# Write-Output LatestChocoVersion = `$LatestChocoVersion
# Write-Output LatestVersion = `$LatestVersion
`$Precedence = (Compare-SemanticVersion -ReferenceVersion `$LatestChocoVersion -DifferenceVersion `$LatestVersion).Precedence;
if (`$Precedence -eq '>' -or `$Precedence -eq '=')
{
Write-Output "因為 Chocolatey 的 bombardier 套件版本(`$LatestChocoVersion) 大於等於 bombardier `$LatestVersion 版本,因此不需要發行套件!"
Write-Output "##vso[task.setvariable variable=BombardierVersion]canceled"
echo "##vso[task.complete result=Canceled;]DONE"
Exit 0
}
else
{
Write-Output "##vso[task.setvariable variable=BombardierVersion]${LatestVersion}"
Write-Output "準備發行 bombardier `$LatestVersion 版本到 Chocolatey Gallery"
choco push bombardier.`$LatestVersion.nupkg --source https://push.chocolatey.org/ --key=#{CHOCO_APIKEY}#
}
"@ | Out-File -FilePath publish.ps1 -Encoding UTF8