Add -Latest to fetch whatever releases/current is serving.

The pinned version and hash stay in chicken.json unless that flag overwrites them.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-09 01:36:58 +03:00
parent 6057eedb2c
commit 55c87a438f
2 changed files with 43 additions and 11 deletions

View File

@@ -37,7 +37,7 @@ GITEA_TOKEN=...
.\ck.ps1 clean
```
Versions live in `chicken.json`. The script loads and saves it with `ConvertFrom-Json` and `ConvertTo-Json`. Change `upstream.version` and clear `upstream.sha256`; `fetch-sources` downloads that release and writes the hash back. `revision` is the local serial in the same file. The tag is `<version>-win<revision>`.
Versions live in `chicken.json`. The script loads and saves it with `ConvertFrom-Json` and `ConvertTo-Json`. Change `upstream.version` and clear `upstream.sha256`; `fetch-sources` downloads that release and writes the hash back. `.\ck.ps1 fetch-sources -Latest` (and `publish -Latest`) instead takes whatever `https://code.call-cc.org/releases/current/` is serving and overwrites `upstream.version` and `upstream.sha256`. `revision` is the local serial in the same file. The tag is `<version>-win<revision>`.
`publish` runs fetch, patch, build, and test, then uploads `work/dist/chicken-<version>-ucrt64-x86_64.zip`. If that tag already exists, publish stops. Bump `revision` to ship another build of the same upstream tarball.

52
ck.ps1
View File

@@ -1,9 +1,12 @@
# Build and publish a UCRT64 CHICKEN 6 prefix.
# .\ck.ps1 fetch-sources | patch | build | test | publish | clean
# .\ck.ps1 publish -Latest
param(
[Parameter(Mandatory = $true, Position = 0)]
[ValidateSet('fetch-sources', 'patch', 'build', 'test', 'publish', 'clean')]
[string]$Command
[string]$Command,
[switch]$Latest
)
$ErrorActionPreference = 'Stop'
@@ -75,6 +78,21 @@ function Invoke-Ucrt([string]$Script) {
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
function Get-LatestUpstream {
$index = 'https://code.call-cc.org/releases/current/'
$page = & curl.exe -fsSL $index
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
$text = if ($page -is [array]) { $page -join "`n" } else { [string]$page }
$found = [regex]::Matches($text, 'chicken-(\d+(?:\.\d+){2,})\.tar\.gz') |
ForEach-Object { $_.Groups[1].Value } |
Select-Object -Unique
if (-not $found) {
Write-Error "no CHICKEN tarball linked from $index"
exit 1
}
$found | Sort-Object { [version]$_ } -Descending | Select-Object -First 1
}
function Get-Tarball {
Join-Path $Work "chicken-$($Config.upstream.version).tar.gz"
}
@@ -84,22 +102,34 @@ function Get-FileSha256([string]$Path) {
}
function Invoke-FetchSources {
param([switch]$Latest)
New-Item -ItemType Directory -Force -Path $Work | Out-Null
$previousVersion = [string]$Config.upstream.version
$previousSha = [string]$Config.upstream.sha256
if ($Latest) {
$Config.upstream.version = Get-LatestUpstream
$script:UpstreamVersion = $Config.upstream.version
$script:UpstreamUrl = "https://code.call-cc.org/releases/$UpstreamVersion/chicken-$UpstreamVersion.tar.gz"
Write-Host "latest release is $UpstreamVersion"
}
$tarball = Get-Tarball
$expected = [string]$Config.upstream.sha256
$expected = if ($Latest) { '' } else { $previousSha }
$have = Test-Path -LiteralPath $tarball
$actual = if ($have) { Get-FileSha256 $tarball } else { '' }
$matches = $have -and $expected -and ($actual -eq $expected.ToLower())
$matches = -not $Latest -and $have -and $expected -and ($actual -eq $expected.ToLower())
if (-not $matches) {
Write-Host "downloading $UpstreamUrl"
& curl.exe -fL --retry 2 -o $tarball $UpstreamUrl
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
$actual = Get-FileSha256 $tarball
}
if (-not $expected) {
$Config.upstream.sha256 = $actual
Save-ProjectConfig $Config
Write-Host "recorded sha256 in chicken.json"
if ($Latest -or -not $previousSha) {
if ($Config.upstream.version -ne $previousVersion -or $actual -ne $previousSha.ToLower()) {
$Config.upstream.sha256 = $actual
Save-ProjectConfig $Config
Write-Host "recorded $UpstreamVersion $actual in chicken.json"
}
} elseif ($actual -ne $expected.ToLower()) {
Write-Error "sha256 mismatch for $($Config.upstream.version). Clear upstream.sha256 in chicken.json to record the new tarball."
exit 1
@@ -154,12 +184,14 @@ function Get-Revision {
}
function Invoke-Publish {
param([switch]$Latest)
Import-DotEnv
if ([string]::IsNullOrEmpty($env:GITEA_TOKEN)) {
Write-Error "GITEA_TOKEN is not set. Put it in .env (not committed)."
exit 1
}
Invoke-FetchSources
Invoke-FetchSources -Latest:$Latest
Invoke-Patch
Invoke-Build
Invoke-Test
@@ -202,11 +234,11 @@ function Invoke-Publish {
}
switch ($Command) {
'fetch-sources' { Invoke-FetchSources }
'fetch-sources' { Invoke-FetchSources -Latest:$Latest }
'patch' { Invoke-Patch }
'build' { Invoke-Build }
'test' { Invoke-Test }
'publish' { Invoke-Publish }
'publish' { Invoke-Publish -Latest:$Latest }
'clean' {
if (Test-Path -LiteralPath $Work) {
Remove-Item -LiteralPath $Work -Recurse -Force