-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.ps1
170 lines (145 loc) · 4.57 KB
/
package.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
param(
[switch]$PackAndTest = $false,
[switch]$Push = $false,
[switch]$Debug = $false,
[switch]$Verbose = $false,
[string]$ApiKey = $null,
[switch]$Uninstall = $true
)
if ($Push)
{
$PackAndTest = $true
Write-Host "[INFO] PACKAGE WILL BE TESTED AND PUSHED"
}
$DebugPreference = 'Continue'
$ErrorActionPreference = 'Stop'
# Set-PSDebug -Strict -Trace 1
Set-PSDebug -Off
Set-StrictMode -Version 'Latest' -ErrorAction 'Stop' -Verbose
New-Variable -Name curdir -Option Constant -Value $PSScriptRoot
Write-Host "[INFO] curdir: $curdir"
if ($Debug)
{
New-Variable -Name arg_debug -Option Constant -Value '--debug'
}
else
{
New-Variable -Name arg_debug -Option Constant -Value ''
}
if ($Verbose)
{
New-Variable -Name arg_verbose -Option Constant -Value '--verbose'
}
else
{
New-Variable -Name arg_verbose -Option Constant -Value ''
}
try
{
$ProgressPreference = 'SilentlyContinue'
New-Variable -Name rebar3_json -Option Constant `
-Value (Invoke-WebRequest -Uri https://api.github.com/repos/erlang/rebar3/releases/latest | ConvertFrom-Json)
}
finally
{
$ProgressPreference = 'Continue'
}
New-Variable -Name rebar3_version -Option Constant -Value $rebar3_json.tag_name
Write-Host "[INFO] rebar3_version: $rebar3_version"
New-Variable -Name rebar3_asset_node -Option Constant `
-Value ($rebar3_json.assets | Where-Object { $_.name -eq 'rebar3' })
New-Variable -Name rebar3_file -Option Constant -Value $rebar3_asset_node.name
if (!(Test-Path -Path $rebar3_file))
{
Write-Host "[INFO] downloading from " $rebar3_asset_node.browser_download_url
try
{
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $rebar3_asset_node.browser_download_url -OutFile $rebar3_file
}
finally
{
$ProgressPreference = 'Continue'
}
}
New-Variable -Name rebar3_file_sha256 -Option Constant `
-Value (Get-FileHash -Path $rebar3_file -Algorithm SHA256).Hash.ToLowerInvariant()
(Get-Content -Raw -Path rebar3.nuspec.in).Replace('@@REBAR3_VERSION@@', $rebar3_version) | Set-Content rebar3.nuspec
New-Variable -Name chocolateyInstallPs1In -Option Constant `
-Value (Join-Path -Path $curdir -ChildPath 'tools' | Join-Path -ChildPath 'chocolateyInstall.ps1.in')
New-Variable -Name chocolateyInstallPs1 -Option Constant `
-Value (Join-Path -Path $curdir -ChildPath 'tools' | Join-Path -ChildPath 'chocolateyInstall.ps1')
(Get-Content -Raw -Path $chocolateyInstallPs1In).Replace('@@REBAR3_VERSION@@', $rebar3_version).Replace('@@SHA256@@', $rebar3_file_sha256) | Set-Content $chocolateyInstallPs1
New-Variable -Name chocolateyUninstallPs1In -Option Constant `
-Value (Join-Path -Path $curdir -ChildPath 'tools' | Join-Path -ChildPath 'chocolateyUninstall.ps1.in')
New-Variable -Name chocolateyUninstallPs1 -Option Constant `
-Value (Join-Path -Path $curdir -ChildPath 'tools' | Join-Path -ChildPath 'chocolateyUninstall.ps1')
(Get-Content -Raw -Path $chocolateyUninstallPs1In).Replace('@@REBAR3_VERSION@@', $rebar3_version) | Set-Content $chocolateyUninstallPs1
if ($PackAndTest)
{
& choco pack
if ($LASTEXITCODE -eq 0)
{
Write-Host "[INFO] 'choco pack' succeeded."
}
else
{
throw "[ERROR] 'choco pack' failed!"
}
& choco install rebar3 $arg_debug $arg_verbose --yes --source ".;https://chocolatey.org/api/v2/"
if ($LASTEXITCODE -eq 0)
{
Write-Host "[INFO] 'choco install' succeeded."
}
else
{
throw "[ERROR] 'choco install' failed!"
}
& rebar3 version
try
{
if ($LASTEXITCODE -eq 0)
{
Write-Host "[INFO] rebar3 check succeeded."
}
else
{
throw "[ERROR] rebar3 check failed!"
}
}
finally
{
if ($Uninstall)
{
Write-Host "[INFO] choco un-installing Rebar3..."
& choco uninstall rebar3 $arg_debug $arg_verbose --yes --source ".;https://chocolatey.org/api/v2/"
Write-Host "[INFO] uninstallation complete!"
}
else
{
Write-Host "[INFO] choco NOT un-installing Rebar3!"
}
}
}
if ($Push)
{
& choco apikey --yes --key $ApiKey --source https://push.chocolatey.org/
if ($LASTEXITCODE -eq 0)
{
Write-Host "[INFO] 'choco apikey' succeeded."
}
else
{
throw "[ERROR] 'choco apikey' failed!"
}
& choco push rebar3.$rebar3_version.nupkg --source https://push.chocolatey.org
if ($LASTEXITCODE -eq 0)
{
Write-Host "[INFO] 'choco push' succeeded."
}
else
{
throw "[ERROR] 'choco push' failed!"
}
}
Set-PSDebug -Off