Skip to content

Commit ef8814b

Browse files
1 parent 7f8de51 commit ef8814b

File tree

9 files changed

+120
-453
lines changed

9 files changed

+120
-453
lines changed

.github/workflows/validate.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,47 @@
1-
# github-action-template
1+
# create-unity-project
22

3-
A GitHub Actions template repository for TypeScript based Actions.
3+
A GitHub Action to create a new Unity Project using a predefined template package.
44

55
## How to use
66

7+
### Requirements
8+
9+
> [!IMPORTANT]
10+
> This action requires that the Unity Editor is installed on the runner.
11+
>
12+
> You can use [`unity-setup`](https://github.com/RageAgainstThePixel/unity-setup) action to install Unity Editor before using this action.
13+
14+
- `UNITY_EDITOR_PATH` environment variable must be set to the path of the Unity Editor executable.
15+
16+
> [!IMPORTANT]
17+
> This action requires an active Unity license be available on the runner.
18+
>
19+
> You can use [`activate-unity-license`](https://github.com/RageAgainstThePixel/activate-unity-license) action to activate the Unity license before using this action.
20+
21+
- A license activation for the Unity Editor must also be completed before using this action.
22+
723
### workflow
824

925
```yaml
1026
steps:
11-
- uses: RageAgainstThePixel/github-action-template@v1
27+
- uses: RageAgainstThePixel/create-unity-project@v1
28+
with:
29+
project-name: Test Project
30+
project-directory: ./Unity Project
31+
template-name: com.unity.template.3d(-cross-platform)?
1232
```
1333
1434
### inputs
1535
1636
| name | description | required |
1737
| ---- | ----------- | -------- |
18-
| .... | ........... | ........ |
38+
| `project-name` | The name of the Unity project to create. | true |
39+
| `project-directory` | The directory where the Unity project will be created. | Defaults to the root of the workspace. |
40+
| `template-name` | The name of the template package to use for creating the Unity project. | Default: `com.unity.template.3d(-cross-platform)?` |
41+
42+
> [!NOTE]
43+
> `template-name` supports regex patterns, allowing you to match multiple template packages. For example, `com.unity.template.3d(-cross-platform)?` will match both `com.unity.template.3d` and `com.unity.template.3d-cross-platform`.
1944

2045
### outputs
46+
47+
- `project-path`: The path to the created Unity project. This is the absolute path to the project directory.

action.yml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1-
name: github-action-template
2-
description: 'A GitHub Actions template repository for TypeScript based Actions'
3-
# inputs:
4-
# outputs:
1+
name: create-unity-project
2+
branding:
3+
icon: cloud-lightning
4+
color: blue
5+
description: A GitHub Action to create a new Unity Project using a predefined template package.
6+
inputs:
7+
project-name:
8+
description: The name of the Unity project to create.
9+
required: true
10+
project-directory:
11+
description: The directory where the Unity project will be created. Defaults to the root of the workspace.
12+
required: false
13+
default: '${{ github.workspace }}'
14+
template-name:
15+
description: The name of the template package to use for creating the Unity project.
16+
required: false
17+
default: 'com.unity.template.3d(-cross-platform)?'
18+
outputs:
19+
project-path:
20+
description: The path to the created Unity project.
21+
value: '${{ inputs.project-directory }}/${{ inputs.project-name }}'
522
runs:
6-
using: 'node20'
7-
main: 'dist/index.js'
8-
#post: 'dist/index.js'
23+
using: composite
24+
steps:
25+
- name: Get Unity Template
26+
id: template
27+
shell: bash
28+
run: ${{ github.action_path }}/get-unity-template.sh "${{ inputs.template-name }}"
29+
- uses: RageAgainstThePixel/unity-action@v2
30+
name: Create Unity Project
31+
with:
32+
log-name: create-unity-project
33+
args: '-quit -nographics -batchmode -createProject "${{ inputs.project-directory }}/${{ inputs.project-name }}" -cloneFromTemplate "${{ steps.template.outputs.template-path }}"'

get-unity-template.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# This script is used to fetch the Unity template from the editor path in env variables.
3+
set -e
4+
5+
if [ -z "$UNITY_EDITOR_PATH" ]; then
6+
echo "UNITY_EDITOR_PATH is not set. Please set it to the path of your Unity editor."
7+
exit 1
8+
fi
9+
10+
PACKAGE="$1"
11+
12+
if [ -z "$PACKAGE" ]; then
13+
echo "Usage: $0 <package-name-or-regex>"
14+
echo "Example: $0 'com.unity.template.3d'"
15+
echo " $0 'com.unity.template.3d-cross-platform'"
16+
echo " $0 'com.unity.template.3d*' (regex supported)"
17+
echo " $0 'com.unity.template.3d(-cross-platform)?' (regex supported)"
18+
exit 1
19+
fi
20+
21+
EDITOR_ROOT=$(dirname "${UNITY_EDITOR_PATH}")
22+
EDITOR_ROOT=${EDITOR_ROOT//\\//\/}
23+
TEMPLATE_DIR="${EDITOR_ROOT}/Data/Resources/PackageManager/ProjectTemplates"
24+
OS_NAME=$(uname -s | tr '[:upper:]' '[:lower:]')
25+
26+
if [[ "${OS_NAME}" == "darwin" ]]; then
27+
TEMPLATE_DIR=$(dirname "${EDITOR_ROOT}")/Resources/PackageManager/ProjectTemplates
28+
fi
29+
30+
if [ ! -d "${TEMPLATE_DIR}" ]; then
31+
echo "Template directory not found: ${TEMPLATE_DIR}"
32+
exit 1
33+
fi
34+
35+
PACKAGES=$(find "${TEMPLATE_DIR}" -name "*.tgz" 2>/dev/null)
36+
37+
if [ -z "${PACKAGES}" ]; then
38+
echo "No templates found in ${TEMPLATE_DIR}"
39+
else
40+
echo "Available templates:"
41+
echo "${PACKAGES}" | while IFS= read -r pkg; do
42+
echo " - $(basename \""${pkg}"\")"
43+
done
44+
fi
45+
46+
MATCHES=$(find "${TEMPLATE_DIR}" -name "*.tgz" 2>/dev/null | grep -E "${PACKAGE}.*[0-9]+\.[0-9]+\.[0-9]+\.tgz")
47+
TEMPLATE_PATH=$(echo "${MATCHES}" | awk '{ print length, $0 }' | sort -nr | cut -d" " -f2- | head -n 1)
48+
49+
if [ -z "${TEMPLATE_PATH}" ]; then
50+
echo "${PACKAGE} path not found in ${TEMPLATE_DIR}!"
51+
exit 1
52+
fi
53+
54+
TEMPLATE_PATH=${TEMPLATE_PATH//\\//\/}
55+
56+
echo "TEMPLATE_PATH=${TEMPLATE_PATH}"
57+
echo "template-path=${TEMPLATE_PATH}" >> "${GITHUB_OUTPUT}"

0 commit comments

Comments
 (0)