-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackageAndRelease.ps1
207 lines (169 loc) · 6.67 KB
/
PackageAndRelease.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<#
# Simple ESOUI API Package & Upload PowerShell Script
# Author: Trent Apple
#
# Dependencies:
# * 7-Zip (optionally fallback to Compress-Archive)
# * curl (for multipart form uploading)
#
# Instructions: This addon assumes you will retain the default directory structure
# of the "Elder Scrolls Online" folder and that it will be located directly within
# the %USERPROFILE%\Documents\ directory. Please refer to the script's parameters.
#>
param (
[string]$projectDirName,
[switch]$incrementVersionNumber,
[switch]$noCopyIncrementedVersionNumberToClipboard,
[switch]$openExplorer,
[switch]$uploadToEsoui,
[string]$compatibilityVersion, # 5.3.4 - Harrowstorm (100030)
[string]$defaultSevenZipPath = "C:\PROGRA~1\7-Zip\7z.exe",
[string]$esouiApiToken # *or* Environment Variable: ESOUI_API_TOKEN
)
if ([string]::IsNullOrEmpty($esouiApiToken))
{
# Attempt to get value from environment variable
if (![string]::IsNullOrEmpty($env:ESOUI_API_TOKEN))
{
$esouiApiToken = $env:ESOUI_API_TOKEN;
}
else
{
Write-Debug -Message "No included -esouiApiToken command line argument or ESOUI_API_TOKEN environment variable found."
}
}
if ([string]::IsNullOrEmpty($projectDirName))
{
Write-Error -Message "No -projectDirName command line argument found."
}
if (![string]::IsNullOrEmpty($compatibilityVersion) -and $compatibilityVersion -notmatch '^\d+\.\d+\.\d+$')
{
Write-Error -Message "Compatibility version (-compatibilityVersion) must be in the format of 'x.x.x'. The version is based upon the ESO API version."
}
New-Alias Out-Clipboard $env:SystemRoot\system32\clip.exe
filter Select-MatchingGroupValue($groupNum)
{
if (! $groupNum)
{
$groupNum = 0
}
Select-Object -InputObject $_ -ExpandProperty Matches |
Select-Object -ExpandProperty Groups |
Select-Object -Index $groupNum |
Select-Object -ExpandProperty Value
}
$elderScrollsOnlineAddOnPath = Join-Path $env:USERPROFILE -ChildPath "Documents" | Join-Path -ChildPath "Elder Scrolls Online" | Join-Path -ChildPath "live" | Join-Path -ChildPath "AddOns"
$projectArchiveName = ("{0}.zip" -f $projectDirName)
$projectArchiveFilePath = Join-Path $elderScrollsOnlineAddOnPath -ChildPath $projectArchiveName
$projectPath = Join-Path $elderScrollsOnlineAddOnPath -ChildPath $projectDirName
$projectTxtName = ("{0}.txt" -f $projectDirName)
$projectTxtFilePath = Join-Path $projectPath -ChildPath $projectTxtName
$currentVersion = Get-Content $projectTxtFilePath -ErrorAction SilentlyContinue |
Select-String '^## Version: (.*)' |
Select-Object -First 1 |
Select-MatchingGroupValue 1
Write-Host "Current Version: $currentVersion"
$versionTokens = $currentVersion.Split(".")
$major = [int]( $versionTokens[0])
$minor = [int]( $versionTokens[1])
$patch = [int]( $versionTokens[2])
$newVersion = $currentVersion
if ($incrementVersionNumber)
{
if ( $minor -cge 9 -and $patch -cge 9 )
{
$major = $major + 1
$minor = 0
$patch = 0
}
elseif ( $patch -cge 9 )
{
$minor = $minor + 1
$patch = 0
}
else
{
$patch = $patch + 1
}
$newVersion = ([string] $major) + "." + ([string] $minor ) + "." + ([string] $patch)
Write-Host "New Version (Incremented): $newVersion"
if (!$noCopyIncrementedVersionNumberToClipboard)
{
$newVersion | Out-Clipboard
}
# Create Version String
$newVersionWriteString = '## Version: ' + $newVersion
(get-content -ErrorAction SilentlyContinue $projectTxtFilePath) | foreach-object -ErrorAction SilentlyContinue {$_ -replace '^## Version: (.*)', $newVersionWriteString} | set-content -ErrorAction SilentlyContinue $projectTxtFilePath
}
if (Test-Path $projectArchiveFilePath)
{
Remove-Item $projectArchiveFilePath
}
if (Test-Path $defaultSevenZipPath)
{
if (Test-Path $projectPath)
{
Write-Host "Packaging Addon: $projectDirName"
}
else
{
Write-Error -Message "Project directory not found: $projectPath"
}
if ($projectArchiveFilePath -like "*.zip")
{
Write-Host "Creating Archive: $projectArchiveFilePath"
}
else
{
Write-Error -Message "Invalid archive file path: $projectArchiveFilePath"
}
# Perform packaging using 7z (create .zip archive) -- if no 7z then use Compress-Archive
if ($defaultSevenZipPath -like "*.exe")
{
Invoke-Expression "$defaultSevenZipPath a -tzip '$projectArchiveFilePath' '$projectPath' '-x!$projectDirName\.idea' '-x!$projectDirName\.git*'"
}
else
{
Compress-Archive -Path $projectPath -DestinationPath $projectArchiveFilePath -Update -CompressionLevel Optimal -Force -Exclude "$projectDirName\.idea", "$projectDirName\.git*"
}
if ($openExplorer)
{
Invoke-Expression "explorer '/select,""$projectArchiveFilePath""'"
}
if ($uploadToEsoui -and ![string]::IsNullOrEmpty($esouiApiToken))
{
# Get List of Addons
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("x-api-token", $esouiApiToken)
# Curl Command: curl -k -H "x-api-token: <apiToken>" https://api.esoui.com/addons/list.json
$listResponse = Invoke-RestMethod 'https://api.esoui.com/addons/list.json' -Headers $headers
# Fetch the Addon's Details -- match addon id based upon name of last packaged zip file uploaded.
$matchedAddOn = $listResponse | ForEach-Object {
Invoke-RestMethod ($_.details) -Headers $headers |
ForEach-Object {
if ($_.filename -match $projectArchiveName) { $_ }
} | Select-Object -First 1
}
Write-Output $matchedAddOn
$matchedAddonId = $matchedAddOn.id
Write-Output "New Version: $newVersion"
# Upload Addon to ESOUI API -- Current solution requires the installation of curl for Windows. You may use Chocolately (recommended) or manually download to install.
$exec = ('cmd /C curl -k -H "x-api-token:' + $esouiApiToken + '" -F "id=' + $matchedAddonId + '" -F "version=' + $newVersion + '" -F "compatible=' + $compatibilityVersion + '" -F "updatefile=@' + $projectArchiveFilePath + '" https://api.esoui.com/addons/update')
Invoke-Expression $exec
<#
# Upload Addon to ESOUI API -- Would not properly function the same way that the following behaves: `curl -H ... -F ... -F ... -F "updatefile=@C:..." uri`
$FileContent = [IO.File]::ReadAllBytes($projectArchiveFilePath);
$updatePostParams = @{
'id' = $matchedAddOn.id;
'version' = $newVersion;
'updatefile' = $FileContent;
}
# https://api.esoui.com/addons/updatetest
Invoke-RestMethod -Uri 'https://api.esoui.com/addons/updatetest' -Method Post -Headers $headers -Body $updatePostParams
#>
}
}
else
{
Write-Error -Message "7-Zip path in script appears to be missing or invalid. Is it installed?"
}