Skip to content

Commit 09a77e5

Browse files
committed
Initial commit
0 parents  commit 09a77e5

8 files changed

Lines changed: 562 additions & 0 deletions

File tree

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

‎.github/CODEOWNERS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Unity owns this repository.
2+
# See https://docs.github.com/articles/about-code-owners
3+
* @Unity-Technologies/unity-cli

‎.github/workflows/test.yml‎

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
# Weekly, so a CDN or runner-image change is caught without a commit.
9+
schedule:
10+
- cron: '17 6 * * 1'
11+
12+
permissions:
13+
contents: read
14+
15+
concurrency:
16+
group: test-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
install:
21+
name: ${{ matrix.os }} · ${{ matrix.version }}
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
os:
26+
[
27+
ubuntu-latest,
28+
ubuntu-24.04-arm,
29+
macos-latest,
30+
macos-15-intel,
31+
windows-latest,
32+
windows-11-arm,
33+
]
34+
version: [latest, 1.0.1]
35+
runs-on: ${{ matrix.os }}
36+
steps:
37+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
38+
with:
39+
persist-credentials: false
40+
41+
- id: setup
42+
uses: ./
43+
with:
44+
version: ${{ matrix.version }}
45+
46+
- name: The installed CLI runs from PATH and matches the outputs
47+
shell: bash
48+
env:
49+
WANT: ${{ matrix.version }}
50+
GOT: ${{ steps.setup.outputs.version }}
51+
BIN: ${{ steps.setup.outputs.path }}
52+
run: |
53+
set -euo pipefail
54+
test -n "$GOT"
55+
if [ "$WANT" != latest ]; then test "$GOT" = "$WANT"; fi
56+
test "$(unity --version)" = "$GOT"
57+
test -f "$BIN"
58+
test "$UNITY_NON_INTERACTIVE" = 1
59+
60+
# Same job, second call: the binary is already there and must be reused.
61+
- id: again
62+
uses: ./
63+
with:
64+
version: ${{ steps.setup.outputs.version }}
65+
- shell: bash
66+
run: unity --version
67+
68+
# The oldest supported glibc, in a container image without jq or python3.
69+
container:
70+
runs-on: ubuntu-latest
71+
container: buildpack-deps:focal-curl
72+
steps:
73+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
74+
with:
75+
persist-credentials: false
76+
- uses: ./
77+
with:
78+
cache: 'false'
79+
- run: unity --version
80+
81+
# musl is unsupported: the action must refuse it, not install a binary
82+
# whose loader then fails.
83+
rejects-musl:
84+
runs-on: ubuntu-latest
85+
container: alpine:3.20
86+
steps:
87+
- run: apk add --no-cache bash curl
88+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
89+
with:
90+
persist-credentials: false
91+
- id: musl
92+
continue-on-error: true
93+
uses: ./
94+
with:
95+
cache: 'false'
96+
# A failed step alone proves little: a musl install also fails later, at
97+
# --version. Check that the refusal itself ran and nothing was installed.
98+
- name: The action refused musl
99+
env:
100+
OUTCOME: ${{ steps.musl.outcome }}
101+
shell: bash
102+
run: |
103+
set -euo pipefail
104+
test "$OUTCOME" = failure
105+
if command -v unity; then exit 1; fi
106+
if out="$(./setup.sh resolve 2>&1)"; then exit 1; fi
107+
printf '%s' "$out" | grep -q 'musl libc'
108+
109+
rejects-bad-input:
110+
runs-on: ubuntu-latest
111+
steps:
112+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
113+
with:
114+
persist-credentials: false
115+
- id: bad
116+
continue-on-error: true
117+
uses: ./
118+
with:
119+
version: 1.0.1/../../latest
120+
- name: The bad version failed the action
121+
env:
122+
OUTCOME: ${{ steps.bad.outcome }}
123+
run: test "$OUTCOME" = failure

