86 lines
1.7 KiB
PowerShell
86 lines
1.7 KiB
PowerShell
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Message,
|
|
|
|
[string[]]$Paths = @(),
|
|
|
|
[switch]$Amend
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function Run-Step {
|
|
param(
|
|
[string]$Name,
|
|
[scriptblock]$Block
|
|
)
|
|
Write-Host "== $Name =="
|
|
& $Block
|
|
}
|
|
|
|
Run-Step "workspace check" {
|
|
powershell -ExecutionPolicy Bypass -File scripts/dev/windows/check-workspace.ps1
|
|
}
|
|
|
|
Run-Step "local tests" {
|
|
powershell -ExecutionPolicy Bypass -File scripts/dev/windows/test-all.ps1
|
|
powershell -ExecutionPolicy Bypass -File scripts/dev/windows/check-secrets.ps1
|
|
}
|
|
|
|
Run-Step "git preflight" {
|
|
$branch = & git branch --show-current
|
|
if ($branch -ne "main") {
|
|
throw "Branch must be main, actual: $branch"
|
|
}
|
|
|
|
$origin = & git remote get-url origin
|
|
if ($origin -ne "ssh://git@git.txyundm.cn:2222/panda/qipai.git") {
|
|
throw "Invalid origin: $origin"
|
|
}
|
|
|
|
& git status --short --branch --untracked-files=all
|
|
}
|
|
|
|
Run-Step "stage files" {
|
|
if ($Paths.Count -gt 0) {
|
|
foreach ($path in $Paths) {
|
|
& git add -- $path
|
|
}
|
|
}
|
|
else {
|
|
Write-Host "No paths supplied. Review status and stage files manually, then rerun with -Paths."
|
|
throw "No paths supplied."
|
|
}
|
|
|
|
& git diff --cached --stat
|
|
if (-not (& git diff --cached --name-only)) {
|
|
throw "No staged changes."
|
|
}
|
|
}
|
|
|
|
Run-Step "commit" {
|
|
if ($Amend) {
|
|
& git commit --amend --no-edit
|
|
}
|
|
else {
|
|
& git commit -m $Message
|
|
}
|
|
}
|
|
|
|
Run-Step "push" {
|
|
& git push origin main
|
|
}
|
|
|
|
Run-Step "remote verify" {
|
|
& git fetch origin main
|
|
$head = & git rev-parse HEAD
|
|
$remote = & git rev-parse origin/main
|
|
if ($head -ne $remote) {
|
|
throw "Remote verification failed: HEAD=$head origin/main=$remote"
|
|
}
|
|
& git log -1 --oneline origin/main
|
|
}
|
|
|
|
Write-Host "PASS: module pushed and verified."
|
|
|