unity-devkit 0.1.0__tar.gz
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-0.1.0/.github/workflows/ci.yml +30 -0
- unity_devkit-0.1.0/.github/workflows/release.yml +25 -0
- unity_devkit-0.1.0/.gitignore +6 -0
- unity_devkit-0.1.0/AGENTS.md +53 -0
- unity_devkit-0.1.0/CLAUDE.md +1 -0
- unity_devkit-0.1.0/LICENSE +201 -0
- unity_devkit-0.1.0/NOTICE +1 -0
- unity_devkit-0.1.0/PKG-INFO +11 -0
- unity_devkit-0.1.0/README.md +47 -0
- unity_devkit-0.1.0/publish-config.json +11 -0
- unity_devkit-0.1.0/pyproject.toml +40 -0
- unity_devkit-0.1.0/ruff.toml +95 -0
- unity_devkit-0.1.0/src/unity_devkit/__init__.py +0 -0
- unity_devkit-0.1.0/src/unity_devkit/build_unity.py +101 -0
- unity_devkit-0.1.0/src/unity_devkit/cache.py +89 -0
- unity_devkit-0.1.0/src/unity_devkit/ci_step.py +52 -0
- unity_devkit-0.1.0/src/unity_devkit/compile_unity.py +46 -0
- unity_devkit-0.1.0/src/unity_devkit/git_tags.py +24 -0
- unity_devkit-0.1.0/src/unity_devkit/install.py +169 -0
- unity_devkit-0.1.0/src/unity_devkit/license.py +51 -0
- unity_devkit-0.1.0/src/unity_devkit/license_restore.py +38 -0
- unity_devkit-0.1.0/src/unity_devkit/lock_unity.py +28 -0
- unity_devkit-0.1.0/src/unity_devkit/matrix.py +31 -0
- unity_devkit-0.1.0/src/unity_devkit/projects.py +53 -0
- unity_devkit-0.1.0/src/unity_devkit/py.typed +0 -0
- unity_devkit-0.1.0/src/unity_devkit/setup.py +127 -0
- unity_devkit-0.1.0/src/unity_devkit/setup_oras.py +51 -0
- unity_devkit-0.1.0/src/unity_devkit/test_unity.py +31 -0
- unity_devkit-0.1.0/src/unity_devkit/third-party/README.md +9 -0
- unity_devkit-0.1.0/src/unity_devkit/third-party/dotnet-install.sh +1887 -0
- unity_devkit-0.1.0/src/unity_devkit/unity.py +173 -0
- unity_devkit-0.1.0/uv.lock +305 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
check:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v5
|
|
18
|
+
|
|
19
|
+
- uses: astral-sh/setup-uv@v7
|
|
20
|
+
with:
|
|
21
|
+
enable-cache: true
|
|
22
|
+
|
|
23
|
+
- name: Lint
|
|
24
|
+
run: uv run ruff check .
|
|
25
|
+
|
|
26
|
+
- name: Format
|
|
27
|
+
run: uv run ruff format --check .
|
|
28
|
+
|
|
29
|
+
- name: Type check
|
|
30
|
+
run: uv run basedpyright
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_run:
|
|
5
|
+
workflows: [CI]
|
|
6
|
+
types: [completed]
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
publish:
|
|
11
|
+
if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' && github.event.workflow_run.head_branch == 'main'
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
permissions:
|
|
14
|
+
contents: write
|
|
15
|
+
id-token: write
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v5
|
|
18
|
+
|
|
19
|
+
# Workaround: fetch-tags is broken with shallow clones
|
|
20
|
+
- run: git fetch --tags origin
|
|
21
|
+
|
|
22
|
+
- uses: astral-sh/setup-uv@v7
|
|
23
|
+
|
|
24
|
+
- name: Publish
|
|
25
|
+
run: uvx --from release-kit==0.1.0 publish-packages --config publish-config.json
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# unity-devkit
|
|
2
|
+
|
|
3
|
+
## What this is
|
|
4
|
+
|
|
5
|
+
`unity-devkit` is the Unity build toolkit: project discovery, local builds, CI builds, license activation, the `install` command (download-or-build then install onto a device), and the ORAS cache/setup helpers those need. Consumer repositories install this package from PyPI and get the same Unity CI and install flow — paired with a reusable `unity-build.yml` GitHub Actions workflow (housed in consumer repos today) that invokes only this package's entry points.
|
|
6
|
+
|
|
7
|
+
The repo and package renamed from `unity-devkit` to `unity-devkit` (2026-09-21, member of the `-devkit` family; before that `placeframe-unity` → `unity-devkit` on extraction). The PyPI identity is fresh: `unity-devkit` starts its own tag ledger at `0.1.0`; the terminal `unity-devkit` distributions (≤0.1.1) are deprecation signposts pointing here, not this package's history.
|
|
8
|
+
|
|
9
|
+
## Release flow
|
|
10
|
+
|
|
11
|
+
Publishing rides `release.yml`, triggered by a successful CI run on a `main` push: the machinery — release-kit, invoked uvx-isolated, never a project dependency (unity-devkit sits inside its own dependency graph; a project-level release-kit edge is a resolver cycle) — computes the plan from the tag ledger and path-diff, patches the version ephemerally, and publishes to PyPI under OIDC trusted publishing (publisher bound to `release.yml`, no environment). The committed `pyproject.toml` version is permanently the `0.0.0.dev0` sentinel; the `unity-devkit-v*` tags are the version ledger (first release `0.1.0`, patch-auto thereafter). API-breaking changes ship with a manually bumped version — patch-auto assumes additive changes.
|
|
12
|
+
|
|
13
|
+
## Shape
|
|
14
|
+
|
|
15
|
+
One flat module per concern under `src/unity_devkit/`:
|
|
16
|
+
|
|
17
|
+
| `uv run` command | Module | Notes |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| `compile-unity` | `compile_unity.py` | Local Unity build (APK or platform binary, suitable for `adb install`). Required flags: `--project <name>` and `--build <target>`, matching a discovered `unity-build.json` manifest. Streams the editor log, prints output paths under `<project>/Build/`. |
|
|
20
|
+
| `install` | `install.py` | Install a Unity build onto an `adb`-connected device or launch a linux executable. Default: download the latest GitHub Actions artifact for `(project, target)` on the current branch (overridable with `--branch` / `--run`), cache it under `~/.unity-devkit/builds/{run_id}/`, `adb install` the APK (or `bash_handoff` the linux64 executable). With `--build` / `-B`, skips the artifact fetch and calls `compile-unity` locally instead, funneling the produced APK / executable through the same install path. Honours the manifest's `package` (for pre-install uninstall) and `grant_permissions` (post-install `adb shell pm grant`). |
|
|
21
|
+
| `lock-unity` | `lock_unity.py` | Lock Unity package versions for reproducible builds. |
|
|
22
|
+
| `test-unity` | `test_unity.py` | Run Unity editmode / playmode tests. |
|
|
23
|
+
| `activate-unity-license` | `license.py` | Activate the Unity Editor license (locally or with `--oras-push` for the CI cache). |
|
|
24
|
+
| `unity-license-tag` | `license_restore.py` | Print the license cache tag (CI pins it via `LICENSE_CACHE_TAG`). |
|
|
25
|
+
| `unity-matrix` | `matrix.py` | Emit the CI build matrix (CI-only). |
|
|
26
|
+
| `build-unity` | `build_unity.py` | CI build with library cache restore/save and version stamping (CI-only; assumes `GITHUB_WORKSPACE`, OCI registry, runner environment). |
|
|
27
|
+
|
|
28
|
+
Supporting modules: `projects.py` (manifest schema + discovery), `unity.py` (editor lookup, platform configs, batchmode command, shared Unity runner), `git_tags.py` (generic git-tag helpers), `cache.py` (ORAS restore/save), `ci_step.py` (GitHub Actions `::group::` step wrapper), `setup.py` / `setup_oras.py` (CI runner provisioning), `third-party/dotnet-install.sh` (vendored — see its sibling README for provenance).
|
|
29
|
+
|
|
30
|
+
## Constraints
|
|
31
|
+
|
|
32
|
+
**Every Unity invocation goes through `unity.run_unity_batchmode`, which does not trust the editor's exit code.** Unity exits 0 while reporting fatal package-manager errors (unresolvable dependencies, invalid package.json versions) only in the editor log — a resolver failure therefore surfaces as a stale `packages-lock.json` and nothing else. The runner streams the log live through `tee` into a captured file and afterwards scans it for `QUIET_FAILURE_SIGNATURES`; a match fails the invocation with the matched log block regardless of exit code. New Unity verbs must call the runner rather than invoking the editor directly, and newly discovered silent-failure log lines get added to the signature tuple. Exit-code strictness is per-verb: build/test verbs fail on non-zero (`strict_exit=True`, the default), while `lock-unity` passes `strict_exit=False` — it judges resolution, not compilation, so a project whose scripts fail to compile (resolution already done, lock written) produces a warning, not a failure. `-runTests` invocations pass `auto_quit=False` (the test runner owns exit timing).
|
|
33
|
+
|
|
34
|
+
**Every runtime dependency must be PyPI-resolvable.** This package publishes to and is consumed from PyPI, and a registry consumer resolves the whole graph transitively by name — any dependency that is not on PyPI breaks every consumer's install. [`bashrun`](https://github.com/outernet-foundation/bashrun) is on PyPI like the rest; git-source pins are a scratch-branch-only vehicle for testing unreleased changes.
|
|
35
|
+
|
|
36
|
+
**Unity project discovery is manifest-driven, not catalog-driven.** The Unity commands discover projects by scanning the working-directory tree for `unity-build.json` manifest files (pruning `Library`, `Temp`, `obj`, `Build`, `node_modules`, `.git`, and dot-directories). A manifest marks its directory as an opted-in Unity project; the project name is the directory name; the manifest carries only intent the project cannot otherwise express (`builds`, `execute_methods`, `package`, `grant_permissions`, `tag_prefix` — schema in `projects.py`). There is no central catalog: a project's build identity lives inside the project, so it travels with the project if it moves between repositories, and the commands run unchanged in any repo containing manifests. Discovery anchors at the current working directory — run commands from the repo root.
|
|
37
|
+
|
|
38
|
+
**`unity-matrix` prints `$GITHUB_OUTPUT`-format lines, not bare JSON.** Its stdout is two `key=value` lines — `matrix=<JSON with an include array>` and `license-image=<unityci/editor tag>` — so the workflow step is exactly `uv run --no-sync unity-matrix >> "$GITHUB_OUTPUT"` with no shell logic. Each matrix entry carries an `editor-image` tag composed from the project's `ProjectSettings/ProjectVersion.txt` editor version, the platform's unityci module, and the `UNITYCI_IMAGE_REVISION` constant in `unity.py`; `license-image` uses the highest discovered editor version with the `linux-il2cpp` module. Nothing else pins an editor version: upgrading a project's editor in `ProjectVersion.txt` automatically switches its CI container, and the consumer-side `unity-build.yml` stays free of repo-specific values.
|
|
39
|
+
|
|
40
|
+
**Entry-point names are the workflow contract.** Consumer `unity-build.yml` workflows invoke `unity-matrix`, `unity-license-tag`, `activate-unity-license`, and `build-unity` by name via `uv run`. Consumers pin the workflow by ref and this package by git revision independently; the two pins stay compatible as long as the entry-point names and flags hold, so treat those as a public API.
|
|
41
|
+
|
|
42
|
+
**The environment-lookup helpers are cross-repo Python API.** `unity.find_editor_for_version` (editor ladder: `unity-editor` on PATH → `/opt/unity/<version>` → `~/Unity/Hub/Editor/<version>`; raises `ValueError` listing every searched path on a miss), `unity.editor_version` (`ProjectVersion.txt` parse; `None` for a missing file or unparseable content), and `projects.directories_containing` (+ `PRUNE_DIRECTORIES`) are imported by git-referencing consumers — prepo's `sync` verb — the same way pubpkg imports `ci_step`/`setup`. Their signatures and miss behavior are contract, not internals. The `SystemExit`-raising wrappers (`find_unity_editor`, `read_editor_version`) exist for unity-devkit's own CLI paths and delegate to the core helpers.
|
|
43
|
+
|
|
44
|
+
**Version stamping is opt-in via `tag_prefix`.** `build-unity` writes `.build-version.json` (consumed by the project's build `executeMethod`) only when the project's manifest declares `tag_prefix`; the version is the latest `<tag_prefix>-v*` git tag plus a run-number suffix. Projects without the field build unversioned. Consumer repos that release keep their own name→prefix map on their side — the two must agree for projects that release.
|
|
45
|
+
|
|
46
|
+
**`dotnet-install.sh` is vendored, not downloaded.** Downloading it via curl inside CI containers is unreliable (timeouts) — the same reason `actions/setup-dotnet` bundles it. It ships as package data inside `src/unity_devkit/third-party/` and is resolved `__file__`-relative, which works in editable installs, wheels, and git checkouts alike.
|
|
47
|
+
|
|
48
|
+
**The ORAS cache media type identifies the wrapper package, not the consuming repo.** `cache.save()` pushes with `application/vnd.unity-devkit.cache.v1+zstd`. Restore doesn't filter on media type, so older manifests carrying a different vendor prefix still pull, but new pushes always carry this one — the identifier tracks the tool that wrote the cache, not the project whose bytes are inside it.
|
|
49
|
+
|
|
50
|
+
## See also
|
|
51
|
+
|
|
52
|
+
- [`bashrun`](https://github.com/outernet-foundation/bashrun) — the shell-exec helpers this package uses everywhere (`bash`, `bash_output`, `bash_check`, `bash_handoff`).
|
|
53
|
+
- `README.md` — human-facing setup, command catalog, and consumer install snippet.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@AGENTS.md
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright 2026 Tyler Hatch
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: unity-devkit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Unity project discovery, build, license, and CI tooling
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
License-File: NOTICE
|
|
7
|
+
Requires-Python: >=3.13
|
|
8
|
+
Requires-Dist: bashrun>=0.1.0
|
|
9
|
+
Requires-Dist: pydantic-settings>=2.9.1
|
|
10
|
+
Requires-Dist: pydantic>=2.11.7
|
|
11
|
+
Requires-Dist: typer>=0.17.4
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# unity-devkit
|
|
2
|
+
|
|
3
|
+
Unity project discovery, local builds, CI builds, license activation, and the shared CI helpers those need. Consumers scan the working-directory tree for `unity-build.json` manifests to enumerate their Unity projects; the commands here (`compile-unity`, `install`, `build-unity`, `unity-matrix`, license helpers) work unchanged in any repo containing manifests. Paired with the reusable [`unity-build.yml`](https://github.com/outernet-foundation/unity-devkit/blob/main/.github/workflows/unity-build.yml) GitHub Actions workflow (once the workflow lands here — until then, workflow YAML lives in consumer repos).
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
Requires Python 3.13+ and [uv](https://docs.astral.sh/uv/).
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
uv sync
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Commands
|
|
14
|
+
|
|
15
|
+
Run from a repo root containing one or more `unity-build.json` manifests.
|
|
16
|
+
|
|
17
|
+
| `uv run <name>` | What it does |
|
|
18
|
+
|---|---|
|
|
19
|
+
| `compile-unity --project <name> --build <target>` | Local Unity build (APK or platform binary) suitable for `adb install`. |
|
|
20
|
+
| `install --project <name>` | Download the latest CI artifact and `adb install` (or launch, for `linux64`); with `--build`, compile locally first. |
|
|
21
|
+
| `lock-unity` | Lock Unity package versions. |
|
|
22
|
+
| `test-unity --project <name>` | Run editmode / playmode tests. |
|
|
23
|
+
| `activate-unity-license` | Activate the Unity Editor license (locally or with `--oras-push`). |
|
|
24
|
+
| `unity-license-tag` | Print the license cache tag. |
|
|
25
|
+
| `unity-matrix` | Emit the CI build matrix (CI-only; two `key=value` lines for `$GITHUB_OUTPUT`). |
|
|
26
|
+
| `build-unity` | CI build with library-cache restore/save and version stamping (CI-only). |
|
|
27
|
+
|
|
28
|
+
Every command accepts `--help`.
|
|
29
|
+
|
|
30
|
+
## Consuming from another repo
|
|
31
|
+
|
|
32
|
+
Install from PyPI:
|
|
33
|
+
|
|
34
|
+
```toml
|
|
35
|
+
[project]
|
|
36
|
+
dependencies = ["unity-devkit>=0.1.0"]
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Then `uv run compile-unity`, `uv run install`, etc. work from that repo against its own `unity-build.json` projects. To test an unreleased change, pin the repo at a git ref in a scratch branch instead (`unity-devkit = { git = "…", rev = "<sha>" }` under `[tool.uv.sources]`) and drop the pin when the release lands.
|
|
40
|
+
|
|
41
|
+
## Development
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
uv run ruff check .
|
|
45
|
+
uv run ruff format --check .
|
|
46
|
+
uv run basedpyright
|
|
47
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "unity-devkit"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Unity project discovery, build, license, and CI tooling"
|
|
5
|
+
requires-python = ">=3.13"
|
|
6
|
+
dependencies = [
|
|
7
|
+
"bashrun>=0.1.0",
|
|
8
|
+
"typer>=0.17.4",
|
|
9
|
+
"pydantic>=2.11.7",
|
|
10
|
+
"pydantic-settings>=2.9.1",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
[dependency-groups]
|
|
14
|
+
dev = ["basedpyright>=1.39.10", "ruff>=0.14.11"]
|
|
15
|
+
|
|
16
|
+
[project.scripts]
|
|
17
|
+
activate-unity-license = "unity_devkit.license:activate_app"
|
|
18
|
+
build-unity = "unity_devkit.build_unity:app"
|
|
19
|
+
compile-unity = "unity_devkit.compile_unity:app"
|
|
20
|
+
install = "unity_devkit.install:app"
|
|
21
|
+
lock-unity = "unity_devkit.lock_unity:app"
|
|
22
|
+
test-unity = "unity_devkit.test_unity:app"
|
|
23
|
+
unity-license-tag = "unity_devkit.license_restore:tag_app"
|
|
24
|
+
unity-matrix = "unity_devkit.matrix:main"
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["hatchling"]
|
|
28
|
+
build-backend = "hatchling.build"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.wheel]
|
|
31
|
+
packages = ["src/unity_devkit"]
|
|
32
|
+
include = ["src/unity_devkit/py.typed", "src/unity_devkit/third-party/**"]
|
|
33
|
+
|
|
34
|
+
[tool.uv.sources]
|
|
35
|
+
|
|
36
|
+
[tool.basedpyright]
|
|
37
|
+
venvPath = "."
|
|
38
|
+
venv = ".venv"
|
|
39
|
+
typeCheckingMode = "strict"
|
|
40
|
+
include = ["src"]
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
target-version = "py313"
|
|
2
|
+
line-length = 120
|
|
3
|
+
preview = true
|
|
4
|
+
|
|
5
|
+
[lint]
|
|
6
|
+
select = ["ALL"]
|
|
7
|
+
ignore = [
|
|
8
|
+
# ── Permanent ─────────────────────────────────────────────────────────
|
|
9
|
+
# Type annotations — basedpyright strict mode handles this
|
|
10
|
+
"ANN",
|
|
11
|
+
# No docstrings, no copyright headers
|
|
12
|
+
"D",
|
|
13
|
+
"DOC",
|
|
14
|
+
"CPY",
|
|
15
|
+
# TODO/FIXME comment formatting
|
|
16
|
+
"TD",
|
|
17
|
+
"FIX",
|
|
18
|
+
# Exception message ergonomics — literal-indirection and custom-class churn without benefit
|
|
19
|
+
"EM101",
|
|
20
|
+
"EM102",
|
|
21
|
+
"TRY003",
|
|
22
|
+
# Class attribute names never conflict with builtins via self.x
|
|
23
|
+
"A003",
|
|
24
|
+
# Function-size counters — C901 already covers structural complexity
|
|
25
|
+
"PLR0911",
|
|
26
|
+
"PLR0912",
|
|
27
|
+
"PLR0913",
|
|
28
|
+
"PLR0914",
|
|
29
|
+
"PLR0915",
|
|
30
|
+
"PLR0917",
|
|
31
|
+
# Typer's Option/Argument in argument defaults is typer's standard API pattern
|
|
32
|
+
"B008",
|
|
33
|
+
# Boolean parameters read fine as keyword-only flags here
|
|
34
|
+
"FBT001",
|
|
35
|
+
"FBT002",
|
|
36
|
+
"FBT003",
|
|
37
|
+
# Relative imports are the intra-package convention
|
|
38
|
+
"TID252",
|
|
39
|
+
# Formatter-owned; enforced by `ruff format`
|
|
40
|
+
"COM812",
|
|
41
|
+
"I001",
|
|
42
|
+
# Magic values in comparisons are readable in this CLI
|
|
43
|
+
"PLR2004",
|
|
44
|
+
# The formatter owns wrapping; long string literals and URLs stay on one line
|
|
45
|
+
"E501",
|
|
46
|
+
# src-layout tests need no __init__.py
|
|
47
|
+
"INP001",
|
|
48
|
+
# Runtime-used typing imports stay at module level
|
|
49
|
+
"TC001",
|
|
50
|
+
"TC002",
|
|
51
|
+
"TC003",
|
|
52
|
+
# Small literal tuples read fine in membership tests
|
|
53
|
+
"PLR6201",
|
|
54
|
+
|
|
55
|
+
# ── Deferred to PLE-248 — Enforce the deferred ruff rules
|
|
56
|
+
# https://linear.app/plerionplatforms/issue/PLE-248
|
|
57
|
+
# Mirrors placeframe's root ruff.toml transitional Ticket-N blocks; lifting
|
|
58
|
+
# a rule here should happen alongside lifting it from placeframe's ruff.toml.
|
|
59
|
+
"TC006", # move import into TYPE_CHECKING block (quoted annotation) — Ticket 1
|
|
60
|
+
"UP015", # unnecessary open mode parameters — Ticket 1
|
|
61
|
+
"FURB101", # read-text can replace open+read — Ticket 2
|
|
62
|
+
"FURB103", # write-text can replace open+write — Ticket 2
|
|
63
|
+
"FURB113", # use list.extend instead of repeated append — Ticket 2
|
|
64
|
+
"PLW1514", # open/read_text without explicit encoding — Ticket 2
|
|
65
|
+
"PTH101", # os.chmod → Path.chmod — Ticket 2
|
|
66
|
+
"PTH112", # os.path.isdir → Path.is_dir — Ticket 2
|
|
67
|
+
"PTH118", # os.path.join → Path / — Ticket 2
|
|
68
|
+
"PTH123", # open() → Path.open() — Ticket 2
|
|
69
|
+
"RET504", # unnecessary assignment before return — Ticket 2
|
|
70
|
+
"RET505", # unnecessary else after return — Ticket 2
|
|
71
|
+
"RUF005", # consider spread operator instead of concatenation — Ticket 2
|
|
72
|
+
"SIM102", # collapsible if statements — Ticket 2
|
|
73
|
+
"SIM115", # use context manager for opening files — Ticket 2
|
|
74
|
+
"SIM117", # use single with statement for multiple context managers — Ticket 2
|
|
75
|
+
"B904", # raise ... from inside except — Ticket 8
|
|
76
|
+
"BLE001", # blind except Exception — Ticket 8
|
|
77
|
+
"TRY300", # try/except/return — move return into else — Ticket 8
|
|
78
|
+
"C901", # function too complex — Ticket 9
|
|
79
|
+
"PLC0415", # import not at top level — Ticket 9
|
|
80
|
+
"PLW0603", # global statement — Ticket 9
|
|
81
|
+
"PLW2901", # loop variable overwritten — Ticket 9
|
|
82
|
+
"PTH201", # do not pass "." explicitly to Path — Ticket 2
|
|
83
|
+
"S103", # bad-file-permissions (0o755 on executable) — Ticket 9
|
|
84
|
+
"S108", # hardcoded temp file / directory — Ticket 9
|
|
85
|
+
"S404", # suspicious subprocess import — Ticket 9
|
|
86
|
+
"S603", # subprocess call with non-literal — Ticket 9
|
|
87
|
+
"S607", # start-process-with-partial-path — Ticket 9
|
|
88
|
+
|
|
89
|
+
# ── Deferred to PLE-336 — Replace print() with structured logging
|
|
90
|
+
# https://linear.app/plerionplatforms/issue/PLE-336
|
|
91
|
+
"T201", # print found
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
[lint.flake8-builtins]
|
|
95
|
+
ignorelist = ["id", "map"]
|
|
File without changes
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
import typer
|
|
9
|
+
from pydantic_settings import BaseSettings
|
|
10
|
+
|
|
11
|
+
from .cache import restore, save
|
|
12
|
+
from .ci_step import ci_step
|
|
13
|
+
from .license_restore import restore_license
|
|
14
|
+
from .setup import configure_git, install_dotnet
|
|
15
|
+
from .setup_oras import install_oras
|
|
16
|
+
from .unity import prepare_unity_project, resolve_unity_build, run_unity_batchmode
|
|
17
|
+
from .git_tags import get_latest_tag_version
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Settings(BaseSettings):
|
|
21
|
+
github_workspace: str
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
settings = Settings.model_validate({})
|
|
25
|
+
|
|
26
|
+
app = typer.Typer(add_completion=False, pretty_exceptions_show_locals=False)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@app.command()
|
|
30
|
+
def main(
|
|
31
|
+
project: str = typer.Option(help="Project name"),
|
|
32
|
+
project_path: Path = typer.Option(help="Path to Unity project"),
|
|
33
|
+
platform: str = typer.Option(help="Target platform"),
|
|
34
|
+
cache_key: str = typer.Option(help="Cache key prefix"),
|
|
35
|
+
run_number: int = typer.Option(0, help="CI run number"),
|
|
36
|
+
branch: str = typer.Option("dev", help="Git branch name"),
|
|
37
|
+
registry: str = typer.Option(help="OCI registry path"),
|
|
38
|
+
build_env: str = typer.Option(
|
|
39
|
+
"", help="Newline-separated KEY=VALUE pairs injected into the Unity build process environment"
|
|
40
|
+
),
|
|
41
|
+
) -> None:
|
|
42
|
+
for line in build_env.splitlines():
|
|
43
|
+
entry = line.strip()
|
|
44
|
+
if not entry:
|
|
45
|
+
continue
|
|
46
|
+
key, separator, value = entry.partition("=")
|
|
47
|
+
if not separator:
|
|
48
|
+
raise SystemExit(f"Invalid --build-env entry (expected KEY=VALUE): {entry!r}")
|
|
49
|
+
os.environ[key.strip()] = value.strip()
|
|
50
|
+
|
|
51
|
+
with ci_step("Setup"):
|
|
52
|
+
configure_git(settings.github_workspace)
|
|
53
|
+
install_dotnet("8.0")
|
|
54
|
+
install_oras()
|
|
55
|
+
restore_license()
|
|
56
|
+
|
|
57
|
+
branch_slug = branch.replace("/", "-")
|
|
58
|
+
tag = f"{cache_key}-{platform}-{branch_slug}"
|
|
59
|
+
fallback_branch = "dev"
|
|
60
|
+
fallback_tags = [f"{cache_key}-{platform}-{fallback_branch}"] if branch_slug != fallback_branch else None
|
|
61
|
+
|
|
62
|
+
with ci_step("Restore library cache"):
|
|
63
|
+
restore(registry, "unity-library", tag, Path("."), fallback_tags=fallback_tags)
|
|
64
|
+
|
|
65
|
+
with ci_step("Prepare build"):
|
|
66
|
+
project_config, build_flag, execute_method = resolve_unity_build(project, platform)
|
|
67
|
+
unity_project_path = project_config.path
|
|
68
|
+
|
|
69
|
+
with ci_step("Prepare project"):
|
|
70
|
+
prepare_unity_project(unity_project_path)
|
|
71
|
+
|
|
72
|
+
with ci_step(f"Build {unity_project_path.name} [{platform}]"):
|
|
73
|
+
tag_prefix = project_config.tag_prefix
|
|
74
|
+
if tag_prefix:
|
|
75
|
+
version = get_latest_tag_version(f"{tag_prefix}-v") or "0.0.0"
|
|
76
|
+
full_version = f"{version}-dev+{run_number}" if branch != "main" else f"{version}+{run_number}"
|
|
77
|
+
version_file = unity_project_path / ".build-version.json"
|
|
78
|
+
version_file.write_text(json.dumps({"version": full_version, "runNumber": run_number}))
|
|
79
|
+
print(f"Wrote version {full_version} (bundleVersionCode={run_number}) to {version_file}")
|
|
80
|
+
|
|
81
|
+
run_unity_batchmode(unity_project_path, f"{build_flag} -executeMethod {execute_method}", nographics=False)
|
|
82
|
+
|
|
83
|
+
with ci_step("Save library cache"):
|
|
84
|
+
# PackageCache (~1.6 GiB) is redundant with the shared UPM cache at ~/.cache/Unity/upm/
|
|
85
|
+
package_cache = project_path / "Library" / "PackageCache"
|
|
86
|
+
if package_cache.exists():
|
|
87
|
+
shutil.rmtree(package_cache)
|
|
88
|
+
|
|
89
|
+
save(registry, "unity-library", tag, Path("."), [f"{project_path}/Library/"])
|
|
90
|
+
|
|
91
|
+
with ci_step("Collect build artifacts"):
|
|
92
|
+
build_directory = project_path / "Build"
|
|
93
|
+
if build_directory.is_dir():
|
|
94
|
+
artifact_directory = Path("/tmp/unity-builds")
|
|
95
|
+
artifact_directory.mkdir(parents=True, exist_ok=True)
|
|
96
|
+
if platform == "linux64":
|
|
97
|
+
shutil.copytree(build_directory, artifact_directory, dirs_exist_ok=True)
|
|
98
|
+
else:
|
|
99
|
+
for file in build_directory.rglob("*"):
|
|
100
|
+
if file.suffix in {".apk", ".exe"}:
|
|
101
|
+
shutil.copy2(file, artifact_directory / file.name)
|