Skip to content

Commit

Permalink
Elixir build script to export releases.
Browse files Browse the repository at this point in the history
  • Loading branch information
fire committed Nov 13, 2024
1 parent e10fc50 commit 3bcb0ca
Show file tree
Hide file tree
Showing 30 changed files with 1,788 additions and 448 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Release

on:
push:
tags:
- 'v*.*.*'
branches:
- main
- master
pull_request:

jobs:
build:
runs-on: windows-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install unzip
run: choco install unzip

- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: '1.12'
otp-version: '24.0'

- name: Run build script
run: |
elixir --sname build -r buildscript.iex -e "BuildScript.all"
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: export/export_*
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ data_*/
.DS_Store

export/

addons/vsk_version/build_constants.gd.uid

addons/vsk_version/build_constants.gd

addons/vsk_version/vsk_version.gd.uid
1 change: 1 addition & 0 deletions addons/GPUTrail-main/GPUTrail3D.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bjpqewbtgif6n
1 change: 1 addition & 0 deletions addons/GPUTrail-main/plugin.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dtvbu6i7jdfpp
1 change: 1 addition & 0 deletions addons/GPUTrail-main/shaders/trail.gdshader.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://nqhuvjyl5bf4
1 change: 1 addition & 0 deletions addons/GPUTrail-main/shaders/trail_draw_pass.gdshader.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://b35htbko4hv85
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bhvqwircniboq
1 change: 1 addition & 0 deletions addons/procedural_3d_grid/core/bool_timer.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dioc7tw6snepa
1 change: 1 addition & 0 deletions addons/procedural_3d_grid/core/experiment.gdshader.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://b7vj4bp81hjsh
1 change: 1 addition & 0 deletions addons/procedural_3d_grid/core/follow_test.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://18xcph2o0pci
1 change: 1 addition & 0 deletions addons/procedural_3d_grid/core/hand.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bhgqer41udrla
1 change: 1 addition & 0 deletions addons/procedural_3d_grid/core/procedural_grid_3d.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://c6ouln8g13834
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cubfh2dm1g350
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dheiq8csvlle8
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://c46ssct7fj6pj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://b2cjphncghsi8
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dl6f33628oxnt
1 change: 1 addition & 0 deletions addons/procedural_3d_grid/core/strokes.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://beag45eu5igqb
1 change: 1 addition & 0 deletions addons/procedural_3d_grid/core/world_grab.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bcc178k783hmw
1 change: 1 addition & 0 deletions addons/procedural_3d_grid/core/xr_origin.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cqeyvdcoi37qr
1 change: 1 addition & 0 deletions addons/procedural_3d_grid/core/xr_pinch.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://c351cyh3u2n31
10 changes: 0 additions & 10 deletions addons/vsk_version/build_constants.gd

This file was deleted.

22 changes: 19 additions & 3 deletions addons/vsk_version/vsk_version.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,24 @@
@tool
extends Node

const build_constants_const = preload("build_constants.gd")
var build_constants = null

func _ready():
if ResourceLoader.exists("build_constants.gd"):
build_constants = preload("build_constants.gd")
else:
print("build_constants.gd does not exist")

static func get_build_label() -> String:
return build_constants_const.BUILD_DATE_STR + "\n" + build_constants_const.BUILD_LABEL
func get_build_label() -> String:
var build_label = "DEVELOPER_BUILD"
var build_date_str = "Build Date"
var build_unix_time = -1

if build_constants and build_constants.has("BUILD_LABEL"):
build_label = build_constants.BUILD_LABEL
if build_constants and build_constants.has("BUILD_DATE_STR"):
build_date_str = build_constants.BUILD_DATE_STR
if build_constants and build_constants.has("BUILD_UNIX_TIME"):
build_unix_time = build_constants.BUILD_UNIX_TIME

return build_date_str + "\n" + build_label
245 changes: 245 additions & 0 deletions buildscript.iex
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
defmodule BuildScript do
@url "https://github.com/V-Sekai/world-editor/releases/download/latest.v-sekai-editor-187/v-sekai-world.zip"
@output "v-sekai-world.zip"
@extract_dir "export"
@extract_dir_extracted "#{@extract_dir}/temp"
@os_family :os.type()
@project_name "xr_grid"
@expected_hash "F7AB549A676C52DD47F9D74C9308EBBE447ABFA1513C7E563B3C15809C0CE3E3"

def all do
pending_files_to_delete = editor_download()
editor_sign()
export_stage()
cleanup_pending_files(pending_files_to_delete)
end

def editor_download do
case verify_hash() do
{:ok, _hash, _message} ->
IO.puts("File hash matches, skipping download.")
{:error, _hash, _message} ->
download()
case verify_hash() do
{:ok, _hash, _message} ->
IO.puts("Download complete and hash verified.")
{:error, _hash, _message} ->
IO.puts("Hash verification failed after download.")
exit(:normal)
end
end
pending_files_to_delete = extract()
create_gdignore()
pending_files_to_delete
end

