This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish_release.ps1
117 lines (102 loc) · 3.67 KB
/
publish_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
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
$go = $args[0]
$wdir = Get-Item .
Write-Host
Write-Host ("Starting continous integration for '" + $wdir.Name + "'") -ForegroundColor Yellow
Write-Host
[string]$gitStatus = (git status --porcelain)
if ($gitStatus) {
Write-Host
Write-Host 'Preparing a release...' -ForegroundColor Yellow
}
else {
Write-Error 'Nothing to commit as a release!' -ErrorAction Stop
}
Write-Host
Write-Host 'Doing a git pull...' -ForegroundColor Yellow
git pull
Write-Host
Write-Host 'Doing a build...' -ForegroundColor Yellow
$buildResult = (dotnet build *>&1)
if ($LASTEXITCODE -eq 0) {
Write-Host "Build ok!" -ForegroundColor Green
}
else {
Write-Host
$buildResult = $buildResult -join [System.Environment]::NewLine
Write-Error $buildResult -ErrorAction Stop
Write-Host
Write-Host 'NO GO: Build failed!' -ForegroundColor Magenta
exit
}
Write-Host
Write-Host 'Running tests...' -ForegroundColor Yellow
$testResult = (dotnet test *>&1)
if ($LASTEXITCODE -eq 0) {
Write-Host "Tests ok!" -ForegroundColor Green
}
else {
Write-Host
$testResult = $testResult -join [System.Environment]::NewLine
Write-Error $testResult
Write-Host
Write-Host 'NO GO: Tests failed!' -ForegroundColor Magenta
Write-Host
exit
}
Write-Host
$releaseFile = Get-ChildItem -Path '.\release.xml'
if ($releaseFile) {
[XML]$relaseXml = Get-Content $releaseFile
$devProjectFile = Get-ChildItem -Path ($relaseXml.release.devProjectFile)
if ($devProjectFile) {
[XML]$devXml = Get-Content $devProjectFile
[string]$devVersion = $devXml.Project.PropertyGroup.Version
[string]$repoTxt = (New-Object System.Net.WebClient).DownloadString($relaseXml.release.repoProjectFileUri)
if (-not $repoTxt) {
Write-Error 'Failed to read repo project file' -ErrorAction Stop
}
[XML]$repoXml = $repoTxt
[string]$repoVersion = $repoXml.Project.PropertyGroup.Version
Write-Host
Write-Host ("Previous release is '" + $repoVersion + "'") -ForegroundColor Yellow
Write-Host ("New release is '" + $devVersion + "'") -ForegroundColor Yellow
if ($devVersion -gt $repoVersion)
{
[string]$releaseIssue = $relaseXml.release.releaseIssue
if ($releaseIssue) {
[string]$issues = ($relaseXml.release.issues.issue) -join ', #'
[string]$commitMessage = ($devVersion + ' (#' + $releaseIssue + ')')
if ($issues) {
$commitMessage = ($commitMessage + ' -> (' + '#' + $issues + ')')
}
Write-Host
Write-Host ("Will do release with the following commit message if given the GO signal: '" + $commitMessage + "'") -ForegroundColor Yellow
if ($go -and ($go -eq 'GO')) {
Write-Host
Write-Host ("GO signal given... doing release '" + $devVersion + "'") -ForegroundColor Yellow
Write-Host
git add .
git commit -m $commitMessage
git push
}
else {
Write-Host
Write-Host ("GO signal NOT given (this is a dry run)... '" + $devVersion + "' NOT released") -ForegroundColor Yellow #tested
}
}
else {
Write-Error 'Missing release issue'
}
}
else {
Write-Error ('Dev version (' + $devVersion + ') not greater than repo version (' + $repoVersion + ')')
}
}
else {
Write-Error 'Missing dev project file'
}
}
else {
Write-Error 'Missing release.xml in current dir'
}
Write-Host