-
Notifications
You must be signed in to change notification settings - Fork 9
/
DeployRAVBA-M.ps1
127 lines (97 loc) · 3.98 KB
/
DeployRAVBA-M.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
Function DeployVBA
{
Param(
[Parameter(Mandatory)]
[ValidateSet("True","False")]
$ForceUpdate
)
Process
{
################################################################################
# Custom Variables:
$FilesToCopy = @(".\RA_Integration\Overlay",
".\RAVBA-M\project\vs2012_mfc\Release\RAVisualBoyAdvance-M.exe",
".\RAVBA-M\project\vs2012_mfc\Release\D3DX9_41.dll",
".\RAVBA-M\Deploy\COPYING",
".\RAVBA-M\Deploy\NEWS",
".\RAVBA-M\Deploy\README-win.txt");
$TargetArchiveName = "RAVBA.zip"
$VersionDoc = "..\RAWeb\public\LatestRAVBAVersion.html"
$ExpectedTag = "RAVBA-M"
################################################################################
# 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/public"
$WebRootBin = "/var/www/html/public/bin"
if (-not (Test-Path "$env:ProgramFiles\7-Zip\7z.exe"))
{
throw "$env:ProgramFiles\7-Zip\7z.exe needed"
}
Set-Alias sz "$env:ProgramFiles\7-Zip\7z.exe"
################################################################################
# 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
################################################################################
# Produce Archive zip
# Create stage
if ( Test-Path ".\Stage" )
{
Remove-Item ".\Stage" -Force -Recurse
}
$stage = New-Item -ItemType Directory -Name "Stage" -Force
# Copy all required to stage
Foreach( $filepath in $FilesToCopy )
{
Copy-Item $filepath $stage.PSPath -Recurse -Force
}
sz a $TargetArchiveName "$($stage.FullName)\*.*" -r > 7z.log
################################################################################
# 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 $TargetArchiveName -RemotePath $WebRootBin -Overwrite
# Disconnect SFTP session
$session.Disconnect()
# Kill Stage
Remove-Item ".\Stage" -Force -Recurse
# Kill new zip
Remove-Item $TargetArchiveName -Force
}
}
################################################################################
# Set working directory:
$dir = Split-Path $MyInvocation.MyCommand.Path
Set-Location $dir
DeployVBA