-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrelease_prod.ps1
95 lines (74 loc) · 2.26 KB
/
release_prod.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
param($message)
# create a function to get the last commit message
function Get-LastCommitMessage {
$lastCommit = Invoke-Expression 'git log -1 --pretty=format:%s'
return $lastCommit
}
function Speak-Message ($message) {
$voice = New-Object -ComObject Sapi.spvoice
# get voices, use one where Id contains ZIRA
$voices = $voice.GetVoices()
$voice.Voice = $voices | Where-Object { $_.Id.Contains("ZIRA") }
$voice.rate = 0
$voice.speak($message)
}
function Exit-With-Error ($message) {
write-host $message
Speak-Message $message
exit 1
}
# check if there are any git changes, and if there are, report them and exit
$gitStatus = git status --porcelain
if ($null -ne $gitStatus) {
# store message as multiline string
$message = "
There are uncommitted changes in git, please make sure everything is committed before doing a release.
Git status:
$gitStatus
"
Exit-With-Error $message
}
if ([System.String]::IsNullOrEmpty($message))
{
$lastCommit = Get-LastCommitMessage
$warningMessage = "Message is missing, would you like to use the last commit message: $lastCommit"
write-host $warningMessage
Speak-Message $warningMessage
$response = Read-Host "y/n"
if ($response -eq "y")
{
$message = $lastCommit
}
else
{
Exit-With-Error "Please provide a message"
}
}
# short hand to use the last commit message, don't ask why 'y' is used
if ($message -eq "y")
{
$message = Get-LastCommitMessage
}
# ensure that $messsage has "'" escaped
$message = $message -replace "'", "''"
Invoke-Expression "dotnet build -c Release"
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0) {
Exit-With-Error "Build failed"
}
Invoke-Expression 'git push'
$v = Invoke-Expression 'git describe --tags --abbrev=0'
write-host $v
$version = new-object System.Version($v.Substring(1))
$newVersion = new-object System.Version($version.Major, $version.Minor, ($version.Build + 1))
$cmd = "git tag -a v$($newVersion) -m '$message'"
Invoke-Expression $cmd
Invoke-Expression "git push --tags"
$cmd = "git checkout prod"
Invoke-Expression $cmd
$cmd = "git merge main -m '$($newVersion): $message'"
Invoke-Expression $cmd
$cmd = "git push"
Invoke-Expression $cmd
$cmd = "git checkout main"
Invoke-Expression $cmd