-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
54 lines (46 loc) · 2.46 KB
/
build.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
#Requires -Version 5.1
Set-StrictMode -Version 'Latest'
$ErrorActionPreference = 'Stop'
Function StartProcess([String]$FilePath, [String[]]$ArgumentList='') {
$Process = New-Object System.Diagnostics.Process
$Process.StartInfo.FileName = $FilePath
$Process.StartInfo.Arguments = $ArgumentList
$Process.StartInfo.UseShellExecute = $false
$Process.StartInfo.RedirectStandardError = $true
$Process.StartInfo.RedirectStandardOutput = $true
$Process.Start() | Out-Null
$Process.WaitForExit()
Write-Host $Process.StandardOutput.ReadToEnd().replace("$env:GITHUB_TOKEN", '[SECRET]')
Write-Host $Process.StandardError.ReadToEnd().replace("$env:GITHUB_TOKEN", '[SECRET]')
return $Process.ExitCode
}
[string]$version = .\gradlew -s properties | Where { $_ -match '^version: ' } | % { $_ -replace 'version: ', '' }
If ($env:TRAVIS_BRANCH -eq 'master') {
[string]$baseVersion = $version.replace('-SNAPSHOT', '')
Write-Host $baseVersion
[string]$patchVersion = git tag | Where { $_ -match "$baseVersion" } | % { $_ -replace "$baseVersion.", '' } | Sort-Object | Select-Object -Last 1
if($patchVersion) {
([int]$patchVersion)++
} else {
$patchVersion = '0'
}
[string]$newVersion = "$baseVersion.$patchVersion"
(Get-Content 'build.gradle.kts') | Foreach-Object {$_ -replace "[ ]*version[ ]*=[ ]*`"$version`"", "version = `"$newVersion`"" } | Out-File 'build.gradle.kts'
}
./gradlew --no-daemon clean dist
If ($env:TRAVIS_BRANCH -eq 'master') {
StartProcess -FilePath 'git' -ArgumentList 'config', '--global', 'push.default', 'simple'
StartProcess -FilePath 'git' -ArgumentList 'config', '--global', 'user.name', 'Travis CI'
StartProcess -FilePath 'git' -ArgumentList 'config', '--global', 'user.email', '[email protected]'
StartProcess -FilePath 'git' -ArgumentList 'remote', 'add', 'origins', "https://$env:[email protected]/$env:TRAVIS_REPO_SLUG.git"
StartProcess -FilePath 'git' -ArgumentList 'add', 'build.gradle.kts'
StartProcess -FilePath 'git' -ArgumentList 'commit', '-m', "Release $newVersion"
StartProcess -FilePath 'git' -ArgumentList 'push', 'origins', 'master'
StartProcess -FilePath 'git' -ArgumentList 'tag', '-f', "$newVersion"
StartProcess -FilePath 'git' -ArgumentList 'tag', '-f', 'latest'
StartProcess -FilePath 'git' -ArgumentList 'push', '--tags'
}
If ($env:TRAVIS_BRANCH -eq 'master' -or $env:TRAVIS_BRANCH -eq 'develop') {
./gradlew publish
}
exit $LastExitCode