Skip to content

Commit a8fbf54

Browse files
1 parent c870065 commit a8fbf54

File tree

7 files changed

+157
-1
lines changed

7 files changed

+157
-1
lines changed

.gitattributes

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

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @buildalon/buildalon
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Update Action Release Tags
2+
on:
3+
push:
4+
tags: ['*']
5+
workflow_dispatch:
6+
jobs:
7+
update-release-tags:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
- uses: RageAgainstThePixel/update-action-release-tags@v1

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Buildalon
3+
Copyright (c) 2025 Virtual Maker Corporation
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,47 @@
11
# create-unity-project
2+
23
A GitHub Action to create a new Unity Project using a predefined template package.
4+
5+
## How to use
6+
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/buildalon/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/buildalon/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+
23+
### workflow
24+
25+
```yaml
26+
steps:
27+
- uses: buildalon/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)?
32+
```
33+
34+
### inputs
35+
36+
| name | description | required |
37+
| ---- | ----------- | -------- |
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`.
44+
45+
### 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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Buildalon create unity project from hub template
2+
branding:
3+
icon: cloud-lightning
4+
color: red
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 }}'
22+
runs:
23+
using: composite
24+
steps:
25+
- name: Get Unity Template
26+
id: template
27+
shell: bash
28+
env:
29+
ACTION_PATH: ${{ github.action_path }}
30+
TEMPLATE_NAME: ${{ inputs.template-name }}
31+
run: '"${ACTION_PATH}/get-unity-template.sh" "${TEMPLATE_NAME}"'
32+
- uses: buildalon/unity-action@v2
33+
name: Create Unity Project
34+
with:
35+
log-name: create-unity-project
36+
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)