unity-devkit 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unity_devkit/__init__.py +0 -0
- unity_devkit/build_unity.py +101 -0
- unity_devkit/cache.py +89 -0
- unity_devkit/ci_step.py +52 -0
- unity_devkit/compile_unity.py +46 -0
- unity_devkit/git_tags.py +24 -0
- unity_devkit/install.py +169 -0
- unity_devkit/license.py +51 -0
- unity_devkit/license_restore.py +38 -0
- unity_devkit/lock_unity.py +28 -0
- unity_devkit/matrix.py +31 -0
- unity_devkit/projects.py +53 -0
- unity_devkit/py.typed +0 -0
- unity_devkit/setup.py +127 -0
- unity_devkit/setup_oras.py +51 -0
- unity_devkit/test_unity.py +31 -0
- unity_devkit/third-party/README.md +9 -0
- unity_devkit/third-party/dotnet-install.sh +1887 -0
- unity_devkit/unity.py +173 -0
- unity_devkit-0.1.0.dist-info/METADATA +11 -0
- unity_devkit-0.1.0.dist-info/RECORD +25 -0
- unity_devkit-0.1.0.dist-info/WHEEL +4 -0
- unity_devkit-0.1.0.dist-info/entry_points.txt +9 -0
- unity_devkit-0.1.0.dist-info/licenses/LICENSE +201 -0
- unity_devkit-0.1.0.dist-info/licenses/NOTICE +1 -0
unity_devkit/projects.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
MANIFEST_FILENAME = "unity-build.json"
|
|
8
|
+
PRUNE_DIRECTORIES = {".git", "Library", "Temp", "obj", "Build", "node_modules", "__pycache__"}
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class UnityBuildManifest(BaseModel, extra="forbid"):
|
|
12
|
+
builds: list[str] | None = None
|
|
13
|
+
execute_methods: dict[str, str] | None = None
|
|
14
|
+
package: str | None = None
|
|
15
|
+
grant_permissions: list[str] = []
|
|
16
|
+
tag_prefix: str | None = None
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class UnityProject(UnityBuildManifest):
|
|
20
|
+
path: Path
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def load_unity_projects() -> dict[str, UnityProject]:
|
|
24
|
+
projects: dict[str, UnityProject] = {}
|
|
25
|
+
for directory in directories_containing(Path.cwd(), MANIFEST_FILENAME):
|
|
26
|
+
project_path = directory.resolve()
|
|
27
|
+
name = project_path.name
|
|
28
|
+
version_file = project_path / "ProjectSettings" / "ProjectVersion.txt"
|
|
29
|
+
if not version_file.exists():
|
|
30
|
+
raise SystemExit(
|
|
31
|
+
f"{project_path / MANIFEST_FILENAME} is not inside a Unity project: missing {version_file}"
|
|
32
|
+
)
|
|
33
|
+
if name in projects:
|
|
34
|
+
raise SystemExit(f"Duplicate Unity project name '{name}': {projects[name].path} and {project_path}")
|
|
35
|
+
|
|
36
|
+
manifest = UnityBuildManifest(**json.loads((project_path / MANIFEST_FILENAME).read_text()))
|
|
37
|
+
projects[name] = UnityProject(path=project_path, **manifest.model_dump())
|
|
38
|
+
|
|
39
|
+
if not projects:
|
|
40
|
+
raise SystemExit(f"No {MANIFEST_FILENAME} manifests found under {Path.cwd()} — run from the repo root")
|
|
41
|
+
|
|
42
|
+
return projects
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def directories_containing(root: Path, filename: str) -> list[Path]:
|
|
46
|
+
directories: list[Path] = []
|
|
47
|
+
for directory, subdirectories, filenames in os.walk(root):
|
|
48
|
+
subdirectories[:] = sorted(
|
|
49
|
+
name for name in subdirectories if name not in PRUNE_DIRECTORIES and not name.startswith(".")
|
|
50
|
+
)
|
|
51
|
+
if filename in filenames:
|
|
52
|
+
directories.append(Path(directory))
|
|
53
|
+
return directories
|
unity_devkit/py.typed
ADDED
|
File without changes
|
unity_devkit/setup.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import platform
|
|
5
|
+
import re
|
|
6
|
+
import shlex
|
|
7
|
+
import shutil
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from bashrun import bash, bash_no_raise, bash_output
|
|
11
|
+
from pydantic import Field
|
|
12
|
+
from pydantic_settings import BaseSettings
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Settings(BaseSettings):
|
|
16
|
+
github_path: str | None = None
|
|
17
|
+
system_drive: str = Field("C:", validation_alias="SystemDrive")
|
|
18
|
+
agent_tools_directory: str | None = Field(None, validation_alias="AGENT_TOOLSDIRECTORY")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
settings = Settings.model_validate({})
|
|
22
|
+
|
|
23
|
+
CONTAINER_PATHS = ["/to_clean/android", "/to_clean/dotnet", "/to_clean/ghcup", "/to_clean/swift"]
|
|
24
|
+
|
|
25
|
+
BARE_LINUX_PATHS = ["/usr/local/lib/android", "/usr/share/dotnet", "/usr/local/.ghcup", "/usr/share/swift", "/opt/ghc"]
|
|
26
|
+
|
|
27
|
+
LARGE_PACKAGE_PATTERNS = [
|
|
28
|
+
"^aspnetcore-.*",
|
|
29
|
+
"^dotnet-.*",
|
|
30
|
+
"^llvm-.*",
|
|
31
|
+
"php.*",
|
|
32
|
+
"^mongodb-.*",
|
|
33
|
+
"^mysql-.*",
|
|
34
|
+
"azure-cli",
|
|
35
|
+
"google-chrome-stable",
|
|
36
|
+
"firefox",
|
|
37
|
+
"powershell",
|
|
38
|
+
"mono-devel",
|
|
39
|
+
"libgl1-mesa-dri",
|
|
40
|
+
"google-cloud-sdk",
|
|
41
|
+
"google-cloud-cli",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _remove_paths(paths: list[str], sudo: bool = False) -> None:
|
|
46
|
+
existing = [path for path in paths if Path(path).exists()]
|
|
47
|
+
if not existing:
|
|
48
|
+
return
|
|
49
|
+
if sudo:
|
|
50
|
+
bash_no_raise(f"sudo rm -rf {shlex.join(existing)}")
|
|
51
|
+
elif platform.system() == "Windows":
|
|
52
|
+
for path in existing:
|
|
53
|
+
shutil.rmtree(path, ignore_errors=True)
|
|
54
|
+
else:
|
|
55
|
+
bash_no_raise(f"rm -rf {shlex.join(existing)}")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# actions/checkout sets safe.directory in a temporary HOME that's cleaned up
|
|
59
|
+
# after the step finishes (actions/checkout#766). Container jobs that run
|
|
60
|
+
# git later need it re-set in the real HOME.
|
|
61
|
+
def configure_git(workspace: str) -> None:
|
|
62
|
+
bash(f"git config --global --add safe.directory {shlex.quote(workspace)}")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def free_disk_space(*, large_packages: bool = False, docker_images: bool = False, swap_storage: bool = False) -> None:
|
|
66
|
+
system = platform.system()
|
|
67
|
+
in_container = Path("/to_clean").is_dir()
|
|
68
|
+
|
|
69
|
+
if system == "Windows":
|
|
70
|
+
paths = [os.path.join(settings.system_drive, "Program Files", "dotnet")]
|
|
71
|
+
if settings.agent_tools_directory:
|
|
72
|
+
paths.append(settings.agent_tools_directory)
|
|
73
|
+
print(f"Removing: {', '.join(paths)}")
|
|
74
|
+
_remove_paths(paths)
|
|
75
|
+
elif in_container:
|
|
76
|
+
print("Removing pre-installed toolchains (container)")
|
|
77
|
+
_remove_paths(CONTAINER_PATHS)
|
|
78
|
+
else:
|
|
79
|
+
print("Removing pre-installed toolchains")
|
|
80
|
+
_remove_paths(BARE_LINUX_PATHS, sudo=True)
|
|
81
|
+
|
|
82
|
+
if large_packages:
|
|
83
|
+
print("Removing large apt packages")
|
|
84
|
+
bash_no_raise(f"sudo apt-get remove -y --fix-missing {shlex.join(LARGE_PACKAGE_PATTERNS)}")
|
|
85
|
+
bash_no_raise("sudo apt-get autoremove -y")
|
|
86
|
+
bash_no_raise("sudo apt-get clean")
|
|
87
|
+
|
|
88
|
+
if docker_images:
|
|
89
|
+
print("Pruning Docker images")
|
|
90
|
+
bash_no_raise("sudo docker image prune --all --force")
|
|
91
|
+
|
|
92
|
+
if swap_storage:
|
|
93
|
+
print("Removing swap")
|
|
94
|
+
bash_no_raise("sudo swapoff -a")
|
|
95
|
+
bash_no_raise("sudo rm -f /mnt/swapfile")
|
|
96
|
+
|
|
97
|
+
bash("df -h")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def install_dotnet(channel: str) -> None:
|
|
101
|
+
print(f"Installing .NET SDK {channel}")
|
|
102
|
+
script = Path(__file__).parent / "third-party" / "dotnet-install.sh"
|
|
103
|
+
bash(f"bash {script} --channel {channel}")
|
|
104
|
+
dotnet_path = str(Path.home() / ".dotnet")
|
|
105
|
+
os.environ["PATH"] = f"{dotnet_path}{os.pathsep}{os.environ['PATH']}"
|
|
106
|
+
if settings.github_path:
|
|
107
|
+
with open(settings.github_path, "a") as file:
|
|
108
|
+
file.write(f"{dotnet_path}\n")
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def install_node(version: str, registry_url: str | None = None) -> None:
|
|
112
|
+
system = platform.system()
|
|
113
|
+
sudo = system == "Linux" and os.geteuid() != 0
|
|
114
|
+
|
|
115
|
+
print(f"Installing Node.js {version}")
|
|
116
|
+
shasums = bash_output(f"curl -fsSL https://nodejs.org/dist/latest-v{version}.x/SHASUMS256.txt")
|
|
117
|
+
match = re.search(r"(node-v[\d.]+-linux-x64\.tar\.xz)", shasums)
|
|
118
|
+
if not match:
|
|
119
|
+
raise SystemExit(f"Could not find Node.js v{version} linux-x64 binary")
|
|
120
|
+
filename = match.group(1)
|
|
121
|
+
prefix = "sudo " if sudo else ""
|
|
122
|
+
bash(f"curl -fsSLO https://nodejs.org/dist/latest-v{version}.x/{filename}")
|
|
123
|
+
bash(f"{prefix}rm -rf /usr/local/lib/node_modules/npm")
|
|
124
|
+
bash(f"{prefix}tar -xJf {filename} -C /usr/local --strip-components=1")
|
|
125
|
+
Path(filename).unlink()
|
|
126
|
+
if registry_url:
|
|
127
|
+
(Path.home() / ".npmrc").write_text(f"registry={registry_url}\n")
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import platform
|
|
5
|
+
import shlex
|
|
6
|
+
import shutil
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from bashrun import bash
|
|
10
|
+
from pydantic_settings import BaseSettings
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Settings(BaseSettings):
|
|
14
|
+
github_token: str
|
|
15
|
+
github_actor: str = ""
|
|
16
|
+
github_path: str | None = None
|
|
17
|
+
runner_temp: str = "."
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def install_oras(version: str = "1.2.2") -> None:
|
|
21
|
+
settings = Settings.model_validate({})
|
|
22
|
+
system = platform.system()
|
|
23
|
+
sudo = system == "Linux" and os.geteuid() != 0
|
|
24
|
+
prefix = "sudo " if sudo else ""
|
|
25
|
+
|
|
26
|
+
if system == "Linux":
|
|
27
|
+
bash(f"{prefix}apt-get update -qq")
|
|
28
|
+
bash(f"{prefix}apt-get install -y -qq zstd")
|
|
29
|
+
elif system == "Windows":
|
|
30
|
+
bash("choco install zstandard -y --no-progress")
|
|
31
|
+
|
|
32
|
+
if system == "Linux":
|
|
33
|
+
archive = f"oras_{version}_linux_amd64.tar.gz"
|
|
34
|
+
bash(f"curl -fsSLO https://github.com/oras-project/oras/releases/download/v{version}/{archive}")
|
|
35
|
+
bash(f"{prefix}tar -xzf {archive} -C /usr/local/bin/ oras")
|
|
36
|
+
Path(archive).unlink()
|
|
37
|
+
elif system == "Windows":
|
|
38
|
+
archive = f"oras_{version}_windows_amd64.zip"
|
|
39
|
+
oras_directory = Path(settings.runner_temp) / "oras"
|
|
40
|
+
bash(f"curl -fsSLO https://github.com/oras-project/oras/releases/download/v{version}/{archive}")
|
|
41
|
+
shutil.unpack_archive(archive, oras_directory)
|
|
42
|
+
Path(archive).unlink()
|
|
43
|
+
os.environ["PATH"] = f"{oras_directory}{os.pathsep}{os.environ['PATH']}"
|
|
44
|
+
if settings.github_path:
|
|
45
|
+
with open(settings.github_path, "a") as file:
|
|
46
|
+
file.write(f"{oras_directory}\n")
|
|
47
|
+
|
|
48
|
+
bash(
|
|
49
|
+
f"oras login ghcr.io --username {shlex.quote(settings.github_actor)} --password-stdin",
|
|
50
|
+
stdin_text=settings.github_token,
|
|
51
|
+
)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Annotated
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
|
|
8
|
+
from .projects import load_unity_projects
|
|
9
|
+
from .unity import run_unity_batchmode
|
|
10
|
+
|
|
11
|
+
app = typer.Typer(add_completion=False, pretty_exceptions_show_locals=False)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@app.command()
|
|
15
|
+
def main(
|
|
16
|
+
project: Annotated[str, typer.Option(help="Unity project name (directory containing unity-build.json)")],
|
|
17
|
+
test_platform: Annotated[str, typer.Option(help="Unity test platform (EditMode or PlayMode)")] = "EditMode",
|
|
18
|
+
results: Annotated[Path, typer.Option(help="Output path for NUnit XML results")] = Path(
|
|
19
|
+
"artifacts/unity-test-results.xml"
|
|
20
|
+
),
|
|
21
|
+
) -> None:
|
|
22
|
+
projects = load_unity_projects()
|
|
23
|
+
if project not in projects:
|
|
24
|
+
raise SystemExit(f"Unknown project '{project}'. Valid: {', '.join(projects)}")
|
|
25
|
+
|
|
26
|
+
project_path = projects[project].path
|
|
27
|
+
results.parent.mkdir(parents=True, exist_ok=True)
|
|
28
|
+
|
|
29
|
+
run_unity_batchmode(
|
|
30
|
+
project_path, f"-runTests -testPlatform {test_platform} -testResults {results.resolve()}", auto_quit=False
|
|
31
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Third-party vendored files
|
|
2
|
+
|
|
3
|
+
## dotnet-install.sh
|
|
4
|
+
|
|
5
|
+
- **Source**: https://dot.net/v1/dotnet-install.sh
|
|
6
|
+
- **Upstream repo**: https://github.com/dotnet/install-scripts
|
|
7
|
+
- **License**: MIT (see header in script)
|
|
8
|
+
- **Vendored**: 2026-03-16
|
|
9
|
+
- **Why**: The `actions/setup-dotnet` GitHub Action bundles this script locally to avoid downloading it at runtime. We vendor it for the same reason — downloading it via curl inside CI containers is unreliable (timeouts).
|