-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy.ps1
More file actions
48 lines (42 loc) · 1.53 KB
/
Copy pathdeploy.ps1
File metadata and controls
48 lines (42 loc) · 1.53 KB
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
# You may be required to enable script execution: Set-ExecutionPolicy Unrestricted -Scope CurrentUser
# Requires at least Powershell 3.0 (included since Windows 7)
$Src = (Split-Path $MyInvocation.MyCommand.Path) + "\"
$Dest = [System.IO.Path]::GetTempFileName()
# Read key from first argument
if ($Args.length -eq 0) {
echo "Usage: .\$($MyInvocation.MyCommand.Name) <upload key>"
Exit
}
# Create a ZIP file, remove old one first
If (Test-Path $Dest){
Remove-Item $Dest
}
try {
[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
[System.IO.Compression.ZipFile]::CreateFromDirectory($Src, $Dest, [System.IO.Compression.CompressionLevel]::Optimal, $false)
} catch {
echo "Unable to create ZIP."
echo $_.Exception.GetType().FullName, $_.Exception.Message
Exit
}
# Upload the file
try {
$OldEAP = $ErrorActionPreference
$ErrorActionPreference = 'SilentlyContinue'
$result = Invoke-RestMethod -Uri "https://happening.im/plugin/$($Args[0])" -InFile $Dest -Method POST
$ErrorActionPreference = $OldEAP
# Print success result
echo $result
} catch [Exception] {
echo ">>> Failed to deploy your plugin to Happening:"
# Print the exception message (includes the HTTP status code)
echo $_.Exception.Message
# Print the body of the server response (includes the error message from Happening)
$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
echo $responseBody
Exit
}