Skip to content

Commit 4f33d38

Browse files
authored
Add new task UnityCreateProjectV1 (#283)
* Set up new create project ask * Add to extension manifest * Add to pipeline * Adjust test timeout
1 parent 795fe51 commit 4f33d38

File tree

12 files changed

+3597
-21
lines changed

12 files changed

+3597
-21
lines changed

.github/workflows/build-test-deploy.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,13 @@ jobs:
8383

8484
- name: Build UnityTestV1
8585
run: npm run build
86-
working-directory: Tasks/UnityTest/UnityTestV1
86+
working-directory: Tasks/UnityTest/UnityTestV1
87+
88+
# UnityCreateProject
89+
- name: Install UnityCreateProjectV1
90+
run: npm install
91+
working-directory: Tasks/UnityCreateProject/UnityCreateProjectV1
92+
93+
- name: Build UnityCreateProjectV1
94+
run: npm run build
95+
working-directory: Tasks/UnityCreateProject/UnityCreateProjectV1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.0]
9+
10+
Initial release
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# About Unity Create Project V1
2+
3+
Please visit [https://unitydevops.com/docs/unity-create-project-task](https://unitydevops.com/docs/unity-create-project-task) for task documentation.
2.54 KB
Loading

Tasks/UnityCreateProject/UnityCreateProjectV1/package-lock.json

Lines changed: 3337 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@dinomite-studios/unity-create-project-task",
3+
"version": "1.0.0",
4+
"description": "Azure Pipelines task to create an empty project at a given path.",
5+
"main": "unity-create-project.js",
6+
"scripts": {
7+
"build": "tsc",
8+
"test": "nyc mocha test/_suite.js",
9+
"upload": "tfx build tasks upload --task-path ./",
10+
"dev-delete": "tfx build tasks delete --task-id 874bd610-5219-45e4-a917-59e3a7ff74da",
11+
"dev-upload": "npm run build && npm run upload"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/Dinomite-Studios/unity-azure-pipelines-tasks"
16+
},
17+
"author": "Dinomite",
18+
"license": "MIT",
19+
"dependencies": {
20+
"@types/node": "^22.9.1",
21+
"@types/q": "^1.5.8",
22+
"@dinomite-studios/unity-azure-pipelines-tasks-lib": "^1.0.11",
23+
"azure-pipelines-task-lib": "^4.17.3"
24+
},
25+
"devDependencies": {
26+
"@types/mocha": "^10.0.10",
27+
"typescript": "^5.6.2",
28+
"mocha": "^11.0.1",
29+
"mocha-junit-reporter": "^2.2.1",
30+
"nyc": "^17.1.0"
31+
}
32+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"id": "874bd610-5219-45e4-a917-59e3a7ff74da",
3+
"name": "UnityCreateProjectTask",
4+
"friendlyName": "Unity Create Project",
5+
"description": "Create an empty project at a given path.",
6+
"helpMarkDown": "Use this task to create a new and empty project. This is e.g. useful for package development. [More Information](https://unitydevops.com/docs/unity-create-project-task)",
7+
"category": "Azure Pipelines",
8+
"visibility": [
9+
"Build"
10+
],
11+
"author": "Dinomite",
12+
"version": {
13+
"Major": 1,
14+
"Minor": 0,
15+
"Patch": 0
16+
},
17+
"releaseNotes": "[Full Changelog](https://github.com/Dinomite-Studios/unity-azure-pipelines-tasks/blob/master/Tasks/UnityCreateProject/UnityCreateProjectV1/CHANGELOG.md)",
18+
"minimumAgentVersion": "2.144.0",
19+
"instanceNameFormat": "Unity Create Project",
20+
"inputs": [
21+
{
22+
"name": "version",
23+
"type": "string",
24+
"label": "Version",
25+
"defaultValue": "",
26+
"required": true,
27+
"helpMarkDown": "The Unity editor version to create the project with, e.g. value: `2022.2.1f1`."
28+
},
29+
{
30+
"name": "path",
31+
"type": "filePath",
32+
"label": "Path",
33+
"defaultValue": "",
34+
"required": false,
35+
"helpMarkDown": "(Optional) Enter the path to create the Unity project at. If no value is entered, the root pipeline workspace is used."
36+
},
37+
{
38+
"name": "projectName",
39+
"type": "string",
40+
"label": "Project Name",
41+
"defaultValue": "New Project",
42+
"required": true,
43+
"helpMarkDown": "The name of the Unity project created."
44+
},
45+
{
46+
"name": "unityEditorsPathMode",
47+
"type": "pickList",
48+
"label": "Unity editors location",
49+
"defaultValue": "default",
50+
"helpMarkDown": "Define where to look for Unity installations on the agent.",
51+
"groupName": "general",
52+
"options": {
53+
"default": "Default (recommended)",
54+
"environmentVariable": "Use UNITYHUB_EDITORS_FOLDER_LOCATION environment variable on agent",
55+
"specify": "Specify path"
56+
}
57+
},
58+
{
59+
"name": "customUnityEditorsPath",
60+
"type": "string",
61+
"label": "Editors folder location",
62+
"defaultValue": "",
63+
"groupName": "general",
64+
"required": true,
65+
"visibleRule": "unityEditorsPathMode == specify",
66+
"helpMarkDown": "Specify where to look for Unity Editor versions on the agent."
67+
}
68+
],
69+
"outputVariables": [
70+
{
71+
"name": "editorLogFilePath",
72+
"description": "Specifies the location of the editor log file generated."
73+
}
74+
],
75+
"execution": {
76+
"Node10": {
77+
"target": "unity-create-project.js",
78+
"argumentFormat": ""
79+
},
80+
"Node20_1": {
81+
"target": "unity-create-project.js",
82+
"argumentFormat": ""
83+
}
84+
},
85+
"messages": {
86+
"successProjectCreated": "Unity project created!",
87+
"failCreateProject": "\nERROR: The Unity process failed with exit code"
88+
}
89+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"module": "commonjs",
5+
"strict": true,
6+
"esModuleInterop": true
7+
},
8+
"exclude": [
9+
"node_modules",
10+
"dist"
11+
]
12+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import path = require('path');
2+
import tl = require('azure-pipelines-task-lib/task');
3+
import { UnityPathTools, UnityToolRunner, Utilities } from '@dinomite-studios/unity-azure-pipelines-tasks-lib';
4+
5+
// Input variables
6+
const versionInputVariableName = 'version';
7+
const pathInputVariableName = 'path';
8+
const projectNameInputVariableName = 'projectName';
9+
const unityEditorsPathModeInputVariableName = 'unityEditorsPathMode';
10+
const customUnityEditorsPathInputVariableName = 'customUnityEditorsPath';
11+
12+
// Output variables.
13+
const editorLogFilePathOutputVariableName = 'editorLogFilePath';
14+
15+
async function run() {
16+
try {
17+
// Configure localization.
18+
tl.setResourcePath(path.join(__dirname, 'task.json'));
19+
20+
// Setup and read inputs.
21+
const projectPath = tl.getPathInput(pathInputVariableName) ?? '';
22+
const projectName = tl.getPathInput(projectNameInputVariableName) ?? 'New Project';
23+
const unityEditorsPath = UnityPathTools.getUnityEditorsPath(
24+
tl.getInput(unityEditorsPathModeInputVariableName, true)!,
25+
tl.getInput(customUnityEditorsPathInputVariableName));
26+
const unityVersion = {
27+
info: {
28+
isAlpha: false,
29+
isBeta: false,
30+
version: tl.getInput(versionInputVariableName, true)!,
31+
revision: undefined
32+
},
33+
error: undefined
34+
}
35+
36+
const unityExecutablePath = UnityPathTools.getUnityExecutableFullPath(unityEditorsPath, unityVersion.info!);
37+
38+
// Set output variable values.
39+
const logFilesDirectory = path.join(tl.getVariable('Agent.TempDirectory')!, 'Logs');
40+
const logFilePath = path.join(logFilesDirectory, `UnityLog_${Utilities.getLogFileNameTimeStamp()}.log`);
41+
tl.setVariable(editorLogFilePathOutputVariableName, logFilePath);
42+
43+
// Execute Unity command line.
44+
const unityCmd = tl.tool(unityExecutablePath)
45+
.arg('-batchmode')
46+
.arg('-createProject')
47+
.arg(path.join(projectPath, projectName))
48+
.arg('-logfile')
49+
.arg(logFilePath)
50+
.arg('-quit');
51+
52+
const result = await UnityToolRunner.run(unityCmd, logFilePath);
53+
54+
// Unity process has finished. Set task result.
55+
if (result === 0) {
56+
const buildSuccessLog = tl.loc('successProjectCreated');
57+
console.log(buildSuccessLog);
58+
tl.setResult(tl.TaskResult.Succeeded, buildSuccessLog);
59+
} else {
60+
const buildFailLog = `${tl.loc('failCreateProject')} ${result}`;
61+
console.log(buildFailLog);
62+
tl.setResult(tl.TaskResult.Failed, buildFailLog);
63+
}
64+
} catch (e) {
65+
if (e instanceof Error) {
66+
console.error(e.message);
67+
tl.setResult(tl.TaskResult.Failed, e.message);
68+
} else {
69+
console.error(e);
70+
tl.setResult(tl.TaskResult.Failed, `${e}`);
71+
}
72+
}
73+
}
74+
75+
run();

