|
| 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). |
0 commit comments