forked from RetroAchievements/RASuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeployRAIntegration.ps1
92 lines (69 loc) · 2.8 KB
/
DeployRAIntegration.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
Function DeployIntegration
{
Param(
[Parameter(Mandatory)]
[ValidateSet("True","False")]
$ForceUpdate
)
Process
{
################################################################################
# Custom Variables:
$IntegrationDLLSource = "RA_Integration/RA_Integration.dll"
$VersionDoc = "..\web\LatestIntegration.html"
$ExpectedTag = "RAIntegration"
################################################################################
# Global Variables:
$Password = ConvertTo-SecureString 'Unused' -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ('ec2-user', $Password)
$KeyPath = ".\RetroAchievementsKey"
$TargetURL = "www.RetroAchievements.org"
$WebRoot = "/var/www/html"
$WebRootBin = "/var/www/html/bin"
################################################################################
# Test we are ready for release
$latestTag = git describe --tags --match "$($ExpectedTag).*"
$diffs = git diff HEAD
if( ![string]::IsNullOrEmpty( $diffs ) )
{
if( $ForceUpdate -ne "True" )
{
throw "Changes exist, cannot deploy!"
}
else
{
Write-Warning "Changes exist, deploying anyway!"
}
}
$newHTMLContent = "0." + $latestTag.Substring( $ExpectedTag.Length + 1, 3 )
$currentVersion = Get-Content $VersionDoc
if( $newHTMLContent -eq $currentVersion )
{
if( $ForceUpdate -ne "True" )
{
throw "We are already on version $currentVersion, nothing to do!"
}
else
{
Write-Warning "We are already on version $currentVersion, deploying anyway!"
}
}
Set-Content $VersionDoc $newHTMLContent
################################################################################
# Upload
# Establish the SFTP connection
$session = ( New-SFTPSession -ComputerName $TargetURL -Credential $Credential -KeyFile $KeyPath )
# Upload the new version html
Set-SFTPFile -SessionId $session.SessionId -LocalFile $VersionDoc -RemotePath $WebRoot -Overwrite
# Upload the zip to the SFTP bin path
Set-SFTPFile -SessionId $session.SessionId -LocalFile $IntegrationDLLSource -RemotePath $WebRootBin -Overwrite
# Disconnect SFTP session
$session.Disconnect()
Write-Warning "Published $latestTag"
}
}
################################################################################
# Set working directory:
$dir = Split-Path $MyInvocation.MyCommand.Path
Set-Location $dir
DeployIntegration