-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-release.ps1
131 lines (115 loc) · 3.5 KB
/
create-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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
$ErrorActionPreference = "Stop"
Function check-result {
if ($LastExitCode -ne 0) { Invoke-BuildError "ERROR: Exiting with error code $LastExitCode" }
return $true
}
Function Invoke-BuildError {
Param(
[parameter(Mandatory=$true)][string] $text
)
if ($env:TEAMCITY_VERSION) {
Write-Error "##teamcity[message text='$text']" # so number of failed tests shows in builds list instead of this text
Write-Error "##teamcity[buildStatus status='ERROR']"
[System.Environment]::Exit(1)
} else {
Write-Error $text
exit
}
}
Function Invoke-Exe {
Param(
[parameter(Mandatory = $true)][string] $cmd,
[parameter(Mandatory = $true)][string] $args
)
Write-Output "Executing: `"$cmd`" --% $args"
& "$cmd" "--%" "$args";
$result = check-result
if (!$result) {
throw "ERROR executing EXE"
exit 1
}
}
Function Get-Version {
if ((Test-Path 'appveyor.yml') -and !(Test-Path 'repository.json')) {
Get-Content appveyor.yml | ForEach-Object {
# version: 1.0.{build}
if ($_ -like 'version: *') {
$version = $_ -replace 'version: ', ''
$version = $version -replace '.{build}', ''
return $version
} else {
#echo $_
}
}
} else {
$config = Get-Content './repository.json' -raw | ConvertFrom-Json
return $config.version
}
}
Function Update-Version {
if ((Test-Path 'appveyor.yml') -and !(Test-Path 'repository.json')) {
$contents = Get-Content appveyor.yml
$contents | ForEach-Object {
# version: 1.0.{build}
if ($_ -like 'version: *') {
$version = $_ -replace 'version: ', ''
$version = $version -replace '.{build}', ''
$v = [version] $version
$versionStringIncremented = [string] [version]::new(
$v.Major,
$v.Minor+1
)
"version: $($versionStringIncremented).{build}"
} else {
$_
}
} | Set-Content appveyor.yml
git commit -m "update version" appveyor.yml
} else {
$config = Get-Content './repository.json' -raw | ConvertFrom-Json
$version = [version] $config.version
$versionStringIncremented = [string] [version]::new(
$version.Major,
$version.Minor+1
)
$config.version = $versionStringIncremented
$config | ConvertTo-Json -depth 32 | set-content './repository.json'
$config | ConvertTo-Json -depth 32 | Format-Json | Out-File -FilePath './repository.json' -Encoding utf8
git commit -m "update version" ./repository.json
}
}
# common repository functions
Import-Module .\Repository.psm1 -Force
Invoke-Exe -cmd git -args "checkout master"
Invoke-Exe -cmd git -args "pull"
Invoke-Exe -cmd git -args "checkout develop"
Invoke-Exe -cmd git -args "pull"
Invoke-Exe -cmd git -args "merge master"
Invoke-Exe -cmd git -args "push"
$version = Get-Version
$branch = "release/$($version)"
echo $branch
$exists = (git ls-remote origin $branch)
if ($exists.Length -eq 0) {
git checkout -b $branch
$releaseNotes = ./generate-changelog.ps1 -version $version -WithReturn
git add CHANGELOG.md
git commit -m "generate changelog"
#git push
git push --set-upstream origin $branch
$remote = (git remote -v)
$ghexists = if (Get-Command "gh.exe" -ErrorAction SilentlyContinue) { $true } else { $false }
if ($remote -like "*github.com*" -and $ghexists) {
gh repo set-default
gh pr create --title "Release $version" --body "$releaseNotes" --base master
} else {
echo "should create the pr here -- everything passed - $branch"
echo $body
}
git checkout develop
git merge $branch
Update-Version
git push
} else {
echo "release branch already exists"
}