‎CONTRIBUTING.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Contributing
2+
3+
This action is maintained by Unity and published here automatically. We don't accept pull requests, because the next publish overwrites any change made here directly.
4+
5+
- **Found a bug, or have an idea?** Post in the [Unity Discussions forum](https://discussions.unity.com/).
6+
- **Work at Unity?** The action is authored internally. Ask the Unity CLI team where to make your change.

‎LICENSE.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Setup Unity CLI © 2026 Unity Technologies
2+
3+
Licensed under the Unity Companion License for Unity-dependent projects (see https://unity3d.com/legal/licenses/unity_companion_license).
4+
5+
Unless expressly provided otherwise, the Software under this license is made available strictly on an "AS IS" BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.

‎README.md‎

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Setup Unity CLI
2+
3+
Installs the [Unity CLI](https://docs.unity.com/en-us/unity-cli) (`unity`) on a GitHub Actions runner and
4+
adds it to `PATH`.
5+
6+
```yaml
7+
steps:
8+
- uses: actions/checkout@v4
9+
- uses: Unity-Technologies/setup-unity-cli@v1
10+
- run: unity --version
11+
```
12+
13+
## Inputs
14+
15+
| Input | Default | Description |
16+
|---|---|---|
17+
| `version` | `latest` | `latest`, or an exact version such as `1.0.1`. Pin a version for reproducible builds. |
18+
| `channel` | `stable` | Release channel when `version` is `latest`: `stable` or `beta`. |
19+
| `cache` | `true` | Cache the downloaded binary between workflow runs. |
20+
| `non-interactive` | `true` | Sets `UNITY_NON_INTERACTIVE=1` for later steps, so no command waits on a prompt. |
21+
22+
## Outputs
23+
24+
| Output | Description |
25+
|---|---|
26+
| `version` | The installed Unity CLI version. |
27+
| `path` | Full path to the installed `unity` binary. |
28+
| `cache-hit` | `true` when the binary came from the cache. |
29+
30+
## Supported runners
31+
32+
GitHub-hosted and self-hosted runners on Linux, macOS and Windows, x64 and ARM64. Linux needs glibc 2.31 or
33+
newer (Ubuntu 20.04, Debian 11 and later); Alpine and other musl images are not supported. The runner needs
34+
`bash` and `curl`; Windows runners use the Git Bash that ships with them.
35+
36+
## Building and testing a Unity project
37+
38+
Sign-in uses a Unity Cloud service account read from the environment, so credentials never appear on a
39+
command line. Pass them only to the steps that need them, never to this action.
40+
41+
```yaml
42+
jobs:
43+
build:
44+
runs-on: ubuntu-latest
45+
env:
46+
UNITY_FORMAT: github # failures show up as annotations
47+
steps:
48+
- uses: actions/checkout@v4
49+
- uses: Unity-Technologies/setup-unity-cli@v1
50+
with:
51+
version: 1.0.1
52+
53+
- name: Install the Unity Editor
54+
env:
55+
UNITY_SERVICE_ACCOUNT_ID: ${{ secrets.UNITY_SERVICE_ACCOUNT_ID }}
56+
UNITY_SERVICE_ACCOUNT_SECRET: ${{ secrets.UNITY_SERVICE_ACCOUNT_SECRET }}
57+
run: unity install 6000.0.32f1 --yes --accept-eula
58+
59+
- name: Activate the Unity license
60+
env:
61+
UNITY_LICENSE_SERIAL: ${{ secrets.UNITY_LICENSE_SERIAL }}
62+
run: unity license activate
63+
64+
- name: Test
65+
env:
66+
UNITY_SERVICE_ACCOUNT_ID: ${{ secrets.UNITY_SERVICE_ACCOUNT_ID }}
67+
UNITY_SERVICE_ACCOUNT_SECRET: ${{ secrets.UNITY_SERVICE_ACCOUNT_SECRET }}
68+
run: unity test --report-format junit --output test-results.xml
69+
70+
- name: Build
71+
env:
72+
UNITY_SERVICE_ACCOUNT_ID: ${{ secrets.UNITY_SERVICE_ACCOUNT_ID }}
73+
UNITY_SERVICE_ACCOUNT_SECRET: ${{ secrets.UNITY_SERVICE_ACCOUNT_SECRET }}
74+
run: unity build --target StandaloneLinux64 --output build/
75+
76+
- name: Return the Unity license
77+
if: always()
78+
env:
79+
UNITY_SERVICE_ACCOUNT_ID: ${{ secrets.UNITY_SERVICE_ACCOUNT_ID }}
80+
UNITY_SERVICE_ACCOUNT_SECRET: ${{ secrets.UNITY_SERVICE_ACCOUNT_SECRET }}
81+
run: unity license return --yes
82+
```
83+
84+
`unity ci init` generates a complete workflow for your project, including Library caching, the Editor's Linux
85+
runtime libraries and test sharding.
86+
87+
## Security
88+
89+
- The binary is checked against the SHA-256 in the release manifest before it is installed, and again when
90+
it is restored from the cache. The manifest comes from the same CDN as the binary, so the check proves
91+
the download is intact, not who published it. Every request is HTTPS only, redirects included.
92+
- Inputs are validated against allowlists and passed to the script through environment variables.
93+
- The action takes no secrets.
94+
- Pin the action to a full commit SHA if your policy requires it.
95+
96+
## License
97+
98+
[Unity Companion License](LICENSE.md). Contributions: see [CONTRIBUTING.md](CONTRIBUTING.md).

‎action.yml‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Setup Unity CLI
2+
description: Install the Unity CLI (`unity`) on a GitHub Actions runner and add it to PATH.
3+
author: Unity Technologies
4+
branding:
5+
icon: terminal
6+
color: gray-dark
7+
8+
inputs:
9+
version:
10+
description: "'latest', or an exact version such as 1.0.1."
11+
required: false
12+
default: latest
13+
channel:
14+
description: "Release channel when version is 'latest': stable or beta."
15+
required: false
16+
default: stable
17+
cache:
18+
description: Cache the downloaded binary between workflow runs.
19+
required: false
20+
default: 'true'
21+
non-interactive:
22+
description: Set UNITY_NON_INTERACTIVE=1 for later steps, so no command waits on a prompt.
23+
required: false
24+
default: 'true'
25+
26+
outputs:
27+
version:
28+
description: The installed Unity CLI version.
29+
value: ${{ steps.resolve.outputs.version }}
30+
path:
31+
description: Full path to the installed `unity` binary.
32+
value: ${{ steps.install.outputs.path }}
33+
cache-hit:
34+
description: Whether the binary came from the cache.
35+
value: ${{ steps.restore.outputs.cache-hit == 'true' }}
36+
37+
runs:
38+
using: composite
39+
steps:
40+
# Inputs reach the script through env, never ${{ }} inside `run:`, so an
41+
# input value cannot inject shell.
42+
- name: Resolve the Unity CLI version
43+
id: resolve
44+
shell: bash
45+
env:
46+
INPUT_VERSION: ${{ inputs.version }}
47+
INPUT_CHANNEL: ${{ inputs.channel }}
48+
run: '"$GITHUB_ACTION_PATH/setup.sh" resolve'
49+
50+
# Keyed on the checksum, so a re-published binary never matches a stale entry.
51+
- name: Restore the Unity CLI from cache
52+
id: restore
53+
if: inputs.cache == 'true'
54+
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
55+
with:
56+
path: ${{ steps.resolve.outputs.dir }}
57+
key: unity-cli-${{ steps.resolve.outputs.platform }}-${{ steps.resolve.outputs.version }}-${{ steps.resolve.outputs.sha256 }}
58+
59+
- name: Install the Unity CLI
60+
id: install
61+
shell: bash
62+
env:
63+
RESOLVED_VERSION: ${{ steps.resolve.outputs.version }}
64+
RESOLVED_FILENAME: ${{ steps.resolve.outputs.filename }}
65+
RESOLVED_SHA256: ${{ steps.resolve.outputs.sha256 }}
66+
RESOLVED_DIR: ${{ steps.resolve.outputs.dir }}
67+
INPUT_NON_INTERACTIVE: ${{ inputs.non-interactive }}
68+
run: '"$GITHUB_ACTION_PATH/setup.sh" install'
69+
70+
# Saved straight away rather than at job end, so a later failing step still
71+
# leaves the next run a warm cache.
72+
- name: Save the Unity CLI to cache
73+
if: inputs.cache == 'true' && steps.restore.outputs.cache-hit != 'true'
74+
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
75+
with:
76+
path: ${{ steps.resolve.outputs.dir }}
77+
key: unity-cli-${{ steps.resolve.outputs.platform }}-${{ steps.resolve.outputs.version }}-${{ steps.resolve.outputs.sha256 }}

0 commit comments

Comments
 (0)