Synchronize local branch after publishing
Some checks failed
Validate Decky / web-client (push) Has been cancelled
Some checks failed
Validate Decky / web-client (push) Has been cancelled
This commit is contained in:
parent
a0b46497c1
commit
e7b2326521
3 changed files with 51 additions and 15 deletions
|
|
@ -12,6 +12,35 @@ param(
|
|||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repositoryRoot = Split-Path -Parent $PSScriptRoot
|
||||
$releaseDirectory = Join-Path $repositoryRoot "artifacts\release\v$Version"
|
||||
$latestJsonPath = Join-Path $releaseDirectory 'latest.json'
|
||||
if (-not (Test-Path -LiteralPath $latestJsonPath)) { throw "Run Prepare-Release.ps1 first: $latestJsonPath is missing." }
|
||||
|
||||
function Invoke-GitCommand {
|
||||
param([Parameter(Mandatory)][string[]]$ArgumentList)
|
||||
$output = @(& git -C $repositoryRoot @ArgumentList 2>&1)
|
||||
if ($LASTEXITCODE) {
|
||||
throw "git $($ArgumentList -join ' ') failed: $($output -join [Environment]::NewLine)"
|
||||
}
|
||||
return $output
|
||||
}
|
||||
|
||||
$branch = ((Invoke-GitCommand @('rev-parse', '--abbrev-ref', 'HEAD')) | Select-Object -Last 1).Trim()
|
||||
if ($branch -ne 'main') { throw "Releases must be published from main; the current branch is '$branch'." }
|
||||
|
||||
$workingChanges = @(Invoke-GitCommand @('status', '--porcelain'))
|
||||
if ($workingChanges.Count) {
|
||||
throw "Commit or discard all source changes before publishing:`n$($workingChanges -join [Environment]::NewLine)"
|
||||
}
|
||||
|
||||
Invoke-GitCommand @('fetch', 'origin', 'main') | Out-Null
|
||||
$localHead = ((Invoke-GitCommand @('rev-parse', 'HEAD')) | Select-Object -Last 1).Trim()
|
||||
$remoteHead = ((Invoke-GitCommand @('rev-parse', 'origin/main')) | Select-Object -Last 1).Trim()
|
||||
if ($localHead -ne $remoteHead) {
|
||||
throw 'Local main does not exactly match origin/main. Pull/rebase or push the source before publishing.'
|
||||
}
|
||||
|
||||
if (-not $Token) {
|
||||
Write-Host 'A Forgejo personal access token is required to create the release.' -ForegroundColor Cyan
|
||||
Write-Host 'The token is used only by this process and is not saved by Decky.' -ForegroundColor DarkGray
|
||||
|
|
@ -20,11 +49,6 @@ if (-not $Token) {
|
|||
}
|
||||
if (-not $Token) { throw 'No Forgejo personal access token was entered.' }
|
||||
|
||||
$repositoryRoot = Split-Path -Parent $PSScriptRoot
|
||||
$releaseDirectory = Join-Path $repositoryRoot "artifacts\release\v$Version"
|
||||
$latestJsonPath = Join-Path $releaseDirectory 'latest.json'
|
||||
if (-not (Test-Path -LiteralPath $latestJsonPath)) { throw "Run Prepare-Release.ps1 first: $latestJsonPath is missing." }
|
||||
|
||||
$headers = @{ Authorization = "token $Token"; Accept = 'application/json' }
|
||||
$apiRoot = "$($ForgejoBaseUrl.TrimEnd('/'))/api/v1/repos/$Repository"
|
||||
$tag = "v$Version"
|
||||
|
|
@ -82,3 +106,14 @@ $contentBody = @{
|
|||
if ($sha) { $contentBody.sha = $sha }
|
||||
Invoke-RestMethod -Method Put -Uri "$apiRoot/contents/releases/latest.json" -Headers $headers -ContentType 'application/json' -Body ($contentBody | ConvertTo-Json) | Out-Null
|
||||
Write-Host "Published Decky $Version and updated releases/latest.json."
|
||||
|
||||
Invoke-GitCommand @('fetch', 'origin', 'main') | Out-Null
|
||||
$publishedHead = ((Invoke-GitCommand @('rev-parse', 'origin/main')) | Select-Object -Last 1).Trim()
|
||||
if ($publishedHead -ne $localHead) {
|
||||
$mergeBase = ((Invoke-GitCommand @('merge-base', $localHead, $publishedHead)) | Select-Object -Last 1).Trim()
|
||||
if ($mergeBase -ne $localHead) {
|
||||
throw 'The release was published, but origin/main also changed independently. Fetch and reconcile it manually.'
|
||||
}
|
||||
Invoke-GitCommand @('merge', '--ff-only', 'origin/main') | Out-Null
|
||||
}
|
||||
Write-Host 'Local main is synchronized with the Forgejo release metadata commit.'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue