52 lines
1.7 KiB
PowerShell
52 lines
1.7 KiB
PowerShell
param(
|
|
[Parameter(Mandatory)]
|
|
[ValidateNotNullOrEmpty()]
|
|
[string] $Message,
|
|
[string] $Dotnet = 'dotnet',
|
|
[switch] $Smoke
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
function Invoke-Checked {
|
|
param([string] $Executable, [string[]] $Arguments)
|
|
& $Executable @Arguments
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "$Executable $($Arguments[0]) 退出码 $LASTEXITCODE"
|
|
}
|
|
}
|
|
|
|
Push-Location -LiteralPath $PSScriptRoot
|
|
try {
|
|
$expectedRemote = 'ssh://git@gitea.ttstd.com:2222/tt/TTSTDHarmonyOSCommandLineToolsUI.git'
|
|
$pushRemote = Invoke-Checked git @('remote', 'get-url', '--push', '--all', 'origin')
|
|
if (@($pushRemote).Count -ne 1 -or $pushRemote -cne $expectedRemote) {
|
|
throw "origin 推送地址必须是 $expectedRemote"
|
|
}
|
|
$branch = Invoke-Checked git @('symbolic-ref', '--short', 'HEAD')
|
|
|
|
Invoke-Checked $Dotnet @('build', 'EmulatorManager.csproj', '-c', 'Release')
|
|
$runArguments = @('run', '--project', 'EmulatorManager.csproj', '-c', 'Release', '--no-build')
|
|
if ($Smoke) {
|
|
$runArguments += @('--', '--smoke')
|
|
}
|
|
Invoke-Checked $Dotnet $runArguments
|
|
|
|
Invoke-Checked git @('status', '--short')
|
|
$answer = Read-Host '将以上工作区变更提交并推送到 origin。输入 yes 确认'
|
|
if ($answer -cne 'yes') {
|
|
return
|
|
}
|
|
Invoke-Checked git @('add', '-A')
|
|
& git diff --cached --quiet --exit-code
|
|
switch ($LASTEXITCODE) {
|
|
0 { }
|
|
1 { Invoke-Checked git @('commit', '-m', $Message) }
|
|
default { throw "git diff 退出码 $LASTEXITCODE" }
|
|
}
|
|
Invoke-Checked git @('push', '--set-upstream', 'origin', "HEAD:refs/heads/$branch")
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|