Skip to content

Commit

Permalink
update CI to use Godot w/Bitcoin module
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-L2L committed Jul 31, 2024
1 parent 9430a70 commit 1f6c5ef
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 2 deletions.
79 changes: 79 additions & 0 deletions .github/scripts/godot_ci_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#
# Fixes https://github.com/godotengine/godot/issues/77508
# original script source: https://gist.github.com/d6e/5ed21c37a8ac294db26532cc6af5c61c
#

import os
import subprocess
import time
import re
from pathlib import Path

# Set the path to your Godot project and Godot executable
GODOT_PROJECT_PATH = Path(".")
GODOT_EXECUTABLE = "godot" # or the path to your Godot executable
GODOT_LOG_FILE = Path("artifacts") / "godot_output.log" # Log file to store Godot output

print("Building godot cache...", flush=True)
start_time = time.time()

# Step 1: Recursively find all '.import' files and collect the expected imported file paths
expected_imported_files = set()
for import_file in GODOT_PROJECT_PATH.rglob('*.import'):
content = import_file.read_text()
matches = re.findall(r'dest_files=\["(res://\.godot/imported/.+?)"\]', content)
expected_imported_files.update(matches)

total_imports = len(expected_imported_files)
print(f"Found {total_imports} references to imported files...", flush=True)

# Step 2: Launch Godot in the background to start the import process
print("Starting Godot to import files...", flush=True)
GODOT_LOG_FILE.parent.mkdir(parents=True, exist_ok=True)
with GODOT_LOG_FILE.open("w") as log_file:
try:
godot_process = subprocess.Popen(
[GODOT_EXECUTABLE, "--path", str(GODOT_PROJECT_PATH), "--editor", "--headless"],
stdout=log_file,
stderr=subprocess.STDOUT
)
except Exception as e:
print(f"Failed to start Godot: {e}")
exit(1)

# Step 3: Continually check if the expected imported files exist
imported_folder = GODOT_PROJECT_PATH / ".godot/imported"
while expected_imported_files:
# Wait until the imported directory exists
if not imported_folder.exists():
print(f"Waiting for the imported directory to be created by Godot...")
time.sleep(1)
continue

for expected_path in list(expected_imported_files):
imported_file_path = GODOT_PROJECT_PATH / expected_path.replace("res://", "")
if imported_file_path.exists():
expected_imported_files.remove(expected_path)
imported_count = total_imports - len(expected_imported_files)
print(f"Imported {imported_count} / {total_imports} files...")
time.sleep(1) # Wait for a second before checking again

elapsed_time = time.time() - start_time
print(f"Imported all files in {elapsed_time:.2f} seconds.", flush=True)

# Step 4: Once all files have been imported, quit Godot
try:
print("Quitting Godot...", flush=True)
start_time = time.time()
godot_process.terminate()
godot_process.wait(timeout=10)

except subprocess.TimeoutExpired:
print("Godot did not terminate in a timely manner; killing the process.")
godot_process.kill()
finally:
elapsed_time = time.time() - start_time
print(f"Godot has been closed in {elapsed_time:.2f} seconds.", flush=True)

print("All files have been imported. Godot has been closed.")

58 changes: 56 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@ jobs:
include:
- build: linux
godot-bin: 'godot.linuxbsd.editor.x86_64.mono'
godot-template: 'godot.linuxbsd.template_release.x86_64.mono'
godot-templates: '/home/runner/.local/share/godot/export_templates/4.2.2.stable.mono'
- build: macos
godot-bin: 'godot.macos.editor.universal'
godot-template: 'godot.macos.template_release.universal'
godot-templates: '/Users/runner/Library/Application Support/Godot/export_templates/4.2.2.stable'
# Windows build runs on Ubuntu
- build: windows
godot-bin: 'godot.linuxbsd.editor.x86_64.mono'
godot-template: 'godot.linuxbsd.template_release.x86_64.mono'
godot-templates: '/home/runner/.local/share/godot/export_templates/4.2.2.stable.mono'

steps:
- uses: actions/checkout@v3
Expand All @@ -41,8 +47,27 @@ jobs:
tag: v4.2.2-bitcoin
filename: ${{ matrix.godot-bin }}

- name: Download Godot template w/Bitcoin module
uses: robinraju/release-downloader@v1.11
with:
repository: LayerTwo-Labs/godot-bitcoin-module
tag: v4.2.2-bitcoin
filename: ${{ matrix.godot-template }}

# FIXME: remove
- name: show files
- name: show files (linux / windows)
if: ${{ matrix.build == 'linux' || matrix.build == 'windows' }}
run: |
ls
echo 'TEMPLATES'
ls ${{ matrix.godot-templates }}
echo 'VERSION TXT'
cat "${{ matrix.godot-templates }}/version.txt"
echo $GODOT
# FIXME: remove
- name: show files (macos)
if: ${{ matrix.build == 'macos' }}
run: |
ls
#echo 'TEMPLATES'
Expand All @@ -53,6 +78,36 @@ jobs:
#cat '/Users/runner/Library/Application Support/Godot/export_templates/4.2.2.stable/version.txt'
echo $GODOT
- name: Replace default templates with custom templates (linux / windows)
if: ${{ matrix.build == 'linux' || matrix.build == 'windows' }}
run: |
rm "${{ matrix.godot-templates }}/linux_debug.x86_64"
rm "${{ matrix.godot-templates }}/linux_release.x86_64"
- name: Replace default templates with custom templates (macos)
if: ${{ matrix.build == 'macos' }}
run: |
zip --delete "${{ matrix.godot-templates }}/macos.zip" "macos_template.app/Contents/MacOS/godot_macos_release.universal"
zip --delete "${{ matrix.godot-templates }}/macos.zip" "macos_template.app/Contents/MacOS/godot_macos_debug.universal"
# FIXME: remove
- name: show files (linux / windows)
if: ${{ matrix.build == 'linux' || matrix.build == 'windows' }}
run: |
ls
echo 'TEMPLATES'
ls ${{ matrix.godot-templates }}
# FIXME: remove
- name: show files (macos)
if: ${{ matrix.build == 'macos' }}
run: |
ls
echo 'TEMPLATES'
ls '/Users/runner/Library/Application Support/Godot/export_templates/4.2.2.stable'
echo 'MACOS TEMPLATES'
zipinfo -1 '/Users/runner/Library/Application Support/Godot/export_templates/4.2.2.stable/macos.zip'
- name: Verify Setup
run: |
chmod +x ${{ matrix.godot-bin }}
Expand Down Expand Up @@ -85,7 +140,6 @@ jobs:
run: |
name="${{fromJSON('{"windows": "Windows Desktop", "macos": "macOS", "linux": "Linux/X11"}')[matrix.build] }}"
godot --headless --export-debug "$name" --verbose 2>&1 | tee build.log
env:
GODOT_MACOS_NOTARIZATION_API_KEY_ID:
${{ secrets.GODOT_MACOS_NOTARIZATION_API_KEY_ID }}
Expand Down

0 comments on commit 1f6c5ef

Please sign in to comment.