Tasks/UnityGetProjectVersion/UnityGetProjectVersionV1/test/_suite.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,26 @@ import assert from 'assert';
22
import * as mocktest from 'azure-pipelines-task-lib/mock-test';
33
import * as path from 'path';
44

5-
describe("Unity Get Project Version V1 tests", () => {
5+
describe("Unity Get Project Version V1 tests", function () {
6+
this.timeout(5000);
7+
68
it("Error determining the project version from file", (done) => {
79
const testPath = path.join(__dirname, 'errorDeterminingTheProjectVersionFromFile.js');
8-
const runner: mocktest.MockTestRunner = new mocktest.MockTestRunner();
10+
const runner: mocktest.MockTestRunner = new mocktest.MockTestRunner(testPath);
911

10-
runner.LoadAsync(testPath)
12+
runner.runAsync()
1113
.then(() => {
12-
runner.runAsync()
13-
.then(() => {
14-
assert.strictEqual(runner.failed, true);
15-
assert.strictEqual(runner.invokedToolCount, 0);
16-
assert(runner.stdOutContained('loc_mock_failGetUnityEditorVersion | Unknown project version format encountered'));
14+
assert.strictEqual(runner.failed, true);
15+
assert.strictEqual(runner.invokedToolCount, 0);
16+
assert(runner.stdOutContained('loc_mock_failGetUnityEditorVersion | Unknown project version format encountered'));
1717

18-
done();
19-
});
18+
done();
2019
});
2120
});
2221

2322
it("Success (alpha) determining the project version from file", (done) => {
24-
let testPath = path.join(__dirname, 'successAlphaDeterminingTheProjectVersionFromFile.js');
25-
26-
let runner: mocktest.MockTestRunner = new mocktest.MockTestRunner(testPath);
23+
const testPath = path.join(__dirname, 'successAlphaDeterminingTheProjectVersionFromFile.js');
24+
const runner: mocktest.MockTestRunner = new mocktest.MockTestRunner(testPath);
2725

2826
runner.runAsync()
2927
.then(() => {
@@ -38,9 +36,8 @@ describe("Unity Get Project Version V1 tests", () => {
3836
});
3937

4038
it("Success (beta) determining the project version from file", (done) => {
41-
let testPath = path.join(__dirname, 'successBetaDeterminingTheProjectVersionFromFile.js');
42-
43-
let runner: mocktest.MockTestRunner = new mocktest.MockTestRunner(testPath);
39+
const testPath = path.join(__dirname, 'successBetaDeterminingTheProjectVersionFromFile.js');
40+
const runner: mocktest.MockTestRunner = new mocktest.MockTestRunner(testPath);
4441

4542
runner.runAsync()
4643
.then(() => {
@@ -55,9 +52,8 @@ describe("Unity Get Project Version V1 tests", () => {
5552
});
5653

5754
it("Success (stable) determining the project version from file", (done) => {
58-
let testPath = path.join(__dirname, 'successStableDeterminingTheProjectVersionFromFile.js');
59-
60-
let runner: mocktest.MockTestRunner = new mocktest.MockTestRunner(testPath);
55+
const testPath = path.join(__dirname, 'successStableDeterminingTheProjectVersionFromFile.js');
56+
const runner: mocktest.MockTestRunner = new mocktest.MockTestRunner(testPath);
6157

6258
runner.runAsync()
6359
.then(() => {

0 commit comments

Comments
 (0)