Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elixir build script to export releases. #140

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_*
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ data_*/
.DS_Store

export/

addons/vsk_version/build_constants.gd.uid

addons/vsk_version/build_constants.gd

addons/vsk_version/vsk_version.gd.uid

commandlinetools-linux-8092744_latest.zip

jdk/

cmdline-tools/
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
255 changes: 255 additions & 0 deletions buildscript.iex
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
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
IO.inspect(files, label: "Pending files to delete")
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}/**/*")
extracted_files
{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"},
{"web", "wasm32"},
]
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, :darwin} ->
"#{System.get_env("HOME")}/Library/Application Support/Godot/export_templates/#{version}/"
{:unix, _} ->
"#{System.get_env("HOME")}/.local/share/godot/export_templates/#{version}/"
end
File.mkdir_p!(templatedir)

debug_file = case target_platform do
"linuxbsd" -> "#{@extract_dir_extracted}/godot.linuxbsd.template_debug.double.#{target_arch}"
"windows" -> "#{@extract_dir_extracted}/godot.windows.template_debug.double.#{target_arch}.llvm.exe"
"web" -> "#{@extract_dir_extracted}/godot.web.template_debug.double.wasm32.dlink.zip"
"macos" -> "#{@extract_dir_extracted}/godot_macos_double.zip"
"android" -> "#{@extract_dir_extracted}/android_debug.apk"
_ -> raise "Unsupported platform: #{target_platform}"
end

release_file = case target_platform do
"linuxbsd" -> "#{@extract_dir_extracted}/godot.linuxbsd.template_release.double.#{target_arch}"
"windows" -> "#{@extract_dir_extracted}/godot.windows.template_release.double.#{target_arch}.llvm.exe"
"web" -> "#{@extract_dir_extracted}/godot.web.template_release.double.wasm32.dlink.zip"
"macos" -> "#{@extract_dir_extracted}/godot_macos_double.zip"
"android" -> "#{@extract_dir_extracted}/android_release.apk"
_ -> raise "Unsupported platform: #{target_platform}"
end

debug_file_name = case target_platform do
"linuxbsd" -> "linux_debug.#{target_arch}"
"windows" -> "windows_debug_#{target_arch}.exe"
"web" -> "web_dlink_nothreads_debug.zip"
"macos" -> "macos_debug_#{target_arch}"
"android" -> "android_debug.apk"
_ -> "#{target_platform}_debug_#{target_arch}"
end

release_file_name = case target_platform do
"linuxbsd" -> "linux_release.#{target_arch}"
"windows" -> "windows_release_#{target_arch}.exe"
"web" -> "web_dlink_nothreads_release.zip"
"macos" -> "macos_release_#{target_arch}"
"android" -> "android_release.apk"
_ -> "#{target_platform}_release_#{target_arch}"
end

File.cp!(debug_file, "#{templatedir}/#{debug_file_name}", force: true)
File.cp!(release_file, "#{templatedir}/#{release_file_name}", force: true)
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
env = [{"ANDROID_SDK_ROOT", "#{File.cwd!()}/android_sdk"}, {"JAVA_HOME", "#{File.cwd!()}/jdk"}]
arguments = ["--headless", "--path", ".", "--import"]
System.cmd(editor_file, arguments, env: env)

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, env: env)
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