mirror of
https://github.com/game-ci/unity-test-runner.git
synced 2026-02-04 02:43:19 +08:00
Compare commits
12 Commits
v1.7
...
v2.0-alpha
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1be8325cd | ||
|
|
26807aaf05 | ||
|
|
a9d07b742d | ||
|
|
0c3e710069 | ||
|
|
a067c3d5ab | ||
|
|
3fca186a7b | ||
|
|
a8b9742ecd | ||
|
|
31cd755121 | ||
|
|
679222c549 | ||
|
|
29899d84e8 | ||
|
|
7d26e264b9 | ||
|
|
bac0f97d2f |
6
.github/workflows/main.yml
vendored
6
.github/workflows/main.yml
vendored
@@ -12,14 +12,14 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-node@v1.1.2
|
- uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: 12.x
|
node-version: 12.x
|
||||||
- run: yarn
|
- run: yarn
|
||||||
- run: yarn lint
|
- run: yarn lint
|
||||||
- run: yarn test
|
- run: yarn test
|
||||||
- run: yarn build || { echo "build command should always succeed" ; exit 61; }
|
- run: yarn build || { echo "build command should always succeed" ; exit 61; }
|
||||||
- run: yarn build --quiet && git diff --quiet action || { echo "action should be auto generated" ; exit 62; }
|
- run: yarn build --quiet && git diff --quiet action || { echo "ERROR - index.js is different from repository version. Forgot to run `yarn build`?" ; exit 62; }
|
||||||
|
|
||||||
testAllModesLikeInTheReadme:
|
testAllModesLikeInTheReadme:
|
||||||
name: Test in ${{ matrix.testMode }} on version ${{ matrix.unityVersion }}
|
name: Test in ${{ matrix.testMode }} on version ${{ matrix.unityVersion }}
|
||||||
@@ -38,7 +38,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
lfs: true
|
lfs: true
|
||||||
- uses: actions/cache@v1.1.0
|
- uses: actions/cache@v2
|
||||||
with:
|
with:
|
||||||
path: ${{ matrix.projectPath }}/Library
|
path: ${{ matrix.projectPath }}/Library
|
||||||
key: Library-${{ matrix.projectPath }}
|
key: Library-${{ matrix.projectPath }}
|
||||||
|
|||||||
@@ -2,5 +2,6 @@
|
|||||||
"semi": true,
|
"semi": true,
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "all",
|
"trailingComma": "all",
|
||||||
"printWidth": 100
|
"printWidth": 100,
|
||||||
|
"arrowParens": "avoid"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ You have [Node](https://nodejs.org/) installed at v12.2.0+ and [Yarn](https://ya
|
|||||||
Please note that commit hooks will run automatically to perform some tasks;
|
Please note that commit hooks will run automatically to perform some tasks;
|
||||||
|
|
||||||
- format your code
|
- format your code
|
||||||
- run tests
|
- run tests & lint - `yarn lint && yarn test`
|
||||||
- build distributable files
|
- build distributable files - `yarn build`
|
||||||
|
|
||||||
#### License
|
#### License
|
||||||
|
|
||||||
|
|||||||
25
README.md
25
README.md
@@ -1,15 +1,12 @@
|
|||||||
<div align="center">
|
# Unity - Test runner
|
||||||
<a href="https://github.com/marketplace/actions/unity-test-runner">
|
|
||||||
<img width="800" src="media/UnityTestRunner-Logo.png" alt="Unity Test Runner">
|
(Not affiliated with Unity Technologies)
|
||||||
</a>
|
|
||||||
<br />
|
|
||||||
<br />
|
|
||||||
|
|
||||||
GitHub Action to
|
GitHub Action to
|
||||||
[run tests](https://github.com/marketplace/actions/unity-test-runner)
|
[run tests](https://github.com/marketplace/actions/unity-test-runner)
|
||||||
for any Unity project.
|
for any Unity project.
|
||||||
|
|
||||||
Part of the <a href="https://unity-ci.com"><img height="30" src="media/UnityCI-ReferenceLogo.png" alt="Unity CI"></a> open source project.
|
Part of the <a href="https://game.ci">GameCI</a> open source project.
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
@@ -17,30 +14,28 @@ Part of the <a href="https://unity-ci.com"><img height="30" src="media/UnityCI-R
|
|||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
Find the
|
Find the
|
||||||
[docs](https://unity-ci.com/docs/github)
|
[docs](https://game.ci/docs)
|
||||||
on the Unity CI
|
on the GameCI
|
||||||
[website](https://unity-ci.com/).
|
[website](https://game.ci/).
|
||||||
|
|
||||||
## Related actions
|
## Related actions
|
||||||
|
|
||||||
Visit the
|
Visit the
|
||||||
<a href="https://github.com/webbertakken/unity-actions"><img height="30" src="media/UnityActions-ReferenceLogo.png" alt="Unity Actions"></a>
|
GameCI <a href="https://github.com/game-ci/unity-actions">Unity Actions</a>
|
||||||
status repository for related Actions.
|
status repository for related Actions.
|
||||||
|
|
||||||
## Community
|
## Community
|
||||||
|
|
||||||
Feel free to join us on
|
Feel free to join us on
|
||||||
<a href="http://unity-ci.com/discord"><img height="30" src="media/Discord-Logo.svg" alt="Discord" /></a>
|
<a href="http://game.ci/discord"><img height="30" src="media/Discord-Logo.svg" alt="Discord" /></a>
|
||||||
and engage with the community.
|
and engage with the community.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
To help out sharpen the documentation, please find the docs [repository](https://github.com/Unity-CI/Website).
|
To help improve the documentation, please find the docs [repository](https://github.com/game-ci/documentation).
|
||||||
|
|
||||||
To contribute to this project, kindly read the [contribution guide](./CONTRIBUTING.md).
|
To contribute to this project, kindly read the [contribution guide](./CONTRIBUTING.md).
|
||||||
|
|
||||||
|
|||||||
26
action.yml
26
action.yml
@@ -4,8 +4,30 @@ description: 'Run tests for any Unity project.'
|
|||||||
inputs:
|
inputs:
|
||||||
unityVersion:
|
unityVersion:
|
||||||
required: false
|
required: false
|
||||||
default: '2019.2.11f1'
|
default: 'auto'
|
||||||
description: 'Version of unity to use for testing the project.'
|
description: 'Version of unity to use for testing the project. Use "auto" to get from your ProjectSettings/ProjectVersion.txt'
|
||||||
|
customImage:
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
description: 'Specific docker image that should be used for testing the project'
|
||||||
|
projectPath:
|
||||||
|
required: false
|
||||||
|
description: 'Path to the Unity project to be tested.'
|
||||||
|
testMode:
|
||||||
|
required: false
|
||||||
|
default: 'all'
|
||||||
|
description: 'The type of tests to be run by the test runner.'
|
||||||
|
artifactsPath:
|
||||||
|
required: false
|
||||||
|
default: 'artifacts'
|
||||||
|
description: 'Path where test artifacts should be stored.'
|
||||||
|
useNetworkHost:
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
description: 'Initialises Docker using the hosts network.'
|
||||||
|
customParameters:
|
||||||
|
required: false
|
||||||
|
description: 'Extra parameters to configure the Unity editor run.'
|
||||||
outputs:
|
outputs:
|
||||||
artifactsPath:
|
artifactsPath:
|
||||||
description: 'Path where the artifacts are stored'
|
description: 'Path where the artifacts are stored'
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -24,13 +24,12 @@ if [[ -n "$UNITY_LICENSE" ]] || [[ -n "$UNITY_LICENSE_FILE" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Activate license
|
# Activate license
|
||||||
ACTIVATION_OUTPUT=$(xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
ACTIVATION_OUTPUT=$(unity-editor \
|
||||||
/opt/Unity/Editor/Unity \
|
-batchmode \
|
||||||
-batchmode \
|
-nographics \
|
||||||
-nographics \
|
-logFile /dev/stdout \
|
||||||
-logFile /dev/stdout \
|
-quit \
|
||||||
-quit \
|
-manualLicenseFile $FILE_PATH)
|
||||||
-manualLicenseFile $FILE_PATH)
|
|
||||||
|
|
||||||
# Store the exit code from the verify command
|
# Store the exit code from the verify command
|
||||||
UNITY_EXIT_CODE=$?
|
UNITY_EXIT_CODE=$?
|
||||||
@@ -63,15 +62,14 @@ elif [[ -n "$UNITY_SERIAL" && -n "$UNITY_EMAIL" && -n "$UNITY_PASSWORD" ]]; then
|
|||||||
echo "Requesting activation (professional license)"
|
echo "Requesting activation (professional license)"
|
||||||
|
|
||||||
# Activate license
|
# Activate license
|
||||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
unity-editor \
|
||||||
/opt/Unity/Editor/Unity \
|
-batchmode \
|
||||||
-batchmode \
|
-nographics \
|
||||||
-nographics \
|
-logFile /dev/stdout \
|
||||||
-logFile /dev/stdout \
|
-quit \
|
||||||
-quit \
|
-serial "$UNITY_SERIAL" \
|
||||||
-serial "$UNITY_SERIAL" \
|
-username "$UNITY_EMAIL" \
|
||||||
-username "$UNITY_EMAIL" \
|
-password "$UNITY_PASSWORD"
|
||||||
-password "$UNITY_PASSWORD"
|
|
||||||
|
|
||||||
# Store the exit code from the verify command
|
# Store the exit code from the verify command
|
||||||
UNITY_EXIT_CODE=$?
|
UNITY_EXIT_CODE=$?
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ if [[ -n "$UNITY_SERIAL" ]]; then
|
|||||||
#
|
#
|
||||||
# This will return the license that is currently in use.
|
# This will return the license that is currently in use.
|
||||||
#
|
#
|
||||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
unity-editor \
|
||||||
/opt/Unity/Editor/Unity \
|
-batchmode \
|
||||||
-batchmode \
|
-nographics \
|
||||||
-nographics \
|
-logFile /dev/stdout \
|
||||||
-logFile /dev/stdout \
|
-quit \
|
||||||
-quit \
|
-returnlicense
|
||||||
-returnlicense
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -74,19 +74,18 @@ if [ $EDIT_MODE = true ]; then
|
|||||||
echo "# Testing in EditMode #"
|
echo "# Testing in EditMode #"
|
||||||
echo "###########################"
|
echo "###########################"
|
||||||
echo ""
|
echo ""
|
||||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
unity-editor \
|
||||||
/opt/Unity/Editor/Unity \
|
-batchmode \
|
||||||
-batchmode \
|
-logFile "$FULL_ARTIFACTS_PATH/editmode.log" \
|
||||||
-logFile "$FULL_ARTIFACTS_PATH/editmode.log" \
|
-projectPath "$UNITY_PROJECT_PATH" \
|
||||||
-projectPath "$UNITY_PROJECT_PATH" \
|
-runTests \
|
||||||
-runTests \
|
-testPlatform editmode \
|
||||||
-testPlatform editmode \
|
-testResults "$FULL_ARTIFACTS_PATH/editmode-results.xml" \
|
||||||
-testResults "$FULL_ARTIFACTS_PATH/editmode-results.xml" \
|
$CUSTOM_PARAMETERS
|
||||||
$CUSTOM_PARAMETERS
|
|
||||||
|
|
||||||
# Catch exit code
|
# Catch exit code
|
||||||
EDIT_MODE_EXIT_CODE=$?
|
EDIT_MODE_EXIT_CODE=$?
|
||||||
|
|
||||||
# Print unity log output
|
# Print unity log output
|
||||||
cat "$FULL_ARTIFACTS_PATH/editmode.log"
|
cat "$FULL_ARTIFACTS_PATH/editmode.log"
|
||||||
|
|
||||||
@@ -112,16 +111,15 @@ if [ $PLAY_MODE = true ]; then
|
|||||||
echo "# Testing in PlayMode #"
|
echo "# Testing in PlayMode #"
|
||||||
echo "###########################"
|
echo "###########################"
|
||||||
echo ""
|
echo ""
|
||||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
unity-editor \
|
||||||
/opt/Unity/Editor/Unity \
|
-batchmode \
|
||||||
-batchmode \
|
-logFile "$FULL_ARTIFACTS_PATH/playmode.log" \
|
||||||
-logFile "$FULL_ARTIFACTS_PATH/playmode.log" \
|
-projectPath "$UNITY_PROJECT_PATH" \
|
||||||
-projectPath "$UNITY_PROJECT_PATH" \
|
-runTests \
|
||||||
-runTests \
|
-testPlatform playmode \
|
||||||
-testPlatform playmode \
|
-testResults "$FULL_ARTIFACTS_PATH/playmode-results.xml" \
|
||||||
-testResults "$FULL_ARTIFACTS_PATH/playmode-results.xml" \
|
$CUSTOM_PARAMETERS
|
||||||
$CUSTOM_PARAMETERS
|
|
||||||
|
|
||||||
# Catch exit code
|
# Catch exit code
|
||||||
PLAY_MODE_EXIT_CODE=$?
|
PLAY_MODE_EXIT_CODE=$?
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 71 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 48 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 74 KiB |
42
package.json
42
package.json
@@ -13,30 +13,30 @@
|
|||||||
"test": "jest"
|
"test": "jest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.1",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/exec": "1.0.3",
|
"@actions/exec": "1.0.4",
|
||||||
"@actions/github": "^2.1.1"
|
"@actions/github": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "7.8.4",
|
"@babel/cli": "7.12.10",
|
||||||
"@babel/core": "7.8.7",
|
"@babel/core": "7.12.10",
|
||||||
"@babel/preset-env": "7.8.7",
|
"@babel/preset-env": "7.12.11",
|
||||||
"@zeit/ncc": "0.21.1",
|
"@zeit/ncc": "0.22.3",
|
||||||
"babel-eslint": "10.1.0",
|
"babel-eslint": "10.1.0",
|
||||||
"eslint": "6.8.0",
|
"eslint": "7.17.0",
|
||||||
"eslint-config-airbnb": "18.0.1",
|
"eslint-config-airbnb": "18.2.1",
|
||||||
"eslint-config-prettier": "6.10.0",
|
"eslint-config-prettier": "7.1.0",
|
||||||
"eslint-plugin-flowtype": "4.6.0",
|
"eslint-plugin-flowtype": "5.2.0",
|
||||||
"eslint-plugin-import": "2.20.1",
|
"eslint-plugin-import": "2.22.1",
|
||||||
"eslint-plugin-jsx-a11y": "6.2.3",
|
"eslint-plugin-jsx-a11y": "6.4.1",
|
||||||
"eslint-plugin-prettier": "3.1.2",
|
"eslint-plugin-prettier": "3.3.1",
|
||||||
"eslint-plugin-react": "7.19.0",
|
"eslint-plugin-react": "7.22.0",
|
||||||
"eslint-plugin-unicorn": "16.1.1",
|
"eslint-plugin-unicorn": "25.0.1",
|
||||||
"husky": "4.2.3",
|
"husky": "4.3.7",
|
||||||
"jest": "25.1.0",
|
"jest": "26.6.3",
|
||||||
"lint-staged": "10.0.8",
|
"lint-staged": "10.5.3",
|
||||||
"lodash-es": "4.17.15",
|
"lodash-es": "4.17.20",
|
||||||
"prettier": "1.19.1"
|
"prettier": "2.2.1"
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ async function action() {
|
|||||||
const { dockerfile, workspace, actionFolder } = Action;
|
const { dockerfile, workspace, actionFolder } = Action;
|
||||||
const {
|
const {
|
||||||
unityVersion,
|
unityVersion,
|
||||||
|
customImage,
|
||||||
projectPath,
|
projectPath,
|
||||||
testMode,
|
testMode,
|
||||||
artifactsPath,
|
artifactsPath,
|
||||||
useHostNetwork,
|
useHostNetwork,
|
||||||
customParameters,
|
customParameters,
|
||||||
} = Input.getFromUser();
|
} = Input.getFromUser();
|
||||||
const baseImage = ImageTag.createForBase(unityVersion);
|
const baseImage = ImageTag.createForBase({ version: unityVersion, customImage });
|
||||||
|
|
||||||
// Build docker image
|
// Build docker image
|
||||||
const actionImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
|
const actionImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Docker {
|
|||||||
--build-arg IMAGE=${baseImage} \
|
--build-arg IMAGE=${baseImage} \
|
||||||
--tag ${tag}`;
|
--tag ${tag}`;
|
||||||
|
|
||||||
await exec(command, null, { silent });
|
await exec(command, undefined, { silent });
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ class Docker {
|
|||||||
${useHostNetwork ? '--net=host' : ''} \
|
${useHostNetwork ? '--net=host' : ''} \
|
||||||
${image}`;
|
${image}`;
|
||||||
|
|
||||||
await exec(command, null, { silent });
|
await exec(command, undefined, { silent });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,20 @@ describe('Docker', () => {
|
|||||||
it('builds', async () => {
|
it('builds', async () => {
|
||||||
const path = Action.actionFolder;
|
const path = Action.actionFolder;
|
||||||
const dockerfile = `${path}/Dockerfile`;
|
const dockerfile = `${path}/Dockerfile`;
|
||||||
const baseImage = new ImageTag({
|
const image = new ImageTag({
|
||||||
repository: '',
|
repository: '',
|
||||||
name: 'alpine',
|
name: 'alpine',
|
||||||
version: '3',
|
version: '3',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const baseImage = {
|
||||||
|
toString: () => image.toString().slice(0, image.toString().lastIndexOf('-base-0')),
|
||||||
|
version: image.version,
|
||||||
|
};
|
||||||
|
|
||||||
const tag = await Docker.build({ path, dockerfile, baseImage }, true);
|
const tag = await Docker.build({ path, dockerfile, baseImage }, true);
|
||||||
|
|
||||||
expect(tag).toBeInstanceOf(ImageTag);
|
expect(tag).toBeInstanceOf(ImageTag);
|
||||||
expect(tag.toString()).toStrictEqual('unity-action:3');
|
expect(tag.toString()).toStrictEqual('unity-action:3-base-0');
|
||||||
}, 240000);
|
}, 240000);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { trimStart } from 'lodash-es';
|
import { trimStart } from 'lodash-es';
|
||||||
|
|
||||||
class ImageTag {
|
class ImageTag {
|
||||||
static createForBase(version) {
|
static createForBase({ version, customImage }) {
|
||||||
const repository = 'gableroux';
|
const repository = 'unityci';
|
||||||
const name = 'unity3d';
|
const name = 'editor';
|
||||||
return new this({ repository, name, version });
|
return new this({ repository, name, version, customImage });
|
||||||
}
|
}
|
||||||
|
|
||||||
static createForAction(version) {
|
static createForAction(version) {
|
||||||
@@ -13,12 +13,12 @@ class ImageTag {
|
|||||||
return new this({ repository, name, version });
|
return new this({ repository, name, version });
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor({ repository = '', name, version }) {
|
constructor({ repository = '', name, version, customImage }) {
|
||||||
if (!ImageTag.versionPattern.test(version)) {
|
if (!ImageTag.versionPattern.test(version)) {
|
||||||
throw new Error(`Invalid version "${version}".`);
|
throw new Error(`Invalid version "${version}".`);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(this, { repository, name, version });
|
Object.assign(this, { repository, name, version, customImage });
|
||||||
}
|
}
|
||||||
|
|
||||||
static get versionPattern() {
|
static get versionPattern() {
|
||||||
@@ -34,7 +34,11 @@ class ImageTag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString() {
|
||||||
return `${this.image}:${this.tag}`;
|
if (this.customImage && this.customImage !== '') {
|
||||||
|
return this.customImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${this.image}:${this.tag}-base-0`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import ImageTag from './image-tag';
|
import ImageTag from './image-tag';
|
||||||
|
|
||||||
describe('UnityImageVersion', () => {
|
describe('ImageTag', () => {
|
||||||
describe('constructor', () => {
|
describe('constructor', () => {
|
||||||
const some = {
|
const some = {
|
||||||
name: 'someName',
|
name: 'someName',
|
||||||
@@ -23,16 +23,25 @@ describe('UnityImageVersion', () => {
|
|||||||
expect(() => new ImageTag({ version })).not.toThrow();
|
expect(() => new ImageTag({ version })).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
test.each(['some version', '', 1, null])('throws for incorrect versions %p', version => {
|
test.each(['some version', '', 1, undefined])('throws for incorrect versions %p', version => {
|
||||||
expect(() => new ImageTag({ version })).toThrow();
|
expect(() => new ImageTag({ version })).toThrow();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('toString', () => {
|
describe('toString', () => {
|
||||||
it('returns the correct version', () => {
|
it('returns the correct version', () => {
|
||||||
const image = ImageTag.createForBase('2099.1.1111');
|
const image = ImageTag.createForBase({ version: '2099.1.1111' });
|
||||||
|
|
||||||
expect(image.toString()).toStrictEqual(`gableroux/unity3d:2099.1.1111`);
|
expect(image.toString()).toStrictEqual(`unityci/editor:2099.1.1111-base-0`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns customImage if given', () => {
|
||||||
|
const image = ImageTag.createForBase({
|
||||||
|
version: '2099.1.1111',
|
||||||
|
customImage: 'unityci/editor:2099.1.1111-base-0',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(image.toString()).toStrictEqual(image.customImage);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { getInput } from '@actions/core';
|
import { getInput } from '@actions/core';
|
||||||
import { includes } from 'lodash-es';
|
import { includes } from 'lodash-es';
|
||||||
|
import UnityVersionParser from './unity-version-parser';
|
||||||
|
|
||||||
class Input {
|
class Input {
|
||||||
static get testModes() {
|
static get testModes() {
|
||||||
@@ -7,14 +8,15 @@ class Input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static isValidFolderName(folderName) {
|
static isValidFolderName(folderName) {
|
||||||
const validFolderName = new RegExp(/^(\.|\.\/)?(\.?\w+([-_]?\w+)*\/?)*$/);
|
const validFolderName = new RegExp(/^(\.|\.\/)?(\.?\w+([_-]?\w+)*\/?)*$/);
|
||||||
|
|
||||||
return validFolderName.test(folderName);
|
return validFolderName.test(folderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getFromUser() {
|
static getFromUser() {
|
||||||
// Input variables specified in workflow using "with" prop.
|
// Input variables specified in workflow using "with" prop.
|
||||||
const unityVersion = getInput('unityVersion') || '2019.2.11f1';
|
const rawUnityVersion = getInput('unityVersion') || 'auto';
|
||||||
|
const customImage = getInput('customImage') || '';
|
||||||
const testMode = getInput('testMode') || 'all';
|
const testMode = getInput('testMode') || 'all';
|
||||||
const rawProjectPath = getInput('projectPath') || '.';
|
const rawProjectPath = getInput('projectPath') || '.';
|
||||||
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
|
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
|
||||||
@@ -42,10 +44,13 @@ class Input {
|
|||||||
const projectPath = rawProjectPath.replace(/\/$/, '');
|
const projectPath = rawProjectPath.replace(/\/$/, '');
|
||||||
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
||||||
const useHostNetwork = rawUseHostNetwork === 'true';
|
const useHostNetwork = rawUseHostNetwork === 'true';
|
||||||
|
const unityVersion =
|
||||||
|
rawUnityVersion === 'auto' ? UnityVersionParser.read(projectPath) : rawUnityVersion;
|
||||||
|
|
||||||
// Return sanitised input
|
// Return sanitised input
|
||||||
return {
|
return {
|
||||||
unityVersion,
|
unityVersion,
|
||||||
|
customImage,
|
||||||
projectPath,
|
projectPath,
|
||||||
testMode,
|
testMode,
|
||||||
artifactsPath,
|
artifactsPath,
|
||||||
|
|||||||
26
src/model/unity-version-parser.js
Normal file
26
src/model/unity-version-parser.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
class UnityVersionParser {
|
||||||
|
static get versionPattern() {
|
||||||
|
return /20\d{2}\.\d\.\w{3,4}|3/;
|
||||||
|
}
|
||||||
|
|
||||||
|
static parse(projectVersionTxt) {
|
||||||
|
const matches = projectVersionTxt.match(UnityVersionParser.versionPattern);
|
||||||
|
if (!matches || matches.length === 0) {
|
||||||
|
throw new Error(`Failed to parse version from "${projectVersionTxt}".`);
|
||||||
|
}
|
||||||
|
return matches[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
static read(projectPath) {
|
||||||
|
const filePath = path.join(projectPath, 'ProjectSettings', 'ProjectVersion.txt');
|
||||||
|
if (!fs.existsSync(filePath)) {
|
||||||
|
return 'auto';
|
||||||
|
}
|
||||||
|
return UnityVersionParser.parse(fs.readFileSync(filePath, 'utf8'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default UnityVersionParser;
|
||||||
25
src/model/unity-version-parser.test.js
Normal file
25
src/model/unity-version-parser.test.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import UnityVersionParser from './unity-version-parser';
|
||||||
|
|
||||||
|
describe('UnityVersionParser', () => {
|
||||||
|
describe('parse', () => {
|
||||||
|
it('throws for empty string', () => {
|
||||||
|
expect(() => UnityVersionParser.parse('')).toThrow(Error);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parses from ProjectVersion.txt', () => {
|
||||||
|
const projectVersionContents = `m_EditorVersion: 2019.2.11f1
|
||||||
|
m_EditorVersionWithRevision: 2019.2.11f1 (5f859a4cfee5)`;
|
||||||
|
expect(UnityVersionParser.parse(projectVersionContents)).toBe('2019.2.11f1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('read', () => {
|
||||||
|
it('does not throw', () => {
|
||||||
|
expect(() => UnityVersionParser.read('')).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reads from unity-project-with-correct-tests', () => {
|
||||||
|
expect(UnityVersionParser.read('./unity-project-with-correct-tests')).toBe('2019.2.11f1');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class SampleComponent : MonoBehaviour
|
||||||
|
{
|
||||||
|
public BasicCounter Counter;
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
Counter = new BasicCounter(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
Counter.Increment();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7a5f63b9ea4b465194653c4d681faf42
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class TimerComponent : MonoBehaviour
|
||||||
|
{
|
||||||
|
public BasicCounter Counter = new BasicCounter();
|
||||||
|
public float Timer = 1f;
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
Timer -= Time.deltaTime;
|
||||||
|
|
||||||
|
if (Timer > 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Counter.Increment();
|
||||||
|
Timer = 1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b668d68a45bb48108ccda73269e3da7b
|
||||||
|
timeCreated: 1610056748
|
||||||
@@ -2,7 +2,8 @@
|
|||||||
"name": "PlayModeTests",
|
"name": "PlayModeTests",
|
||||||
"references": [
|
"references": [
|
||||||
"UnityEngine.TestRunner",
|
"UnityEngine.TestRunner",
|
||||||
"UnityEditor.TestRunner"
|
"UnityEditor.TestRunner",
|
||||||
|
"MyScripts"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
@@ -16,4 +17,4 @@
|
|||||||
"UNITY_INCLUDE_TESTS"
|
"UNITY_INCLUDE_TESTS"
|
||||||
],
|
],
|
||||||
"versionDefines": []
|
"versionDefines": []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
public class SampleComponentTest
|
||||||
|
{
|
||||||
|
private GameObject target;
|
||||||
|
private SampleComponent component;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
target = GameObject.Instantiate(new GameObject());
|
||||||
|
component = target.AddComponent<SampleComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator TestIncrementOnUpdateAfterNextFrame()
|
||||||
|
{
|
||||||
|
// Save the current value, since it was updated after component Start() method called
|
||||||
|
var count = component.Counter.Count;
|
||||||
|
|
||||||
|
// Skip frame and assert the new value
|
||||||
|
yield return null;
|
||||||
|
Assert.AreEqual(count + 1, component.Counter.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c688799d17b14d35ad515bff9de8d12c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.TestTools;
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
namespace Tests
|
namespace Tests
|
||||||
@@ -12,8 +10,14 @@ namespace Tests
|
|||||||
[Test]
|
[Test]
|
||||||
public void NewTestScriptSimplePasses()
|
public void NewTestScriptSimplePasses()
|
||||||
{
|
{
|
||||||
// Use the Assert class to test conditions
|
// Given
|
||||||
Assert.True(true);
|
var counter = new BasicCounter(0);
|
||||||
|
|
||||||
|
// When
|
||||||
|
counter.Increment();
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Assert.AreEqual(1, counter.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
|
// A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use
|
||||||
@@ -21,9 +25,18 @@ namespace Tests
|
|||||||
[UnityTest]
|
[UnityTest]
|
||||||
public IEnumerator NewTestScriptWithEnumeratorPasses()
|
public IEnumerator NewTestScriptWithEnumeratorPasses()
|
||||||
{
|
{
|
||||||
|
// Given
|
||||||
|
var counter = new BasicCounter(3);
|
||||||
|
|
||||||
// Use the Assert class to test conditions.
|
// Use the Assert class to test conditions.
|
||||||
// Use yield to skip a frame.
|
// Use yield to skip a frame.
|
||||||
yield return null;
|
yield return null;
|
||||||
|
|
||||||
|
// When
|
||||||
|
counter.Increment();
|
||||||
|
|
||||||
|
// Then
|
||||||
|
Assert.AreEqual(4, counter.Count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
public class TimerComponentTest
|
||||||
|
{
|
||||||
|
private GameObject target;
|
||||||
|
private TimerComponent component;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
target = GameObject.Instantiate(new GameObject());
|
||||||
|
component = target.AddComponent<TimerComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator TestIncrementAfterSomeTime()
|
||||||
|
{
|
||||||
|
// Save the current value, since it was updated after component Start() method called
|
||||||
|
var count = component.Counter.Count;
|
||||||
|
|
||||||
|
// Skip frame and assert the new value
|
||||||
|
yield return null;
|
||||||
|
Assert.AreEqual(count, component.Counter.Count);
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(1.1f);
|
||||||
|
Assert.AreEqual(count + 1, component.Counter.Count);
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(1.1f);
|
||||||
|
Assert.AreEqual(count + 2, component.Counter.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator TestTimeScaleIsAffectingIncrement()
|
||||||
|
{
|
||||||
|
// Save the current value, since it was updated after component Start() method called
|
||||||
|
var count = component.Counter.Count;
|
||||||
|
Time.timeScale = .5f;
|
||||||
|
|
||||||
|
// Skip frame and assert the new value
|
||||||
|
yield return null;
|
||||||
|
Assert.AreEqual(count, component.Counter.Count);
|
||||||
|
|
||||||
|
yield return WaitForRealSeconds(1.1f);
|
||||||
|
Assert.AreEqual(count, component.Counter.Count);
|
||||||
|
|
||||||
|
yield return WaitForRealSeconds(1.1f);
|
||||||
|
Assert.AreEqual(count + 1, component.Counter.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skipping time ignoring Time.scale
|
||||||
|
// https://answers.unity.com/questions/301868/yield-waitforseconds-outside-of-timescale.html
|
||||||
|
public static IEnumerator WaitForRealSeconds(float time)
|
||||||
|
{
|
||||||
|
float start = Time.realtimeSinceStartup;
|
||||||
|
while (Time.realtimeSinceStartup < start + time)
|
||||||
|
{
|
||||||
|
yield return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 818b22370d404398b87b47a922a435c9
|
||||||
|
timeCreated: 1610056889
|
||||||
Reference in New Issue
Block a user