3 Commits
3 changed files with 89 additions and 11 deletions
+21 -3
View File
@@ -60,22 +60,39 @@ find_editor() {
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() {
local sum_file="$CACHE_DIR/SHA512-SUMS.txt"
local editor_archive="$CACHE_DIR/$EDITOR_ASSET"
local templates_archive="$CACHE_DIR/$TEMPLATES_ASSET"
local templates_staging_directory="$CACHE_DIR/templates-staging"
local editor_checksum
local templates_checksum
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"
editor_checksum="$(release_asset_checksum "$EDITOR_ASSET" "$sum_file")"
templates_checksum="$(release_asset_checksum "$TEMPLATES_ASSET" "$sum_file")"
download_and_verify "$EDITOR_ASSET" "$editor_archive" "$editor_checksum"
download_and_verify "$TEMPLATES_ASSET" "$templates_archive" "$templates_checksum"
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)"
[[ -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."
@@ -118,14 +135,15 @@ if [[ "$GODOT_DOTNET" == "true" ]]; then
EDITION=dotnet
EDITOR_ASSET="Godot_v${GODOT_VERSION}_mono_linux_${GODOT_HOST_ARCH}.zip"
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_mono_export_templates.tpz"
TEMPLATE_VERSION="${GODOT_VERSION//-/.}.mono"
else
EDITION=standard
EDITOR_ASSET="Godot_v${GODOT_VERSION}_linux.${GODOT_HOST_ARCH}.zip"
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_export_templates.tpz"
TEMPLATE_VERSION="${GODOT_VERSION//-/.}"
fi
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"
EDITOR_DIR="$CACHE_DIR/editor"
USER_DATA_DIR="$CACHE_DIR/user-data"
+21 -3
View File
@@ -58,22 +58,39 @@ find_editor() {
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() {
local sum_file="$CACHE_DIR/SHA512-SUMS.txt"
local editor_archive="$CACHE_DIR/$EDITOR_ASSET"
local templates_archive="$CACHE_DIR/$TEMPLATES_ASSET"
local templates_staging_directory="$CACHE_DIR/templates-staging"
local editor_checksum
local templates_checksum
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"
editor_checksum="$(release_asset_checksum "$EDITOR_ASSET" "$sum_file")"
templates_checksum="$(release_asset_checksum "$TEMPLATES_ASSET" "$sum_file")"
download_and_verify "$EDITOR_ASSET" "$editor_archive" "$editor_checksum"
download_and_verify "$TEMPLATES_ASSET" "$templates_archive" "$templates_checksum"
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)"
[[ -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."
@@ -116,14 +133,15 @@ if [[ "$GODOT_DOTNET" == "true" ]]; then
EDITION=dotnet
EDITOR_ASSET="Godot_v${GODOT_VERSION}_mono_macos.universal.zip"
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_mono_export_templates.tpz"
TEMPLATE_VERSION="${GODOT_VERSION//-/.}.mono"
else
EDITION=standard
EDITOR_ASSET="Godot_v${GODOT_VERSION}_macos.universal.zip"
TEMPLATES_ASSET="Godot_v${GODOT_VERSION}_export_templates.tpz"
TEMPLATE_VERSION="${GODOT_VERSION//-/.}"
fi
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"
EDITOR_DIR="$CACHE_DIR/editor"
USER_HOME="$CACHE_DIR/home"
+47 -5
View File
@@ -17,6 +17,26 @@ function Require-Environment([string]$Name) {
return $value
}
function Test-PathIsWithinDirectory([string]$ParentDirectory, [string]$CandidateDirectory) {
# [IO.Path]::GetRelativePath is not available in Windows PowerShell 5.1.
# Compare complete paths with a separator boundary so, for example,
# C:\workspace-other is not considered a child of C:\workspace.
$parentPath = [IO.Path]::GetFullPath($ParentDirectory)
$candidatePath = [IO.Path]::GetFullPath($CandidateDirectory)
$directorySeparator = [IO.Path]::DirectorySeparatorChar.ToString()
$alternateSeparator = [IO.Path]::AltDirectorySeparatorChar.ToString()
if ($candidatePath.Equals($parentPath, [StringComparison]::OrdinalIgnoreCase)) {
return $true
}
if (-not $parentPath.EndsWith($directorySeparator) -and -not $parentPath.EndsWith($alternateSeparator)) {
$parentPath += $directorySeparator
}
return $candidatePath.StartsWith($parentPath, [StringComparison]::OrdinalIgnoreCase)
}
function Get-ActualArchitecture {
$architecture = $env:PROCESSOR_ARCHITEW6432
if ([string]::IsNullOrWhiteSpace($architecture)) {
@@ -56,6 +76,24 @@ function Find-Editor([string]$Directory) {
return $null
}
function Install-ExportTemplates([string]$StagingDirectory, [string]$TemplateDirectory, [string]$TemplateAsset, [string]$ExpectedVersion) {
$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."
}
$actualVersion = (Get-Content -LiteralPath $stagedVersion -Raw).Trim()
if ($actualVersion -ne $ExpectedVersion) {
Fail "The export-template archive '$TemplateAsset' reports template version '$actualVersion', expected '$ExpectedVersion'."
}
New-Item -ItemType Directory -Force -Path $TemplateDirectory | Out-Null
Get-ChildItem -LiteralPath $stagedTemplates -Force | Copy-Item -Destination $TemplateDirectory -Recurse -Force
Remove-Item -LiteralPath $StagingDirectory -Recurse -Force
if (-not (Test-Path -LiteralPath (Join-Path $TemplateDirectory 'version.txt') -PathType Leaf)) {
Fail "The export-template archive '$TemplateAsset' could not be installed to '$TemplateDirectory'."
}
}
$GodotVersion = Require-Environment 'GODOT_VERSION'
$HostOs = Require-Environment 'GODOT_HOST_OS'
$HostArch = Require-Environment 'GODOT_HOST_ARCH'
@@ -80,8 +118,7 @@ if ($HostArch -ne (Get-ActualArchitecture)) { Fail "host-arch '$HostArch' does n
$workspaceDirectory = [IO.Path]::GetFullPath($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))
$projectRelativePath = [IO.Path]::GetRelativePath($workspaceDirectory, $ProjectDirectory)
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-PathIsWithinDirectory $workspaceDirectory $ProjectDirectory)) { Fail 'project-path must remain inside the checked-out workspace.' }
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'
if (-not (Test-Path -LiteralPath $PresetFile -PathType Leaf)) { Fail "No export_presets.cfg was found in project-path '$ProjectPath'." }
@@ -95,6 +132,7 @@ if ($Dotnet -eq 'true') {
'arm64' { "Godot_v${GodotVersion}_mono_windows_arm64.zip" }
}
$templatesAsset = "Godot_v${GodotVersion}_mono_export_templates.tpz"
$templateVersion = ($GodotVersion -replace '-', '.') + '.mono'
} else {
$edition = 'standard'
$editorAsset = switch ($HostArch) {
@@ -103,10 +141,10 @@ if ($Dotnet -eq 'true') {
'arm64' { "Godot_v${GodotVersion}_windows_arm64.exe.zip" }
}
$templatesAsset = "Godot_v${GodotVersion}_export_templates.tpz"
$templateVersion = $GodotVersion -replace '-', '.'
}
$script:BaseUrl = "https://github.com/godotengine/godot/releases/download/$GodotVersion"
$templateVersion = $GodotVersion -replace '-', '.'
$cacheDirectory = Join-Path $ActionRoot "cache\$GodotVersion\$edition\windows-$HostArch"
$editorDirectory = Join-Path $cacheDirectory 'editor'
$userHome = Join-Path $cacheDirectory 'home'
@@ -120,17 +158,21 @@ if ((Test-Path -LiteralPath $marker -PathType Leaf) -and (Test-Path -LiteralPath
if (-not $editorExecutable) {
if (Test-Path -LiteralPath $cacheDirectory) { Remove-Item -LiteralPath $cacheDirectory -Recurse -Force }
New-Item -ItemType Directory -Force -Path $editorDirectory, $templateDirectory | Out-Null
New-Item -ItemType Directory -Force -Path $editorDirectory | Out-Null
$manifestPath = Join-Path $cacheDirectory 'SHA512-SUMS.txt'
$editorArchive = Join-Path $cacheDirectory $editorAsset
$templatesArchive = Join-Path $cacheDirectory $templatesAsset
$templatesZipArchive = Join-Path $cacheDirectory ($templatesAsset -replace '\.tpz$', '.zip')
$templatesStagingDirectory = Join-Path $cacheDirectory 'templates-staging'
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
Move-Item -LiteralPath $templatesArchive -Destination $templatesZipArchive
Expand-Archive -LiteralPath $templatesZipArchive -DestinationPath $templatesStagingDirectory -Force
Install-ExportTemplates $templatesStagingDirectory $templateDirectory $templatesAsset $templateVersion
$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.' }