Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce35f98fb7 | ||
|
|
ef2f78ff91 | ||
|
|
159e12c79a | ||
|
|
dae0123a17 | ||
|
|
391127c5b9 |
+21
-3
@@ -60,22 +60,39 @@ find_editor() {
|
|||||||
find "$EDITOR_DIR" -maxdepth 3 -type f -name 'Godot*' -print -quit
|
find "$EDITOR_DIR" -maxdepth 3 -type f -name 'Godot*' -print -quit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_export_templates() {
|
||||||
|
local staging_directory="$1"
|
||||||
|
local staged_templates="$staging_directory/templates"
|
||||||
|
local staged_version="$staged_templates/version.txt"
|
||||||
|
local actual_template_version
|
||||||
|
|
||||||
|
[[ -f "$staged_version" ]] || fail "The export-template archive '$TEMPLATES_ASSET' did not contain templates/version.txt."
|
||||||
|
actual_template_version="$(tr -d '\r\n' < "$staged_version")"
|
||||||
|
[[ "$actual_template_version" == "$TEMPLATE_VERSION" ]] || fail "The export-template archive '$TEMPLATES_ASSET' reports template version '$actual_template_version', expected '$TEMPLATE_VERSION'."
|
||||||
|
mkdir -p "$TEMPLATE_DIR"
|
||||||
|
cp -R "$staged_templates/." "$TEMPLATE_DIR/"
|
||||||
|
rm -rf "$staging_directory"
|
||||||
|
[[ -f "$TEMPLATE_DIR/version.txt" ]] || fail "The export-template archive '$TEMPLATES_ASSET' could not be installed to '$TEMPLATE_DIR'."
|
||||||
|
}
|
||||||
|
|
||||||
install_godot() {
|
install_godot() {
|
||||||
local sum_file="$CACHE_DIR/SHA512-SUMS.txt"
|
local sum_file="$CACHE_DIR/SHA512-SUMS.txt"
|
||||||
local editor_archive="$CACHE_DIR/$EDITOR_ASSET"
|
local editor_archive="$CACHE_DIR/$EDITOR_ASSET"
|
||||||
local templates_archive="$CACHE_DIR/$TEMPLATES_ASSET"
|
local templates_archive="$CACHE_DIR/$TEMPLATES_ASSET"
|
||||||
|
local templates_staging_directory="$CACHE_DIR/templates-staging"
|
||||||
local editor_checksum
|
local editor_checksum
|
||||||
local templates_checksum
|
local templates_checksum
|
||||||
|
|
||||||
rm -rf "$CACHE_DIR"
|
rm -rf "$CACHE_DIR"
|
||||||
mkdir -p "$EDITOR_DIR" "$TEMPLATE_DIR"
|
mkdir -p "$EDITOR_DIR"
|
||||||
curl --fail --location --retry 3 --silent --show-error "$BASE_URL/SHA512-SUMS.txt" --output "$sum_file"
|
curl --fail --location --retry 3 --silent --show-error "$BASE_URL/SHA512-SUMS.txt" --output "$sum_file"
|
||||||
editor_checksum="$(release_asset_checksum "$EDITOR_ASSET" "$sum_file")"
|
editor_checksum="$(release_asset_checksum "$EDITOR_ASSET" "$sum_file")"
|
||||||
templates_checksum="$(release_asset_checksum "$TEMPLATES_ASSET" "$sum_file")"
|
templates_checksum="$(release_asset_checksum "$TEMPLATES_ASSET" "$sum_file")"
|
||||||
download_and_verify "$EDITOR_ASSET" "$editor_archive" "$editor_checksum"
|
download_and_verify "$EDITOR_ASSET" "$editor_archive" "$editor_checksum"
|
||||||
download_and_verify "$TEMPLATES_ASSET" "$templates_archive" "$templates_checksum"
|
download_and_verify "$TEMPLATES_ASSET" "$templates_archive" "$templates_checksum"
|
||||||
unzip -q "$editor_archive" -d "$EDITOR_DIR"
|
unzip -q "$editor_archive" -d "$EDITOR_DIR"
|
||||||
unzip -q "$templates_archive" -d "$TEMPLATE_DIR"
|
unzip -q "$templates_archive" -d "$templates_staging_directory"
|
||||||
|
install_export_templates "$templates_staging_directory"
|
||||||
EDITOR_EXECUTABLE="$(find_editor)"
|
EDITOR_EXECUTABLE="$(find_editor)"
|
||||||
[[ -n "$EDITOR_EXECUTABLE" ]] || fail "The Godot editor archive did not contain an executable."
|
[[ -n "$EDITOR_EXECUTABLE" ]] || fail "The Godot editor archive did not contain an executable."
|
||||||
[[ -f "$TEMPLATE_DIR/version.txt" ]] || fail "The export-template archive did not contain version.txt."
|
[[ -f "$TEMPLATE_DIR/version.txt" ]] || fail "The export-template archive did not contain version.txt."
|
||||||
@@ -118,14 +135,15 @@ if [[ "$GODOT_DOTNET" == "true" ]]; then
|
|||||||
EDITION=dotnet
|
EDITION=dotnet
|
||||||
EDITOR_ASSET="Godot_v${GODOT_VERSION}_mono_linux_${GODOT_HOST_ARCH}.zip"
|
EDITOR_ASSET="Godot_v${GODOT_VERSION}_mono_linux_${GODOT_HOST_ARCH}.zip"
|
||||||
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_mono_export_templates.tpz"
|
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_mono_export_templates.tpz"
|
||||||
|
TEMPLATE_VERSION="${GODOT_VERSION//-/.}.mono"
|
||||||
else
|
else
|
||||||
EDITION=standard
|
EDITION=standard
|
||||||
EDITOR_ASSET="Godot_v${GODOT_VERSION}_linux.${GODOT_HOST_ARCH}.zip"
|
EDITOR_ASSET="Godot_v${GODOT_VERSION}_linux.${GODOT_HOST_ARCH}.zip"
|
||||||
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_export_templates.tpz"
|
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_export_templates.tpz"
|
||||||
|
TEMPLATE_VERSION="${GODOT_VERSION//-/.}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BASE_URL="https://github.com/godotengine/godot/releases/download/$GODOT_VERSION"
|
BASE_URL="https://github.com/godotengine/godot/releases/download/$GODOT_VERSION"
|
||||||
TEMPLATE_VERSION="${GODOT_VERSION//-/.}"
|
|
||||||
CACHE_DIR="$GODOT_ACTION_ROOT/cache/$GODOT_VERSION/$EDITION/linux-$GODOT_HOST_ARCH"
|
CACHE_DIR="$GODOT_ACTION_ROOT/cache/$GODOT_VERSION/$EDITION/linux-$GODOT_HOST_ARCH"
|
||||||
EDITOR_DIR="$CACHE_DIR/editor"
|
EDITOR_DIR="$CACHE_DIR/editor"
|
||||||
USER_DATA_DIR="$CACHE_DIR/user-data"
|
USER_DATA_DIR="$CACHE_DIR/user-data"
|
||||||
|
|||||||
+21
-3
@@ -58,22 +58,39 @@ find_editor() {
|
|||||||
find "$EDITOR_DIR" -type f -path '*.app/Contents/MacOS/*' -name 'Godot*' -print -quit
|
find "$EDITOR_DIR" -type f -path '*.app/Contents/MacOS/*' -name 'Godot*' -print -quit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_export_templates() {
|
||||||
|
local staging_directory="$1"
|
||||||
|
local staged_templates="$staging_directory/templates"
|
||||||
|
local staged_version="$staged_templates/version.txt"
|
||||||
|
local actual_template_version
|
||||||
|
|
||||||
|
[[ -f "$staged_version" ]] || fail "The export-template archive '$TEMPLATES_ASSET' did not contain templates/version.txt."
|
||||||
|
actual_template_version="$(tr -d '\r\n' < "$staged_version")"
|
||||||
|
[[ "$actual_template_version" == "$TEMPLATE_VERSION" ]] || fail "The export-template archive '$TEMPLATES_ASSET' reports template version '$actual_template_version', expected '$TEMPLATE_VERSION'."
|
||||||
|
mkdir -p "$TEMPLATE_DIR"
|
||||||
|
cp -R "$staged_templates/." "$TEMPLATE_DIR/"
|
||||||
|
rm -rf "$staging_directory"
|
||||||
|
[[ -f "$TEMPLATE_DIR/version.txt" ]] || fail "The export-template archive '$TEMPLATES_ASSET' could not be installed to '$TEMPLATE_DIR'."
|
||||||
|
}
|
||||||
|
|
||||||
install_godot() {
|
install_godot() {
|
||||||
local sum_file="$CACHE_DIR/SHA512-SUMS.txt"
|
local sum_file="$CACHE_DIR/SHA512-SUMS.txt"
|
||||||
local editor_archive="$CACHE_DIR/$EDITOR_ASSET"
|
local editor_archive="$CACHE_DIR/$EDITOR_ASSET"
|
||||||
local templates_archive="$CACHE_DIR/$TEMPLATES_ASSET"
|
local templates_archive="$CACHE_DIR/$TEMPLATES_ASSET"
|
||||||
|
local templates_staging_directory="$CACHE_DIR/templates-staging"
|
||||||
local editor_checksum
|
local editor_checksum
|
||||||
local templates_checksum
|
local templates_checksum
|
||||||
|
|
||||||
rm -rf "$CACHE_DIR"
|
rm -rf "$CACHE_DIR"
|
||||||
mkdir -p "$EDITOR_DIR" "$TEMPLATE_DIR"
|
mkdir -p "$EDITOR_DIR"
|
||||||
curl --fail --location --retry 3 --silent --show-error "$BASE_URL/SHA512-SUMS.txt" --output "$sum_file"
|
curl --fail --location --retry 3 --silent --show-error "$BASE_URL/SHA512-SUMS.txt" --output "$sum_file"
|
||||||
editor_checksum="$(release_asset_checksum "$EDITOR_ASSET" "$sum_file")"
|
editor_checksum="$(release_asset_checksum "$EDITOR_ASSET" "$sum_file")"
|
||||||
templates_checksum="$(release_asset_checksum "$TEMPLATES_ASSET" "$sum_file")"
|
templates_checksum="$(release_asset_checksum "$TEMPLATES_ASSET" "$sum_file")"
|
||||||
download_and_verify "$EDITOR_ASSET" "$editor_archive" "$editor_checksum"
|
download_and_verify "$EDITOR_ASSET" "$editor_archive" "$editor_checksum"
|
||||||
download_and_verify "$TEMPLATES_ASSET" "$templates_archive" "$templates_checksum"
|
download_and_verify "$TEMPLATES_ASSET" "$templates_archive" "$templates_checksum"
|
||||||
unzip -q "$editor_archive" -d "$EDITOR_DIR"
|
unzip -q "$editor_archive" -d "$EDITOR_DIR"
|
||||||
unzip -q "$templates_archive" -d "$TEMPLATE_DIR"
|
unzip -q "$templates_archive" -d "$templates_staging_directory"
|
||||||
|
install_export_templates "$templates_staging_directory"
|
||||||
EDITOR_EXECUTABLE="$(find_editor)"
|
EDITOR_EXECUTABLE="$(find_editor)"
|
||||||
[[ -n "$EDITOR_EXECUTABLE" ]] || fail "The Godot editor archive did not contain a macOS app executable."
|
[[ -n "$EDITOR_EXECUTABLE" ]] || fail "The Godot editor archive did not contain a macOS app executable."
|
||||||
[[ -f "$TEMPLATE_DIR/version.txt" ]] || fail "The export-template archive did not contain version.txt."
|
[[ -f "$TEMPLATE_DIR/version.txt" ]] || fail "The export-template archive did not contain version.txt."
|
||||||
@@ -116,14 +133,15 @@ if [[ "$GODOT_DOTNET" == "true" ]]; then
|
|||||||
EDITION=dotnet
|
EDITION=dotnet
|
||||||
EDITOR_ASSET="Godot_v${GODOT_VERSION}_mono_macos.universal.zip"
|
EDITOR_ASSET="Godot_v${GODOT_VERSION}_mono_macos.universal.zip"
|
||||||
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_mono_export_templates.tpz"
|
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_mono_export_templates.tpz"
|
||||||
|
TEMPLATE_VERSION="${GODOT_VERSION//-/.}.mono"
|
||||||
else
|
else
|
||||||
EDITION=standard
|
EDITION=standard
|
||||||
EDITOR_ASSET="Godot_v${GODOT_VERSION}_macos.universal.zip"
|
EDITOR_ASSET="Godot_v${GODOT_VERSION}_macos.universal.zip"
|
||||||
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_export_templates.tpz"
|
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_export_templates.tpz"
|
||||||
|
TEMPLATE_VERSION="${GODOT_VERSION//-/.}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
BASE_URL="https://github.com/godotengine/godot/releases/download/$GODOT_VERSION"
|
BASE_URL="https://github.com/godotengine/godot/releases/download/$GODOT_VERSION"
|
||||||
TEMPLATE_VERSION="${GODOT_VERSION//-/.}"
|
|
||||||
CACHE_DIR="$GODOT_ACTION_ROOT/cache/$GODOT_VERSION/$EDITION/macos-$GODOT_HOST_ARCH"
|
CACHE_DIR="$GODOT_ACTION_ROOT/cache/$GODOT_VERSION/$EDITION/macos-$GODOT_HOST_ARCH"
|
||||||
EDITOR_DIR="$CACHE_DIR/editor"
|
EDITOR_DIR="$CACHE_DIR/editor"
|
||||||
USER_HOME="$CACHE_DIR/home"
|
USER_HOME="$CACHE_DIR/home"
|
||||||
|
|||||||
+269
-78
@@ -1,11 +1,16 @@
|
|||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param()
|
param(
|
||||||
|
[switch]$SkipExecution
|
||||||
|
)
|
||||||
|
|
||||||
Set-StrictMode -Version Latest
|
Set-StrictMode -Version Latest
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
function Fail([string]$Message) {
|
function Fail([string]$Message) {
|
||||||
Write-Error "::error::$Message"
|
Write-Host "::error::$Message"
|
||||||
|
if ($SkipExecution) {
|
||||||
|
throw $Message
|
||||||
|
}
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -17,11 +22,28 @@ function Require-Environment([string]$Name) {
|
|||||||
return $value
|
return $value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Test-PathIsWithinDirectory([string]$ParentDirectory, [string]$CandidateDirectory) {
|
||||||
|
$parentPath = [IO.Path]::GetFullPath($ParentDirectory)
|
||||||
|
$candidatePath = [IO.Path]::GetFullPath($CandidateDirectory)
|
||||||
|
$separator = [IO.Path]::DirectorySeparatorChar.ToString()
|
||||||
|
|
||||||
|
if ($candidatePath.Equals($parentPath, [StringComparison]::OrdinalIgnoreCase)) {
|
||||||
|
return $true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (-not $parentPath.EndsWith($separator)) {
|
||||||
|
$parentPath += $separator
|
||||||
|
}
|
||||||
|
|
||||||
|
return $candidatePath.StartsWith($parentPath, [StringComparison]::OrdinalIgnoreCase)
|
||||||
|
}
|
||||||
|
|
||||||
function Get-ActualArchitecture {
|
function Get-ActualArchitecture {
|
||||||
$architecture = $env:PROCESSOR_ARCHITEW6432
|
$architecture = $env:PROCESSOR_ARCHITEW6432
|
||||||
if ([string]::IsNullOrWhiteSpace($architecture)) {
|
if ([string]::IsNullOrWhiteSpace($architecture)) {
|
||||||
$architecture = $env:PROCESSOR_ARCHITECTURE
|
$architecture = $env:PROCESSOR_ARCHITECTURE
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($architecture.ToUpperInvariant()) {
|
switch ($architecture.ToUpperInvariant()) {
|
||||||
'AMD64' { return 'x86_64' }
|
'AMD64' { return 'x86_64' }
|
||||||
'X86' { return 'x86_32' }
|
'X86' { return 'x86_32' }
|
||||||
@@ -30,32 +52,227 @@ function Get-ActualArchitecture {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-Checksum([string]$ManifestPath, [string]$Asset) {
|
function Get-GodotAssets([string]$Version, [string]$Dotnet, [string]$Architecture) {
|
||||||
$line = Get-Content -LiteralPath $ManifestPath | Where-Object {
|
if ($Dotnet -eq 'true') {
|
||||||
$_ -match '^([0-9A-Fa-f]{128})\s+\*?(.+)$' -and $Matches[2] -eq $Asset
|
$edition = 'dotnet'
|
||||||
} | Select-Object -First 1
|
$editorBaseName = switch ($Architecture) {
|
||||||
if (-not $line) {
|
'x86_32' { "Godot_v${Version}_mono_win32" }
|
||||||
Fail "Godot $GodotVersion does not publish required $edition asset '$Asset' for Windows/$HostArch at $script:BaseUrl. Choose a supported stable release and architecture."
|
'x86_64' { "Godot_v${Version}_mono_win64" }
|
||||||
|
'arm64' { "Godot_v${Version}_mono_windows_arm64" }
|
||||||
|
default { Fail "Unsupported Windows host-arch '$Architecture'." }
|
||||||
}
|
}
|
||||||
return ($line -split '\s+')[0].ToLowerInvariant()
|
|
||||||
}
|
|
||||||
|
|
||||||
function Download-AndVerify([string]$Asset, [string]$Destination, [string]$ExpectedChecksum) {
|
return [PSCustomObject]@{
|
||||||
Invoke-WebRequest -Uri "$script:BaseUrl/$Asset" -OutFile $Destination
|
Edition = $edition
|
||||||
$actual = (Get-FileHash -LiteralPath $Destination -Algorithm SHA512).Hash.ToLowerInvariant()
|
EditorAsset = "$editorBaseName.zip"
|
||||||
if ($actual -ne $ExpectedChecksum) {
|
EditorFileName = "${editorBaseName}_console.exe"
|
||||||
Fail "SHA-512 verification failed for $Asset."
|
TemplatesAsset = "Godot_v${Version}_mono_export_templates.tpz"
|
||||||
|
TemplateVersion = ($Version -replace '-', '.') + '.mono'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$edition = 'standard'
|
||||||
|
$editorBaseName = switch ($Architecture) {
|
||||||
|
'x86_32' { "Godot_v${Version}_win32" }
|
||||||
|
'x86_64' { "Godot_v${Version}_win64" }
|
||||||
|
'arm64' { "Godot_v${Version}_windows_arm64" }
|
||||||
|
default { Fail "Unsupported Windows host-arch '$Architecture'." }
|
||||||
|
}
|
||||||
|
|
||||||
|
return [PSCustomObject]@{
|
||||||
|
Edition = $edition
|
||||||
|
EditorAsset = "${editorBaseName}.exe.zip"
|
||||||
|
EditorFileName = "${editorBaseName}_console.exe"
|
||||||
|
TemplatesAsset = "Godot_v${Version}_export_templates.tpz"
|
||||||
|
TemplateVersion = $Version -replace '-', '.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Find-Editor([string]$Directory) {
|
function Get-ExpectedPeMachine([string]$Architecture) {
|
||||||
$console = Get-ChildItem -LiteralPath $Directory -Recurse -File -Filter 'Godot*console.exe' -ErrorAction SilentlyContinue | Select-Object -First 1
|
switch ($Architecture) {
|
||||||
if ($console) { return $console.FullName }
|
'x86_32' { return [uint16]0x014c }
|
||||||
$editor = Get-ChildItem -LiteralPath $Directory -Recurse -File -Filter 'Godot*.exe' -ErrorAction SilentlyContinue | Select-Object -First 1
|
'x86_64' { return [uint16]0x8664 }
|
||||||
if ($editor) { return $editor.FullName }
|
'arm64' { return [uint16]0xaa64 }
|
||||||
|
default { Fail "Unsupported Windows host-arch '$Architecture'." }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-Checksum([string]$ManifestPath, [string]$Asset, [string]$Version, [string]$Edition, [string]$Architecture, [string]$BaseUrl) {
|
||||||
|
foreach ($line in Get-Content -LiteralPath $ManifestPath) {
|
||||||
|
if ($line -match '^([0-9A-Fa-f]{128})\s+\*?(.+)$' -and $Matches[2] -eq $Asset) {
|
||||||
|
return $Matches[1].ToLowerInvariant()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Fail "Godot $Version does not publish required $Edition asset '$Asset' for Windows/$Architecture at $BaseUrl. Choose a supported stable release and architecture."
|
||||||
|
}
|
||||||
|
|
||||||
|
function Invoke-Download([string]$Uri, [string]$Destination) {
|
||||||
|
$lastError = $null
|
||||||
|
for ($attempt = 1; $attempt -le 3; $attempt++) {
|
||||||
|
try {
|
||||||
|
Invoke-WebRequest -UseBasicParsing -Uri $Uri -OutFile $Destination
|
||||||
|
$lastError = $null
|
||||||
|
break
|
||||||
|
} catch {
|
||||||
|
$lastError = $_
|
||||||
|
if (Test-Path -LiteralPath $Destination) {
|
||||||
|
Remove-Item -LiteralPath $Destination -Force
|
||||||
|
}
|
||||||
|
if ($attempt -lt 3) {
|
||||||
|
Start-Sleep -Seconds $attempt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($null -ne $lastError) {
|
||||||
|
Fail "Failed to download '$Uri' after 3 attempts: $($lastError.Exception.Message)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Invoke-VerifiedDownload([string]$Uri, [string]$Destination, [string]$ExpectedChecksum) {
|
||||||
|
Invoke-Download $Uri $Destination
|
||||||
|
$actualChecksum = (Get-FileHash -LiteralPath $Destination -Algorithm SHA512).Hash.ToLowerInvariant()
|
||||||
|
if ($actualChecksum -ne $ExpectedChecksum) {
|
||||||
|
Fail "SHA-512 verification failed for $(Split-Path -Leaf $Destination)."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-CachePaths([string]$Root, [string]$TemplateVersion) {
|
||||||
|
$editorDirectory = Join-Path $Root 'editor'
|
||||||
|
$userHome = Join-Path $Root 'home'
|
||||||
|
return [PSCustomObject]@{
|
||||||
|
Root = $Root
|
||||||
|
EditorDirectory = $editorDirectory
|
||||||
|
UserHome = $userHome
|
||||||
|
TemplateDirectory = Join-Path $userHome "AppData\Roaming\Godot\export_templates\$TemplateVersion"
|
||||||
|
Marker = Join-Path $Root '.complete'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-EditorExecutable([string]$EditorDirectory, [string]$ExpectedFileName) {
|
||||||
|
$matches = @(Get-ChildItem -LiteralPath $EditorDirectory -Recurse -File -ErrorAction SilentlyContinue |
|
||||||
|
Where-Object { $_.Name -eq $ExpectedFileName })
|
||||||
|
if ($matches.Count -eq 1) {
|
||||||
|
return $matches[0].FullName
|
||||||
|
}
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-PeMachine([string]$Path) {
|
||||||
|
try {
|
||||||
|
$stream = [IO.File]::Open($Path, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::Read)
|
||||||
|
try {
|
||||||
|
if ($stream.Length -lt 64) { return $null }
|
||||||
|
$header = New-Object byte[] 64
|
||||||
|
if ($stream.Read($header, 0, $header.Length) -ne $header.Length -or $header[0] -ne 0x4d -or $header[1] -ne 0x5a) {
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
|
$peOffset = [BitConverter]::ToInt32($header, 0x3c)
|
||||||
|
if ($peOffset -lt 0 -or ($peOffset + 6) -gt $stream.Length) { return $null }
|
||||||
|
$stream.Position = $peOffset
|
||||||
|
$signature = New-Object byte[] 6
|
||||||
|
if ($stream.Read($signature, 0, $signature.Length) -ne $signature.Length) { return $null }
|
||||||
|
if ($signature[0] -ne 0x50 -or $signature[1] -ne 0x45 -or $signature[2] -ne 0 -or $signature[3] -ne 0) { return $null }
|
||||||
|
return [BitConverter]::ToUInt16($signature, 4)
|
||||||
|
} finally {
|
||||||
|
$stream.Dispose()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-ExpectedEditor([string]$EditorDirectory, [string]$ExpectedFileName, [uint16]$ExpectedMachine) {
|
||||||
|
$editorExecutable = Get-EditorExecutable $EditorDirectory $ExpectedFileName
|
||||||
|
return $null -ne $editorExecutable -and (Get-PeMachine $editorExecutable) -eq $ExpectedMachine
|
||||||
|
}
|
||||||
|
|
||||||
|
function Assert-ExpectedEditor([string]$EditorDirectory, [string]$ExpectedFileName, [uint16]$ExpectedMachine, [string]$Architecture) {
|
||||||
|
$editorExecutable = Get-EditorExecutable $EditorDirectory $ExpectedFileName
|
||||||
|
if ($null -eq $editorExecutable) {
|
||||||
|
Fail "The Godot editor archive did not contain the expected console executable '$ExpectedFileName'."
|
||||||
|
}
|
||||||
|
if ((Get-PeMachine $editorExecutable) -ne $ExpectedMachine) {
|
||||||
|
Fail "The expected Godot console executable '$ExpectedFileName' is not a valid $Architecture Windows executable."
|
||||||
|
}
|
||||||
|
return $editorExecutable
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-ValidCache($Paths, [string]$TemplateVersion, [string]$ExpectedFileName, [uint16]$ExpectedMachine) {
|
||||||
|
if (-not (Test-Path -LiteralPath $Paths.Marker -PathType Leaf)) { return $false }
|
||||||
|
$installedVersion = Join-Path $Paths.TemplateDirectory 'version.txt'
|
||||||
|
if (-not (Test-Path -LiteralPath $installedVersion -PathType Leaf)) { return $false }
|
||||||
|
if ((Get-Content -LiteralPath $installedVersion -Raw).Trim() -ne $TemplateVersion) { return $false }
|
||||||
|
return Test-ExpectedEditor $Paths.EditorDirectory $ExpectedFileName $ExpectedMachine
|
||||||
|
}
|
||||||
|
|
||||||
|
function Install-ExportTemplates($Paths, [string]$StagingDirectory, [string]$TemplateAsset, [string]$TemplateVersion) {
|
||||||
|
$stagedTemplates = Join-Path $StagingDirectory 'templates'
|
||||||
|
$stagedVersion = Join-Path $stagedTemplates 'version.txt'
|
||||||
|
if (-not (Test-Path -LiteralPath $stagedVersion -PathType Leaf)) {
|
||||||
|
Fail "The export-template archive '$TemplateAsset' did not contain templates/version.txt."
|
||||||
|
}
|
||||||
|
if ((Get-Content -LiteralPath $stagedVersion -Raw).Trim() -ne $TemplateVersion) {
|
||||||
|
Fail "The export-template archive '$TemplateAsset' reports template version '$((Get-Content -LiteralPath $stagedVersion -Raw).Trim())', expected '$TemplateVersion'."
|
||||||
|
}
|
||||||
|
|
||||||
|
New-Item -ItemType Directory -Force -Path $Paths.TemplateDirectory | Out-Null
|
||||||
|
Get-ChildItem -LiteralPath $stagedTemplates -Force | Copy-Item -Destination $Paths.TemplateDirectory -Recurse -Force
|
||||||
|
if (-not (Test-Path -LiteralPath (Join-Path $Paths.TemplateDirectory 'version.txt') -PathType Leaf)) {
|
||||||
|
Fail "The export-template archive '$TemplateAsset' could not be installed to '$($Paths.TemplateDirectory)'."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Install-GodotCache($Paths, $Assets, [uint16]$ExpectedMachine, [string]$Architecture, [string]$Version, [string]$BaseUrl) {
|
||||||
|
New-Item -ItemType Directory -Force -Path $Paths.EditorDirectory | Out-Null
|
||||||
|
$manifestPath = Join-Path $Paths.Root 'SHA512-SUMS.txt'
|
||||||
|
$editorArchive = Join-Path $Paths.Root $Assets.EditorAsset
|
||||||
|
$templatesArchive = Join-Path $Paths.Root $Assets.TemplatesAsset
|
||||||
|
$templatesZipArchive = Join-Path $Paths.Root 'export-templates.zip'
|
||||||
|
$templatesStagingDirectory = Join-Path $Paths.Root 'templates-staging'
|
||||||
|
|
||||||
|
Invoke-Download "$BaseUrl/SHA512-SUMS.txt" $manifestPath
|
||||||
|
$editorChecksum = Get-Checksum $manifestPath $Assets.EditorAsset $Version $Assets.Edition $Architecture $BaseUrl
|
||||||
|
$templatesChecksum = Get-Checksum $manifestPath $Assets.TemplatesAsset $Version $Assets.Edition $Architecture $BaseUrl
|
||||||
|
Invoke-VerifiedDownload "$BaseUrl/$($Assets.EditorAsset)" $editorArchive $editorChecksum
|
||||||
|
Invoke-VerifiedDownload "$BaseUrl/$($Assets.TemplatesAsset)" $templatesArchive $templatesChecksum
|
||||||
|
|
||||||
|
Expand-Archive -LiteralPath $editorArchive -DestinationPath $Paths.EditorDirectory -Force
|
||||||
|
Assert-ExpectedEditor $Paths.EditorDirectory $Assets.EditorFileName $ExpectedMachine $Architecture | Out-Null
|
||||||
|
|
||||||
|
# Expand-Archive recognizes .zip only; Godot's verified .tpz payload is a ZIP archive.
|
||||||
|
Copy-Item -LiteralPath $templatesArchive -Destination $templatesZipArchive -Force
|
||||||
|
Expand-Archive -LiteralPath $templatesZipArchive -DestinationPath $templatesStagingDirectory -Force
|
||||||
|
Install-ExportTemplates $Paths $templatesStagingDirectory $Assets.TemplatesAsset $Assets.TemplateVersion
|
||||||
|
Remove-Item -LiteralPath $templatesStagingDirectory -Recurse -Force
|
||||||
|
|
||||||
|
@("release=$Version", "editor=$($Assets.EditorAsset)", "templates=$($Assets.TemplatesAsset)") |
|
||||||
|
Set-Content -LiteralPath $Paths.Marker -NoNewline -Encoding ASCII
|
||||||
|
}
|
||||||
|
|
||||||
|
function Invoke-GodotExport([string]$EditorExecutable, [string]$ProjectDirectory, [string]$ExportMode, [string]$ExportPreset, [string]$OutputFile, [scriptblock]$EditorRunner) {
|
||||||
|
try {
|
||||||
|
if ($null -ne $EditorRunner) {
|
||||||
|
& $EditorRunner $EditorExecutable $ProjectDirectory $ExportMode $ExportPreset $OutputFile
|
||||||
|
} else {
|
||||||
|
& $EditorExecutable --headless --path $ProjectDirectory "--export-$ExportMode" $ExportPreset $OutputFile
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
Fail "Godot could not start '$EditorExecutable': $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($LASTEXITCODE -ne 0) {
|
||||||
|
Fail "Godot export failed with exit code $LASTEXITCODE."
|
||||||
|
}
|
||||||
|
if (-not (Test-Path -LiteralPath $OutputFile -PathType Leaf)) {
|
||||||
|
Fail "Godot completed without creating the expected output '$(Split-Path -Leaf $OutputFile)'."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($SkipExecution) { return }
|
||||||
|
|
||||||
$GodotVersion = Require-Environment 'GODOT_VERSION'
|
$GodotVersion = Require-Environment 'GODOT_VERSION'
|
||||||
$HostOs = Require-Environment 'GODOT_HOST_OS'
|
$HostOs = Require-Environment 'GODOT_HOST_OS'
|
||||||
$HostArch = Require-Environment 'GODOT_HOST_ARCH'
|
$HostArch = Require-Environment 'GODOT_HOST_ARCH'
|
||||||
@@ -75,79 +292,53 @@ if ($ExportMode -notin @('release', 'debug')) { Fail "export-mode must be 'relea
|
|||||||
if ([string]::IsNullOrWhiteSpace($ExportPreset)) { Fail 'export-preset must not be empty.' }
|
if ([string]::IsNullOrWhiteSpace($ExportPreset)) { Fail 'export-preset must not be empty.' }
|
||||||
if ([string]::IsNullOrWhiteSpace($ExportFileName) -or $ExportFileName -in @('.', '..') -or $ExportFileName.IndexOfAny([IO.Path]::GetInvalidFileNameChars()) -ge 0 -or $ExportFileName.Contains('/') -or $ExportFileName.Contains('\')) { Fail 'export-file-name must be a filename without path separators.' }
|
if ([string]::IsNullOrWhiteSpace($ExportFileName) -or $ExportFileName -in @('.', '..') -or $ExportFileName.IndexOfAny([IO.Path]::GetInvalidFileNameChars()) -ge 0 -or $ExportFileName.Contains('/') -or $ExportFileName.Contains('\')) { Fail 'export-file-name must be a filename without path separators.' }
|
||||||
if ($HostArch -notin @('x86_32', 'x86_64', 'arm64')) { Fail "Unsupported Windows host-arch '$HostArch'." }
|
if ($HostArch -notin @('x86_32', 'x86_64', 'arm64')) { Fail "Unsupported Windows host-arch '$HostArch'." }
|
||||||
if ($HostArch -ne (Get-ActualArchitecture)) { Fail "host-arch '$HostArch' does not match this Windows runner ($(Get-ActualArchitecture))." }
|
|
||||||
|
$actualArchitecture = Get-ActualArchitecture
|
||||||
|
if ($HostArch -ne $actualArchitecture) { Fail "host-arch '$HostArch' does not match this Windows runner ($actualArchitecture)." }
|
||||||
|
|
||||||
$workspaceDirectory = [IO.Path]::GetFullPath($Workspace)
|
$workspaceDirectory = [IO.Path]::GetFullPath($Workspace)
|
||||||
if ([IO.Path]::IsPathRooted($ProjectPath)) { Fail 'project-path must be relative to the checked-out workspace.' }
|
if ([IO.Path]::IsPathRooted($ProjectPath)) { Fail 'project-path must be relative to the checked-out workspace.' }
|
||||||
$ProjectDirectory = [IO.Path]::GetFullPath((Join-Path $workspaceDirectory $ProjectPath))
|
$ProjectDirectory = [IO.Path]::GetFullPath((Join-Path $workspaceDirectory $ProjectPath))
|
||||||
$projectRelativePath = [IO.Path]::GetRelativePath($workspaceDirectory, $ProjectDirectory)
|
if (-not (Test-PathIsWithinDirectory $workspaceDirectory $ProjectDirectory)) { Fail 'project-path must remain inside the checked-out workspace.' }
|
||||||
if ($projectRelativePath -eq '..' -or $projectRelativePath.StartsWith("..$([IO.Path]::DirectorySeparatorChar)") -or [IO.Path]::IsPathRooted($projectRelativePath)) { Fail 'project-path must remain inside the checked-out workspace.' }
|
if (-not (Test-Path -LiteralPath $ProjectDirectory -PathType Container)) { Fail "project-path '$ProjectPath' does not exist." }
|
||||||
if (-not (Test-Path -LiteralPath (Join-Path $ProjectDirectory 'project.godot') -PathType Leaf)) { Fail "No project.godot was found in project-path '$ProjectPath'." }
|
if (-not (Test-Path -LiteralPath (Join-Path $ProjectDirectory 'project.godot') -PathType Leaf)) { Fail "No project.godot was found in project-path '$ProjectPath'." }
|
||||||
$PresetFile = Join-Path $ProjectDirectory 'export_presets.cfg'
|
$presetFile = Join-Path $ProjectDirectory 'export_presets.cfg'
|
||||||
if (-not (Test-Path -LiteralPath $PresetFile -PathType Leaf)) { Fail "No export_presets.cfg was found in project-path '$ProjectPath'." }
|
if (-not (Test-Path -LiteralPath $presetFile -PathType Leaf)) { Fail "No export_presets.cfg was found in project-path '$ProjectPath'." }
|
||||||
if (-not (Select-String -LiteralPath $PresetFile -SimpleMatch "name=`"$ExportPreset`"" -Quiet)) { Fail "Export preset '$ExportPreset' was not found in export_presets.cfg." }
|
if (-not (Select-String -LiteralPath $presetFile -SimpleMatch "name=`"$ExportPreset`"" -Quiet)) { Fail "Export preset '$ExportPreset' was not found in export_presets.cfg." }
|
||||||
|
|
||||||
if ($Dotnet -eq 'true') {
|
$assets = Get-GodotAssets $GodotVersion $Dotnet $HostArch
|
||||||
$edition = 'dotnet'
|
$expectedMachine = Get-ExpectedPeMachine $HostArch
|
||||||
$editorAsset = switch ($HostArch) {
|
$baseUrl = "https://github.com/godotengine/godot/releases/download/$GodotVersion"
|
||||||
'x86_32' { "Godot_v${GodotVersion}_mono_win32.zip" }
|
$cacheDirectory = Join-Path $ActionRoot "cache\$GodotVersion\$($assets.Edition)\windows-$HostArch"
|
||||||
'x86_64' { "Godot_v${GodotVersion}_mono_win64.zip" }
|
$cachePaths = Get-CachePaths $cacheDirectory $assets.TemplateVersion
|
||||||
'arm64' { "Godot_v${GodotVersion}_mono_windows_arm64.zip" }
|
|
||||||
}
|
|
||||||
$templatesAsset = "Godot_v${GodotVersion}_mono_export_templates.tpz"
|
|
||||||
} else {
|
|
||||||
$edition = 'standard'
|
|
||||||
$editorAsset = switch ($HostArch) {
|
|
||||||
'x86_32' { "Godot_v${GodotVersion}_win32.exe.zip" }
|
|
||||||
'x86_64' { "Godot_v${GodotVersion}_win64.exe.zip" }
|
|
||||||
'arm64' { "Godot_v${GodotVersion}_windows_arm64.exe.zip" }
|
|
||||||
}
|
|
||||||
$templatesAsset = "Godot_v${GodotVersion}_export_templates.tpz"
|
|
||||||
}
|
|
||||||
|
|
||||||
$script:BaseUrl = "https://github.com/godotengine/godot/releases/download/$GodotVersion"
|
if (-not (Test-ValidCache $cachePaths $assets.TemplateVersion $assets.EditorFileName $expectedMachine)) {
|
||||||
$templateVersion = $GodotVersion -replace '-', '.'
|
$cacheParent = Split-Path -Parent $cacheDirectory
|
||||||
$cacheDirectory = Join-Path $ActionRoot "cache\$GodotVersion\$edition\windows-$HostArch"
|
$stagingDirectory = Join-Path $cacheParent ((Split-Path -Leaf $cacheDirectory) + ".staging-$PID")
|
||||||
$editorDirectory = Join-Path $cacheDirectory 'editor'
|
if (Test-Path -LiteralPath $stagingDirectory) { Remove-Item -LiteralPath $stagingDirectory -Recurse -Force }
|
||||||
$userHome = Join-Path $cacheDirectory 'home'
|
New-Item -ItemType Directory -Force -Path $cacheParent | Out-Null
|
||||||
$templateDirectory = Join-Path $userHome "AppData\Roaming\Godot\export_templates\$templateVersion"
|
|
||||||
$marker = Join-Path $cacheDirectory '.complete'
|
|
||||||
|
|
||||||
$editorExecutable = $null
|
try {
|
||||||
if ((Test-Path -LiteralPath $marker -PathType Leaf) -and (Test-Path -LiteralPath (Join-Path $templateDirectory 'version.txt') -PathType Leaf)) {
|
$stagingPaths = Get-CachePaths $stagingDirectory $assets.TemplateVersion
|
||||||
$editorExecutable = Find-Editor $editorDirectory
|
Install-GodotCache $stagingPaths $assets $expectedMachine $HostArch $GodotVersion $baseUrl
|
||||||
}
|
if (-not (Test-ValidCache $stagingPaths $assets.TemplateVersion $assets.EditorFileName $expectedMachine)) { Fail 'Godot cache installation did not pass validation.' }
|
||||||
|
|
||||||
if (-not $editorExecutable) {
|
|
||||||
if (Test-Path -LiteralPath $cacheDirectory) { Remove-Item -LiteralPath $cacheDirectory -Recurse -Force }
|
if (Test-Path -LiteralPath $cacheDirectory) { Remove-Item -LiteralPath $cacheDirectory -Recurse -Force }
|
||||||
New-Item -ItemType Directory -Force -Path $editorDirectory, $templateDirectory | Out-Null
|
Move-Item -LiteralPath $stagingDirectory -Destination $cacheDirectory
|
||||||
$manifestPath = Join-Path $cacheDirectory 'SHA512-SUMS.txt'
|
} finally {
|
||||||
$editorArchive = Join-Path $cacheDirectory $editorAsset
|
if (Test-Path -LiteralPath $stagingDirectory) { Remove-Item -LiteralPath $stagingDirectory -Recurse -Force }
|
||||||
$templatesArchive = Join-Path $cacheDirectory $templatesAsset
|
}
|
||||||
Invoke-WebRequest -Uri "$script:BaseUrl/SHA512-SUMS.txt" -OutFile $manifestPath
|
|
||||||
$editorChecksum = Get-Checksum $manifestPath $editorAsset
|
|
||||||
$templatesChecksum = Get-Checksum $manifestPath $templatesAsset
|
|
||||||
Download-AndVerify $editorAsset $editorArchive $editorChecksum
|
|
||||||
Download-AndVerify $templatesAsset $templatesArchive $templatesChecksum
|
|
||||||
Expand-Archive -LiteralPath $editorArchive -DestinationPath $editorDirectory -Force
|
|
||||||
Expand-Archive -LiteralPath $templatesArchive -DestinationPath $templateDirectory -Force
|
|
||||||
$editorExecutable = Find-Editor $editorDirectory
|
|
||||||
if (-not $editorExecutable) { Fail 'The Godot editor archive did not contain an executable.' }
|
|
||||||
if (-not (Test-Path -LiteralPath (Join-Path $templateDirectory 'version.txt') -PathType Leaf)) { Fail 'The export-template archive did not contain version.txt.' }
|
|
||||||
@("release=$GodotVersion", "editor=$editorAsset", "templates=$templatesAsset") | Set-Content -LiteralPath $marker -NoNewline
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$editorExecutable = Assert-ExpectedEditor $cachePaths.EditorDirectory $assets.EditorFileName $expectedMachine $HostArch
|
||||||
$safePreset = ($ExportPreset -replace '[^A-Za-z0-9_.-]', '_').Trim('_')
|
$safePreset = ($ExportPreset -replace '[^A-Za-z0-9_.-]', '_').Trim('_')
|
||||||
if ([string]::IsNullOrWhiteSpace($safePreset)) { $safePreset = 'export' }
|
if ([string]::IsNullOrWhiteSpace($safePreset)) { $safePreset = 'export' }
|
||||||
$buildDirectory = Join-Path $ActionRoot "builds\$safePreset-$ExportMode-$PID"
|
$buildDirectory = Join-Path $ActionRoot "builds\$safePreset-$ExportMode-$PID"
|
||||||
$outputFile = Join-Path $buildDirectory $ExportFileName
|
$outputFile = Join-Path $buildDirectory $ExportFileName
|
||||||
New-Item -ItemType Directory -Force -Path $buildDirectory | Out-Null
|
New-Item -ItemType Directory -Force -Path $buildDirectory | Out-Null
|
||||||
|
|
||||||
$env:USERPROFILE = $userHome
|
$env:USERPROFILE = $cachePaths.UserHome
|
||||||
$env:APPDATA = Join-Path $userHome 'AppData\Roaming'
|
$env:APPDATA = Join-Path $cachePaths.UserHome 'AppData\Roaming'
|
||||||
$env:LOCALAPPDATA = Join-Path $userHome 'AppData\Local'
|
$env:LOCALAPPDATA = Join-Path $cachePaths.UserHome 'AppData\Local'
|
||||||
& $editorExecutable --headless --path $ProjectDirectory "--export-$ExportMode" $ExportPreset $outputFile
|
Invoke-GodotExport $editorExecutable $ProjectDirectory $ExportMode $ExportPreset $outputFile $null
|
||||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
|
||||||
if (-not (Test-Path -LiteralPath $outputFile)) { Fail "Godot completed without creating the expected output '$ExportFileName'." }
|
|
||||||
|
|
||||||
"build-directory=$buildDirectory" | Add-Content -LiteralPath $GithubOutput
|
"build-directory=$buildDirectory" | Add-Content -LiteralPath $GithubOutput -Encoding ASCII
|
||||||
|
|||||||
Reference in New Issue
Block a user