From 091564cdcec4577fdfd4509975c319448e9392ba Mon Sep 17 00:00:00 2001 From: Revela Date: Mon, 16 Mar 2026 03:25:00 -0500 Subject: [PATCH] Enhance nightly release script for client and server Updated the script to build zips for both client and server, including new variables for server release management. Added functionality to create a server zip, fetch server release info, delete old assets, and upload the new server zip to GitHub. The script now updates the server release title with the latest commit hash and provides clearer output messages for both client and server releases. --- Update-NightlyRelease.ps1 | 138 +++++++++++++++++++++++++++++++++++--- 1 file changed, 127 insertions(+), 11 deletions(-) diff --git a/Update-NightlyRelease.ps1 b/Update-NightlyRelease.ps1 index 2fcc4ce2..635147d6 100644 --- a/Update-NightlyRelease.ps1 +++ b/Update-NightlyRelease.ps1 @@ -1,13 +1,12 @@ #Requires -Version 5.1 <# .SYNOPSIS - Builds a zip, updates the Nightly GitHub release, and archives locally. + Builds zips for client and server, updates their Nightly GitHub releases, and archives locally. .DESCRIPTION 1. Fetches the latest commit hash. - 2. Zips x64\Release contents directly into the archive folder (excluding .pch files). - 3. Deletes old assets from the Nightly release on GitHub. - 4. Uploads LCEWindows64.zip, Minecraft.Client.exe, and Minecraft.Client.pdb. - 5. Updates the release title with the latest commit hash (first 7 chars). + 2. Zips client (x64\Release) and server (x64\Minecraft.Server\Release) builds into the archive folder. + 3. Updates the Nightly release: deletes old assets, uploads client zip + exe + pdb, updates title. + 4. Updates the Nightly-Dedicated-Server release: deletes old assets, uploads server zip, updates title. .NOTES Requires GITHUB_TOKEN environment variable to be set. #> @@ -21,6 +20,9 @@ $RepoName = "MinecraftConsoles" $ReleaseTag = "Nightly" $ReleaseDir = Join-Path $PSScriptRoot "x64\Release" $ZipName = "LCEWindows64.zip" +$ServerReleaseTag = "Nightly-Dedicated-Server" +$ServerReleaseDir = Join-Path $PSScriptRoot "x64\Minecraft.Server\Release" +$ServerZipName = "LCEServerWindows64.zip" $ArchiveRoot = "C:\Users\rexma\Documents\Minecraft\itsRevelaReleases" $ApiBase = "https://api.github.com/repos/$RepoOwner/$RepoName" @@ -110,6 +112,62 @@ finally { Write-Host " Created: $ZipPath" -ForegroundColor Green +# --- Step 2b: Zip the server build into the same archive folder --- +Write-Host "==> Creating $ServerZipName in archive folder..." -ForegroundColor Cyan + +$ServerZipPath = Join-Path $archiveFolder $ServerZipName + +if (Test-Path $ServerZipPath) { + Remove-Item $ServerZipPath -Force +} + +$serverTopLevelFolder = "LCEServerWindows64" + +$sfs = [System.IO.File]::Open($ServerZipPath, [System.IO.FileMode]::Create) +try { + $szip = New-Object System.IO.Compression.ZipArchive($sfs, [System.IO.Compression.ZipArchiveMode]::Create) + + try { + $serverBasePath = (Resolve-Path $ServerReleaseDir).Path + + # Add empty directories so they exist when extracted + Get-ChildItem -Path $serverBasePath -Recurse -Directory | ForEach-Object { + $dirFullPath = $_.FullName + $relativePath = $dirFullPath.Substring($serverBasePath.Length).TrimStart('\','/') + $entryName = ($serverTopLevelFolder + "/" + ($relativePath -replace '\\','/') + "/") + $szip.CreateEntry($entryName) | Out-Null + } + + Get-ChildItem -Path $serverBasePath -Recurse -File | ForEach-Object { + $fullPath = $_.FullName + + if ($_.Extension -ieq ".pch" -or $_.Extension -ieq ".zip") { + return + } + + $relativePath = $fullPath.Substring($serverBasePath.Length).TrimStart('\','/') + $entryName = ($serverTopLevelFolder + "/" + ($relativePath -replace '\\','/')) + + Write-Host " Adding: $entryName" + + [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile( + $szip, + $fullPath, + $entryName, + [System.IO.Compression.CompressionLevel]::Optimal + ) | Out-Null + } + } + finally { + $szip.Dispose() + } +} +finally { + $sfs.Dispose() +} + +Write-Host " Created: $ServerZipPath" -ForegroundColor Green + # --- Step 3: Get the Nightly release info --- Write-Host "==> Fetching Nightly release info..." -ForegroundColor Cyan @@ -164,7 +222,7 @@ Write-Host "==> Updating release title..." -ForegroundColor Cyan # Replace the old 7-char hash in the title with the new one # Title format: "Latest: 8bd6690 (+Hardcore Mode)" -$newTitle = $currentTitle -replace '(?<=Latest:\s{1,4})[0-9a-f]{7}', $shortHash +$newTitle = $currentTitle -replace '(?<=Client:\s{1,4})[0-9a-f]{7}', $shortHash if ($newTitle -eq $currentTitle -and $currentTitle -notmatch $shortHash) { # Fallback if regex didn't match — just set a reasonable title @@ -178,10 +236,68 @@ $body = @{ name = $newTitle } | ConvertTo-Json Invoke-RestMethod -Uri "$ApiBase/releases/$releaseId" -Headers $Headers -Method Patch -Body $body -ContentType "application/json" | Out-Null Write-Host " Title updated." -ForegroundColor Green +# --- Step 7: Get the Nightly-Dedicated-Server release info --- +Write-Host "==> Fetching Nightly-Dedicated-Server release info..." -ForegroundColor Cyan + +$serverRelease = Invoke-RestMethod -Uri "$ApiBase/releases/tags/$ServerReleaseTag" -Headers $Headers -Method Get +$serverReleaseId = $serverRelease.id +$serverCurrentTitle = $serverRelease.name +Write-Host " Release ID: $serverReleaseId" +Write-Host " Current title: $serverCurrentTitle" + +# --- Step 8: Delete existing server release assets --- +Write-Host "==> Deleting old server assets..." -ForegroundColor Cyan + +foreach ($asset in $serverRelease.assets) { + Write-Host " Deleting: $($asset.name) (ID: $($asset.id))" + Invoke-RestMethod -Uri "$ApiBase/releases/assets/$($asset.id)" -Headers $Headers -Method Delete +} + +# --- Step 9: Upload server zip --- +Write-Host "==> Uploading server assets..." -ForegroundColor Cyan + +$serverUploadBase = "https://uploads.github.com/repos/$RepoOwner/$RepoName/releases/$serverReleaseId/assets" + +if (-not (Test-Path $ServerZipPath)) { + Write-Error "File not found: $ServerZipPath" + exit 1 +} + +$serverUploadUrl = "$serverUploadBase`?name=$ServerZipName" +$serverFileBytes = [System.IO.File]::ReadAllBytes($ServerZipPath) +$serverSizeMB = [math]::Round($serverFileBytes.Length / 1MB, 2) +Write-Host " Uploading: $ServerZipName ($serverSizeMB MB)..." + +Invoke-RestMethod -Uri $serverUploadUrl -Headers @{ + Authorization = "token $Token" + Accept = "application/vnd.github+json" + "Content-Type" = "application/zip" +} -Method Post -Body $serverFileBytes | Out-Null + +Write-Host " Uploaded: $ServerZipName" -ForegroundColor Green + +# --- Step 10: Update server release title with latest commit hash --- +Write-Host "==> Updating server release title..." -ForegroundColor Cyan + +$serverNewTitle = $serverCurrentTitle -replace '(?<=Server:\s{1,4})[0-9a-f]{7}', $shortHash + +if ($serverNewTitle -eq $serverCurrentTitle -and $serverCurrentTitle -notmatch $shortHash) { + $serverNewTitle = "Server: $shortHash" + Write-Host " Warning: Could not parse existing title format, using fallback." -ForegroundColor Yellow +} + +Write-Host " New title: $serverNewTitle" + +$serverBody = @{ name = $serverNewTitle } | ConvertTo-Json +Invoke-RestMethod -Uri "$ApiBase/releases/$serverReleaseId" -Headers $Headers -Method Patch -Body $serverBody -ContentType "application/json" | Out-Null +Write-Host " Title updated." -ForegroundColor Green + # --- Done --- Write-Host "" -Write-Host "==> Nightly release updated successfully!" -ForegroundColor Green -Write-Host " Commit: $shortHash" -Write-Host " Title: $newTitle" -Write-Host " Assets: $ZipName, Minecraft.Client.exe, Minecraft.Client.pdb" -Write-Host " Archive: $archiveFolder\$ZipName" +Write-Host "==> Nightly releases updated successfully!" -ForegroundColor Green +Write-Host " Commit: $shortHash" +Write-Host " Client title: $newTitle" +Write-Host " Client assets: $ZipName, Minecraft.Client.exe, Minecraft.Client.pdb" +Write-Host " Server title: $serverNewTitle" +Write-Host " Server assets: $ServerZipName" +Write-Host " Archive: $archiveFolder"