Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
init CI (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-L2L authored Oct 21, 2024
1 parent 5d0e287 commit 6e16375
Show file tree
Hide file tree
Showing 2 changed files with 195 additions and 0 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("./cusf_launcher")
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.")

116 changes: 116 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Build Launcher
on:
pull_request:
push:
branches:
- "main"
workflow_dispatch:

jobs:
build:
# both Windows and Linux builds run on Ubuntu
runs-on: ${{ matrix.build == 'macos' && 'macos' || 'ubuntu' }}-latest
strategy:
fail-fast: false
matrix:
build: [macos, windows, linux]
include:
- build: linux
target-bin: 'cusf_launcher.x86_64'
- build: macos
target-bin: 'cusf_launcher.dmg'
- build: windows
target-bin: 'cusf_launcher.exe'

steps:
- uses: actions/checkout@v3

- uses: chickensoft-games/setup-godot@v1
with:
version: 4.3.0
use-dotnet: false
include-templates: true

- name: Verify Setup
run: godot --version

- name: Import certificate to Keychain
if: ${{ matrix.build == 'macos' }}
run: |
echo "${{ secrets.MACOS_CERTIFICATE }}" | base64 --decode > certificate.p12
KEYCHAIN_PASSWORD=$(uuidgen)
security create-keychain -p "$KEYCHAIN_PASSWORD" build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p "$KEYCHAIN_PASSWORD" build.keychain
security import ./certificate.p12 -k ~/Library/Keychains/build.keychain -P ${{ secrets.MACOS_CERTIFICATE_PASSWORD }} -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple: -s -k "$KEYCHAIN_PASSWORD" ~/Library/Keychains/build.keychain
env:
MACOS_CERTIFICATE_PASSWORD: ${{ secrets.MACOS_CERTIFICATE_PASSWORD }}

- name: Setup notarization credentials
if: ${{ matrix.build == 'macos' }}
run: |
echo ${{ secrets.GODOT_MACOS_NOTARIZATION_API_KEY }} | base64 --decode > notarization_api_key.p8
# MUST be run before build
- name: Initialize godot cache
run: python3 .github/scripts/godot_ci_cache.py

- name: Export build
run: |
name="${{fromJSON('{"windows": "Windows", "macos": "Mac", "linux": "Linux"}')[matrix.build] }}"
godot --path "./cusf_launcher/" --headless --export-release "$name" "${{ matrix.target-bin }}" --verbose 2>&1 | tee build.log
env:
GODOT_MACOS_NOTARIZATION_API_KEY_ID:
${{ secrets.GODOT_MACOS_NOTARIZATION_API_KEY_ID }}
GODOT_MACOS_NOTARIZATION_API_KEY: ./notarization_api_key.p8
GODOT_MACOS_NOTARIZATION_API_UUID:
${{ secrets.GODOT_MACOS_NOTARIZATION_API_UUID }}

- name: Upload build
uses: actions/upload-artifact@v4
with:
name: cusf_launcher_${{ matrix.build }}
if-no-files-found: error
path: cusf_launcher/${{ matrix.target-bin }}

- name: Wait for notarization to finish
if: ${{ matrix.build == 'macos' }}
run: |
request_id=$(grep 'Notarization request UUID' build.log | rev | cut -d ' ' -f 1 | rev | tr -d '"')
xcrun notarytool wait $request_id \
--issuer ${{ secrets.GODOT_MACOS_NOTARIZATION_API_UUID }} \
--key-id ${{ secrets.GODOT_MACOS_NOTARIZATION_API_KEY_ID }} \
--key ./notarization_api_key.p8
upload-artifacts-to-releases-drivechain-info:
name: Upload artifacts to releases.drivechain.info
runs-on: ubuntu-latest
needs: [build]
# avoid uploading on PRs!
if: github.event_name == 'push' && github.repository_owner == 'LayerTwo-Labs'
steps:
- name: Download artifacts
uses: actions/download-artifact@v4

- name: Create zip files for releases.drivechain.info
run: |
mv cusf_launcher_linux cusf-launcher-latest-x86_64-unknown-linux-gnu
zip -r cusf-launcher-latest-x86_64-unknown-linux-gnu.zip cusf-launcher-latest-x86_64-unknown-linux-gnu/*
mv cusf_launcher_macos cusf-launcher-latest-x86_64-apple-darwin
zip -r cusf-launcher-latest-x86_64-apple-darwin.zip cusf-launcher-latest-x86_64-apple-darwin/*
mv cusf_launcher_windows cusf-launcher-latest-x86_64-w64
zip -r cusf-launcher-latest-x86_64-w64.zip cusf-launcher-latest-x86_64-w64/*
- name: Upload release assets to releases.drivechain.info
uses: cross-the-world/ssh-scp-ssh-pipelines@latest
with:
host: 45.33.96.47
user: root
pass: ${{ secrets.RELEASES_SERVER_PW }}
port: 22
scp: |
'cusf-launcher-latest-*.zip' => '/var/www/html/'

0 comments on commit 6e16375

Please sign in to comment.