Skip to content

Commit d145d48

Browse files
1 parent 7f8de51 commit d145d48

File tree

9 files changed

+111
-453
lines changed

9 files changed

+111
-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: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
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] This action requires that the Unity Editor is installed on the runner.
10+
> You can use `unity-setup` action to install Unity Editor before using this action.
11+
> `UNITY_EDITOR_PATH` environment variable must be set to the path of the Unity Editor executable.
12+
13+
- `UNITY_EDITOR_PATH` environment variable must be set to the path of the Unity Editor executable.
14+
- A license activation for the Unity Editor must also be completed before using this action.
15+
716
### workflow
817

918
```yaml
1019
steps:
11-
- uses: RageAgainstThePixel/github-action-template@v1
20+
- uses: RageAgainstThePixel/create-unity-project@v1
21+
with:
22+
project-name: Test Project
23+
project-directory: ./Unity
24+
template-name: com.unity.template.3d(-cross-platform)?
1225
```
1326
1427
### inputs
1528
1629
| name | description | required |
1730
| ---- | ----------- | -------- |
18-
| .... | ........... | ........ |
31+
| project-name | The name of the Unity project to create. | true |
32+
| project-directory | The directory where the Unity project will be created. | Defaults to the root of the workspace. |
33+
| template-name | The name of the template package to use for creating the Unity project. | Default: 'com.unity.template.3d(-cross-platform)?' |
34+
35+
> ![NOTE] `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`.
1936

2037
### outputs
38+
39+
- `project-path`: The path to the created Unity project. This is the absolute path to the project directory.

action.yml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
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+
template-name:
14+
description: The name of the template package to use for creating the Unity project.
15+
required: false
16+
default: 'com.unity.template.3d(-cross-platform)?'
17+
outputs:
18+
project-path:
19+
description: The path to the created Unity project.
20+
value: '${{ inputs.project-directory }}/${{ inputs.project-name }}'
521
runs:
6-
using: 'node20'
7-
main: 'dist/index.js'
8-
#post: 'dist/index.js'
22+
using: composite
23+
steps:
24+
- name: Get Unity Template
25+
id: template
26+
shell: bash
27+
run: ./get-unity-template.sh "${{ inputs.template-name }}"
28+
- uses: RageAgainstThePixel/unity-action@v2
29+
name: Create Unity Project
30+
with:
31+
log-name: create-unity-project
32+
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)