Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .github/workflows/validate.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore

This file was deleted.

35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
# github-action-template
# create-unity-project

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

## How to use

### Requirements

> [!IMPORTANT]
> This action requires that the Unity Editor is installed on the runner.
>
> You can use [`unity-setup`](https://github.com/RageAgainstThePixel/unity-setup) action to install Unity Editor before using this action.

- `UNITY_EDITOR_PATH` environment variable must be set to the path of the Unity Editor executable.

> [!IMPORTANT]
> This action requires an active Unity license be available on the runner.
>
> You can use [`activate-unity-license`](https://github.com/RageAgainstThePixel/activate-unity-license) action to activate the Unity license before using this action.

- A license activation for the Unity Editor must also be completed before using this action.

### workflow

```yaml
steps:
- uses: RageAgainstThePixel/github-action-template@v1
- uses: RageAgainstThePixel/create-unity-project@v1
with:
project-name: Test Project
project-directory: ./Unity Project
template-name: com.unity.template.3d(-cross-platform)?
```

### inputs

| name | description | required |
| ---- | ----------- | -------- |
| .... | ........... | ........ |
| `project-name` | The name of the Unity project to create. | true |
| `project-directory` | The directory where the Unity project will be created. | Defaults to the root of the workspace. |
| `template-name` | The name of the template package to use for creating the Unity project. | Default: `com.unity.template.3d(-cross-platform)?` |

> [!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`.

### outputs

- `project-path`: The path to the created Unity project. This is the absolute path to the project directory.
39 changes: 32 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
name: github-action-template
description: 'A GitHub Actions template repository for TypeScript based Actions'
# inputs:
# outputs:
name: create-unity-project
branding:
icon: cloud-lightning
color: blue
description: A GitHub Action to create a new Unity Project using a predefined template package.
inputs:
project-name:
description: The name of the Unity project to create.
required: true
project-directory:
description: The directory where the Unity project will be created. Defaults to the root of the workspace.
required: false
default: '${{ github.workspace }}'
template-name:
description: The name of the template package to use for creating the Unity project.
required: false
default: 'com.unity.template.3d(-cross-platform)?'
outputs:
project-path:
description: The path to the created Unity project.
value: '${{ inputs.project-directory }}/${{ inputs.project-name }}'
runs:
using: 'node20'
main: 'dist/index.js'
#post: 'dist/index.js'
using: composite
steps:
- name: Get Unity Template
id: template
shell: bash
run: ${{ github.action_path }}/get-unity-template.sh "${{ inputs.template-name }}"
- uses: RageAgainstThePixel/unity-action@v2
name: Create Unity Project
with:
log-name: create-unity-project
args: '-quit -nographics -batchmode -createProject "${{ inputs.project-directory }}/${{ inputs.project-name }}" -cloneFromTemplate "${{ steps.template.outputs.template-path }}"'
57 changes: 57 additions & 0 deletions get-unity-template.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
# This script is used to fetch the Unity template from the editor path in env variables.
set -e

if [ -z "$UNITY_EDITOR_PATH" ]; then
echo "UNITY_EDITOR_PATH is not set. Please set it to the path of your Unity editor."
exit 1
fi

PACKAGE="$1"

if [ -z "$PACKAGE" ]; then
echo "Usage: $0 <package-name-or-regex>"
echo "Example: $0 'com.unity.template.3d'"
echo " $0 'com.unity.template.3d-cross-platform'"
echo " $0 'com.unity.template.3d*' (regex supported)"
echo " $0 'com.unity.template.3d(-cross-platform)?' (regex supported)"
exit 1
fi

EDITOR_ROOT=$(dirname "${UNITY_EDITOR_PATH}")
EDITOR_ROOT=${EDITOR_ROOT//\\//\/}
TEMPLATE_DIR="${EDITOR_ROOT}/Data/Resources/PackageManager/ProjectTemplates"
OS_NAME=$(uname -s | tr '[:upper:]' '[:lower:]')

if [[ "${OS_NAME}" == "darwin" ]]; then
TEMPLATE_DIR=$(dirname "${EDITOR_ROOT}")/Resources/PackageManager/ProjectTemplates
fi

if [ ! -d "${TEMPLATE_DIR}" ]; then
echo "Template directory not found: ${TEMPLATE_DIR}"
exit 1
fi

PACKAGES=$(find "${TEMPLATE_DIR}" -name "*.tgz" 2>/dev/null)

if [ -z "${PACKAGES}" ]; then
echo "No templates found in ${TEMPLATE_DIR}"
else
echo "Available templates:"
echo "${PACKAGES}" | while IFS= read -r pkg; do
echo " - $(basename \""${pkg}"\")"
done
fi

MATCHES=$(find "${TEMPLATE_DIR}" -name "*.tgz" 2>/dev/null | grep -E "${PACKAGE}.*[0-9]+\.[0-9]+\.[0-9]+\.tgz")
TEMPLATE_PATH=$(echo "${MATCHES}" | awk '{ print length, $0 }' | sort -nr | cut -d" " -f2- | head -n 1)

if [ -z "${TEMPLATE_PATH}" ]; then
echo "${PACKAGE} path not found in ${TEMPLATE_DIR}!"
exit 1
fi

TEMPLATE_PATH=${TEMPLATE_PATH//\\//\/}

echo "TEMPLATE_PATH=${TEMPLATE_PATH}"
echo "template-path=${TEMPLATE_PATH}" >> "${GITHUB_OUTPUT}"
Loading