-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare-release.ps1
63 lines (51 loc) · 2.2 KB
/
prepare-release.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
#
# Use this script to generate a zip file to upload to farmingsimulators modhub
#
$modDirectory = Split-Path -Path $pwd -Leaf
$modName = "$modDirectory";
$origModName = $modName
$modDescFileName = "$modDirectory/modDesc.xml"
$testRunnerLogPath = ".\.testrunner\"
$readmeFilePath = "README.md"
$isDevelopmentVersion = 0
$xmlData = [xml] (Get-Content $modDescFileName -Encoding UTF8)
$currentVersion = $xmlData.modDesc.version
$newVersion = read-host -Prompt "Please enter a new version (like: a.b.c.d). Current Version is: $currentVersion "
if (([string]::IsNullOrEmpty($newVersion)))
{
$newVersion = "$currentVersion"
}
# Check if we have a update version
if ( $newVersion -ne "1.0.0.0" )
{
$modName = "$($modName)_update"
}
$devVersionConfirmation = read-host -Prompt "DEV version? (y/N) "
if ($devVersionConfirmation -eq 'y') {
$currentGitHash = ((git rev-parse --short HEAD) | Out-String).Trim()
$newVersion = "$newVersion-$currentGitHash"
$isDevelopmentVersion = 1
$modName = "$($origModName)_dev_release"
}
# Write new moddesc version
$xmlData = [xml] (Get-Content $modDescFileName -Encoding UTF8)
$backupXmlData = $xmlData.Clone()
$xmlData.modDesc.version = "$newVersion"
$utf8WithoutBom = New-Object System.Text.UTF8Encoding($false)
$xmlStreamWriter = New-Object System.IO.StreamWriter($modDescFileName, $false, $utf8WithoutBom)
$xmlData.Save( $xmlStreamWriter )
$xmlStreamWriter.Close()
# Write new readme version
((Get-Content -path $readmeFilePath -Raw) -replace "Modhub-v$currentVersion","Modhub-v$newVersion") | Set-Content -NoNewline -Path $readmeFilePath
# Make test run (add testrunner path to your environment path)
New-Item -ItemType Directory -Force -Path "$testRunnerLogPath"
TestRunner_public --logPath "$testRunnerLogPath" --outputPath "$testRunnerLogPath" --noPause "$modDirectory\"
# Make zip file
7z a -bd -stl -tzip -mx=9 "$modName.zip" "$modDirectory/."
# Write old moddesc version back if we have a dev version
if ($isDevelopmentVersion -eq '1') {
$utf8WithoutBom = New-Object System.Text.UTF8Encoding($false)
$xmlStreamWriter = New-Object System.IO.StreamWriter($modDescFileName, $false, $utf8WithoutBom)
$backupXmlData.Save( $xmlStreamWriter )
$xmlStreamWriter.Close()
}