defp cleanup_pending_files(files) do
for file <- files do
File.rm_rf!(file)
end
end

def editor_sign do
make_executable()
sign_app()
end

def download do
File.mkdir_p!(@extract_dir)
System.cmd("curl", ["-L", @url, "-o", "#{@extract_dir}/#{@output}"])
end

def verify_hash do
case File.read("#{@extract_dir}/#{@output}") do
{:ok, content} ->
hash = :crypto.hash(:sha256, content) |> Base.encode16()
IO.puts("Computed hash: #{hash}")
if hash == @expected_hash do
{:ok, hash, "Hash matches"}
else
{:error, hash, "Hash does not match"}
end
_ ->
{:error, nil, "File not found"}
end
end
def extract do
File.mkdir_p!(@extract_dir_extracted)
case System.cmd("tar", ["-xvf", "#{@extract_dir}/#{@output}", "-C", "#{@extract_dir_extracted}", "--strip-components=1"]) do
{output, 0} ->
IO.puts("Extraction output:\n#{output}")
extracted_files = Path.wildcard("#{@extract_dir_extracted}/**/*")

Check warning on line 71 in buildscript.iex

View workflow job for this annotation

GitHub Actions / build

variable "extracted_files" is unused (if the variable is not meant to be used, prefix it with an underscore)
{output, _} ->
IO.puts("Failed to extract file. Output:\n#{output}")
exit(:normal)
end
end

def create_gdignore do
File.touch("#{@extract_dir}/.gdignore")
end

def make_executable do
case @os_family do
{:win32, :nt} ->
# Windows specific commands
:ok
{:unix, _} ->
File.chmod("#{@extract_dir_extracted}/godot.macos.editor.double.arm64", 0o755)
File.chmod("#{@extract_dir_extracted}/godot.macos.template_debug.double.arm64", 0o755)
File.chmod("#{@extract_dir_extracted}/godot.macos.template_release.double.arm64", 0o755)
File.chmod("#{@extract_dir_extracted}/godot_macos_editor_double.app/Contents/MacOS/Godot", 0o755)
end
end

def sign_app do
case @os_family do
{:win32, :nt} ->
# Windows specific commands
:ok
{:unix, :darwin} ->
System.cmd("codesign", ["--deep", "--force", "--sign", "-", "#{@extract_dir_extracted}/godot.macos.editor.double.arm64"])
System.cmd("codesign", ["--deep", "--force", "--sign", "-", "#{@extract_dir_extracted}/godot.macos.template_debug.double.arm64"])
System.cmd("codesign", ["--deep", "--force", "--sign", "-", "#{@extract_dir_extracted}/godot.macos.template_release.double.arm64"])
System.cmd("codesign", ["--deep", "--force", "--sign", "-", "#{@extract_dir_extracted}/godot_macos_editor_double.app/Contents/MacOS/Godot"])
:ok
_ ->
:ok
end
end

def export_stage do
editor_path = case @os_family do
{:win32, :nt} ->
"#{@extract_dir_extracted}/godot.windows.editor.double.x86_64.llvm.exe"
{:unix, :darwin} ->
"#{@extract_dir_extracted}/godot.macos.editor.double.arm64"
{:unix, _} ->
"#{@extract_dir_extracted}/godot.linux.editor.double.x86_64"
end

if File.exists?(editor_path) do
File.chmod(editor_path, 0o755)
version = System.cmd(editor_path, ["--version"]) |> elem(0) |> String.trim()
platforms = [
{"windows", "x86_64"},
{"linuxbsd", "x86_64"},
{"macos", "arm64"},
{"android", "arm64"}
]
for {target_platform, target_arch} <- platforms do
export_template(platform_name(@os_family), platform_arch(@os_family), target_platform, target_arch, version)
export_platform(platform_name(@os_family), platform_arch(@os_family), target_platform, target_arch)
end
else
IO.puts("Editor path not found: #{editor_path}")
end
end

defp platform_name({:win32, :nt}), do: "windows"
defp platform_name({:unix, :darwin}), do: "macos"
defp platform_name({:unix, _}), do: "linux"

defp platform_arch({:win32, :nt}), do: "x86_64"
defp platform_arch({:unix, :darwin}), do: "arm64"
defp platform_arch({:unix, _}), do: "x86_64"

def create_version_file(version) do
content = """
## AUTOGENERATED BY BUILD
const BUILD_LABEL = "#{version}"
const BUILD_DATE_STR = "#{:os.system_time(:seconds) |> DateTime.from_unix!() |> DateTime.to_iso8601()}"
const BUILD_UNIX_TIME = #{:os.system_time(:seconds)}
"""
File.mkdir_p!("addons/vsk_version")
File.write!("addons/vsk_version/build_constants.gd", content)
end

