Files
jobboard/deploy/1-test-and-promote.ps1
T
WolfandClaude Opus 5.5 515d2250fc Deploy from a WSL checkout, from boilerplate 1679e88
When the checkout lives under \\wsl.localhost, step 1 runs its tests in the
distro through deploy/test-commit.sh and db.ps1 push makes its snapshot
there, because the .venv is a Linux one. pipeline/context.py narrows by
sys.platform so mypy passes on Linux. See boilerplate docs/wsl.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-26 19:43:50 +02:00

91 lines
4.0 KiB
PowerShell

<#
.SYNOPSIS
Test the latest local main commit and fast-forward production to it.
.DESCRIPTION
Uses a fixed commit and an isolated worktree. PushBranch optionally publishes
production to origin; without it promotion stays local. Does not run Docker.
#>
[CmdletBinding()]
param([switch] $PushBranch, [switch] $NoTests)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
. "$PSScriptRoot/_common.ps1"
$Source = Setting SOURCE 'main'
$Branch = Setting BRANCH 'production'
$Python = Setting PYTHON (Join-Path $root '.venv\Scripts\python.exe')
Push-Location $root
try {
$commit = git rev-parse --verify "$Source^{commit}"
Assert-Ok 'resolve source commit'
$commit = $commit.Trim()
# ------------------------------------------------------- test the commit
# In a throwaway worktree, not here. The tests then run against exactly the
# tree that is about to become production, with none of the working copy's
# uncommitted edits in the way. Worktrees have no .venv of their own, so the
# interpreter comes from the main checkout and the code from the worktree.
#
# A checkout inside WSL has a Linux .venv, so there the same steps run in
# the distro through deploy/test-commit.sh.
if (-not $NoTests -and $Wsl.Success) {
Write-Step "tests on $Source, in WSL $($Wsl.Groups[1].Value)"
wsl.exe -d $Wsl.Groups[1].Value --cd (ConvertTo-LinuxPath $root) -- sh deploy/test-commit.sh $commit
Assert-Ok 'tests'
} elseif (-not $NoTests) {
Write-Step "tests on $Source"
if (-not (Test-Path $Python)) {
throw "no interpreter at $Python - set PYTHON in deploy\release.env"
}
$base = Join-Path ([IO.Path]::GetTempPath()) ("$Name-test-" + [guid]::NewGuid().ToString('N').Substring(0, 8))
$tree = Join-Path $base $Name
try {
git worktree add --detach $tree $commit | Out-Null
Assert-Ok 'git worktree add'
Push-Location $tree
try {
# Your project's checks. A gate that is red for weeks is not a
# gate -- it is a flag you learn to type -- so take one out when
# it stops meaning anything, and put it back when it is green.
#
# The starter's dev group is pytest and httpx, so pytest is the
# only gate that can run out of the box. Add ruff and mypy to
# [dependency-groups] dev in pyproject.toml, then uncomment the
# two lines below -- a gate whose tool is not installed fails
# every release for a reason that has nothing to do with the code.
& $Python -m pytest -q; Assert-Ok 'pytest'
# & $Python -m ruff check .; Assert-Ok 'ruff'
# & $Python -m mypy --cache-dir (Join-Path $root '.mypy_cache')
# Assert-Ok 'mypy'
} finally { Pop-Location }
} finally {
git worktree remove --force $tree 2>$null | Out-Null
Remove-ReleaseTemp @($base)
}
}
# ------------------------------------------------------------- promote
# Fast-forward only. If production has commits main does not, that is a
# release made from somewhere else, and this stops rather than discarding it.
Write-Step "promote $Source -> $Branch"
git show-ref --verify --quiet "refs/heads/$Branch"
if ($LASTEXITCODE -eq 0) {
git merge-base --is-ancestor $Branch $commit
if ($LASTEXITCODE -ne 0) {
Write-Host "$Branch is not an ancestor of $Source - it has commits of its own." -ForegroundColor Red
throw "look at: git log --oneline $Source..$Branch"
}
}
# Git publication is optional and independent of the image.
git branch -f $Branch $commit; Assert-Ok 'git branch -f'
if ($PushBranch) {
git push origin "${commit}:refs/heads/$Branch"
Assert-Ok 'publish production branch'
}
Write-Host "Promoted $Branch to $commit"
} finally { Pop-Location }