diff --git a/README.md b/README.md index d72fb57..e99bb6d 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,9 @@ GITEA_TOKEN=... .\ck.ps1 clean ``` -`publish` runs fetch, patch, build, and test, then uploads `work/dist/chicken--ucrt64-x86_64.zip`. The tag is `-win` (`revision` in this repo, currently `6.0.0-win1`). If that tag already exists, publish stops. Bump `revision` to ship another build of the same upstream tarball. +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 `-win`. + +`publish` runs fetch, patch, build, and test, then uploads `work/dist/chicken--ucrt64-x86_64.zip`. If that tag already exists, publish stops. Bump `revision` to ship another build of the same upstream tarball. `clean` deletes `work/` only. diff --git a/chicken.json b/chicken.json new file mode 100644 index 0000000..d2605ee --- /dev/null +++ b/chicken.json @@ -0,0 +1,12 @@ +{ + "upstream": { + "version": "6.0.0", + "sha256": "92835552b1b687ad26737e429b5aba36510bf429f8816ec0f6d336c8cb41f443" + }, + "gitea": { + "host": "https://git.kotobank.ch", + "owner": "pkulev", + "repo": "chicken6-4-win" + }, + "revision": 1 +} diff --git a/ck.ps1 b/ck.ps1 index 78e66bd..9d1b7b1 100644 --- a/ck.ps1 +++ b/ck.ps1 @@ -12,13 +12,21 @@ $Work = Join-Path $Root 'work' $Src = Join-Path $Work 'src' $Prefix = Join-Path $Work 'prefix' $Dist = Join-Path $Work 'dist' +$ConfigPath = Join-Path $Root 'chicken.json' -$UpstreamVersion = '6.0.0' -$UpstreamSha256 = '92835552b1b687ad26737e429b5aba36510bf429f8816ec0f6d336c8cb41f443' +function Get-ProjectConfig { + Get-Content -Raw -LiteralPath $ConfigPath | ConvertFrom-Json +} + +function Save-ProjectConfig($Config) { + $json = $Config | ConvertTo-Json -Depth 6 + $utf8 = New-Object System.Text.UTF8Encoding $false + [System.IO.File]::WriteAllText($ConfigPath, $json + "`n", $utf8) +} + +$Config = Get-ProjectConfig +$UpstreamVersion = $Config.upstream.version $UpstreamUrl = "https://code.call-cc.org/releases/$UpstreamVersion/chicken-$UpstreamVersion.tar.gz" -$Gitea = 'https://git.kotobank.ch' -$Owner = 'pkulev' -$RepoName = 'chicken6-4-win' function Import-DotEnv { $path = Join-Path $Root '.env' @@ -68,31 +76,34 @@ function Invoke-Ucrt([string]$Script) { } function Get-Tarball { - Join-Path $Work "chicken-$UpstreamVersion.tar.gz" + Join-Path $Work "chicken-$($Config.upstream.version).tar.gz" } -function Test-Sha256([string]$Path, [string]$Expected) { - $actual = (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLower() - if ($actual -ne $Expected.ToLower()) { - Write-Error "sha256 mismatch for $Path" - exit 1 - } +function Get-FileSha256([string]$Path) { + (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLower() } function Invoke-FetchSources { New-Item -ItemType Directory -Force -Path $Work | Out-Null $tarball = Get-Tarball - $fresh = -not (Test-Path -LiteralPath $tarball) - if (-not $fresh) { - $actual = (Get-FileHash -LiteralPath $tarball -Algorithm SHA256).Hash.ToLower() - $fresh = $actual -ne $UpstreamSha256.ToLower() - } - if ($fresh) { + $expected = [string]$Config.upstream.sha256 + $have = Test-Path -LiteralPath $tarball + $actual = if ($have) { Get-FileSha256 $tarball } else { '' } + $matches = $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" + } 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 } - Test-Sha256 $tarball $UpstreamSha256 if (Test-Path -LiteralPath $Src) { Remove-Item -LiteralPath $Src -Recurse -Force } @@ -139,8 +150,7 @@ function Invoke-Test { } function Get-Revision { - $path = Join-Path $Root 'revision' - return (Get-Content -LiteralPath $path -Raw).Trim() + [string]$Config.revision } function Invoke-Publish { @@ -165,9 +175,9 @@ function Invoke-Publish { & "$env:SystemRoot\System32\tar.exe" -a -cf $zip -C $Prefix . if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - $tag = "$UpstreamVersion-win$(Get-Revision)" + $tag = "$($Config.upstream.version)-win$(Get-Revision)" $headers = @{ Authorization = "token $($env:GITEA_TOKEN)" } - $api = "$Gitea/api/v1/repos/$Owner/$RepoName" + $api = "$($Config.gitea.host)/api/v1/repos/$($Config.gitea.owner)/$($Config.gitea.repo)" try { Invoke-RestMethod -Headers $headers -Uri "$api/releases/tags/$tag" | Out-Null Write-Error "release $tag already exists. Bump revision." diff --git a/revision b/revision deleted file mode 100644 index d00491f..0000000 --- a/revision +++ /dev/null @@ -1 +0,0 @@ -1