def export_template(from_platform, from_arch, target_platform, target_arch, version) do
version = String.replace(version, ".custom_build", "")
create_version_file(version)
templatedir = case @os_family do
{:win32, :nt} -> "#{System.get_env("USERPROFILE")}/AppData/Roaming/Godot/export_templates/#{version}/"
{:unix, _} -> "#{System.get_env("HOME")}/Library/Application Support/Godot/export_templates/#{version}/"
end
File.mkdir_p!(templatedir)
debug_file = if from_platform == "windows" do
"#{@extract_dir_extracted}/godot.#{from_platform}.template_debug.double.#{from_arch}.llvm.exe"
else
"#{@extract_dir_extracted}/godot.#{from_platform}.template_debug.double.#{from_arch}"
end

release_file = if from_platform == "windows" do
"#{@extract_dir_extracted}/godot.#{from_platform}.template_release.double.#{from_arch}.llvm.exe"
else
"#{@extract_dir_extracted}/godot.#{from_platform}.template_release.double.#{from_arch}"
end

if target_platform == "linuxbsd" do
File.rename("#{templatedir}#{target_platform}_debug_#{target_arch}.exe", "#{templatedir}linux_debug_#{target_arch}.exe")
File.rename("#{templatedir}#{target_platform}_release_#{target_arch}.exe", "#{templatedir}linux_release_#{target_arch}.exe")
end
if target_platform == "windows" do
File.rename("#{templatedir}#{target_platform}_debug_#{target_arch}.exe", "#{templatedir}windows_debug_#{target_arch}.exe")
File.rename("#{templatedir}#{target_platform}_release_#{target_arch}.exe", "#{templatedir}windows_release_#{target_arch}.exe")
end
if @os_family == {:win32, :nt} do
user_profile = System.get_env("USERPROFILE")
if File.exists?(debug_file) do
File.cp!(debug_file, "#{user_profile}/AppData/Roaming/Godot/export_templates/#{version}/windows_debug_#{target_arch}.exe", force: true)
else
IO.puts("Debug file not found: #{debug_file}")
end
if File.exists?(release_file) do
File.cp!(release_file, "#{user_profile}/AppData/Roaming/Godot/export_templates/#{version}/windows_release_#{target_arch}.exe", force: true)
else
IO.puts("Release file not found: #{release_file}")
end
end
end

def export_platform(from_platform, from_arch, target_platform, target_arch) do
File.rm_rf!("#{@extract_dir}/export_#{target_platform}_#{target_arch}")
File.mkdir_p!("#{@extract_dir}/export_#{target_platform}_#{target_arch}")

editor_file = if from_platform == "windows" and File.exists?("#{@extract_dir_extracted}/godot.#{from_platform}.editor.double.#{from_arch}.llvm.exe") do
"#{@extract_dir_extracted}/godot.#{from_platform}.editor.double.#{from_arch}.llvm.exe"
else
"#{@extract_dir_extracted}/godot.#{from_platform}.editor.double.#{from_arch}"
end

arguments = ["--headless", "--path", ".", "--import"]
System.cmd(editor_file, arguments)

output_file = "#{@extract_dir}/export_#{target_platform}_#{target_arch}/#{@project_name}"
output_file = if target_platform == "windows", do: output_file <> ".exe", else: output_file

arguments = ["--headless", "--path", ".", "--export-release", target_platform, output_file]
System.cmd(editor_file, arguments)
IO.puts(Enum.join(arguments, " "))

case target_platform do
"windows" ->
System.cmd("strip", [output_file])
pdb_file = "#{@extract_dir_extracted}/godot.#{target_platform}.template_release.double.#{from_arch}.llvm.pdb"
if File.exists?(pdb_file) do
File.cp!(pdb_file, "#{@extract_dir}/export_#{target_platform}_#{target_arch}/#{Path.basename(pdb_file)}")
else
IO.puts("PDB file not found: #{pdb_file}")
end
_ -> :ok
end
end

def upload_stage do
upload_artifacts("windows", "x86_64")
upload_artifacts("linux", "x86_64")
end

def upload_artifacts(platform, arch) do
File.mkdir_p!("#{@extract_dir}/game")
File.mkdir_p!("#{@extract_dir}/editor")
File.cp_r!("#{@extract_dir_extracted}/export_#{platform}_#{arch}", "#{@extract_dir}/game")
File.cp_r!("#{@extract_dir_extracted}/export_#{platform}_#{arch}/xr_grid_#{platform}_#{arch}", "#{@extract_dir}/editor/xr_grid_#{platform}_#{arch}_editor")
end
end
Loading

0 comments on commit 3bcb0ca

Please sign in to comment.