Merge remote-tracking branch 'upstream/main'

pull/164/head
Aaron Trudeau 2022-04-26 11:55:45 -04:00
commit 793451abba
No known key found for this signature in database
GPG Key ID: D6874B046ABF9536
19 changed files with 261 additions and 300 deletions

View File

@ -62,7 +62,7 @@ jobs:
testMode: ${{ matrix.testMode }}
artifactsPath: ${{ matrix.testMode }}-artifacts
customParameters: -profile SomeProfile -someBoolean -someValue exampleValue
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: Test results for ${{ matrix.testMode }}
path: ${{ steps.tests.outputs.artifactsPath }}
@ -105,16 +105,25 @@ jobs:
projectPath: ${{ matrix.projectPath }}
unityVersion: ${{ matrix.unityVersion }}
testMode: all
coverageOptions: 'generateAdditionalMetrics;generateHtmlReport;generateBadgeReport;assemblyFilters:+MyScripts'
# Test implicit artifactsPath, by not setting it
# Upload artifacts
- name: Upload test results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: Test results (all)
path: ${{ steps.allTests.outputs.artifactsPath }}
retention-days: 14
# Upload coverage
- name: Upload coverage results
uses: actions/upload-artifact@v3
with:
name: Coverage results (all)
path: ${{ steps.allTests.outputs.coveragePath }}
retention-days: 14
testRunnerInEditMode:
name: Test edit mode 📝
runs-on: ubuntu-latest
@ -156,12 +165,20 @@ jobs:
# Upload artifacts
- name: Upload test results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: Test results (edit mode)
path: ${{ steps.editMode.outputs.artifactsPath }}
retention-days: 14
# Upload coverage
- name: Upload coverage results
uses: actions/upload-artifact@v3
with:
name: Coverage results (edit mode)
path: ${{ steps.editMode.outputs.coveragePath }}
retention-days: 14
testRunnerInPlayMode:
name: Test play mode 📺
runs-on: ubuntu-latest
@ -203,12 +220,20 @@ jobs:
# Upload artifacts
- name: Upload test results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: Test results (play mode)
path: ${{ steps.playMode.outputs.artifactsPath }}
retention-days: 14
# Upload coverage
- name: Upload coverage results
uses: actions/upload-artifact@v3
with:
name: Coverage results (play mode)
path: ${{ steps.playMode.outputs.coveragePath }}
retention-days: 14
testEachModeSequentially:
name: Test each mode sequentially 👩‍👩‍👧‍👦 # don't try this at home (it's much slower)
runs-on: ubuntu-latest
@ -258,7 +283,7 @@ jobs:
# Upload combined artifacts
- name: Upload combined test results
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: Test results (combined)
path: artifacts/

View File

@ -8,4 +8,6 @@ fi
yarn lint-staged
yarn lint
yarn test
yarn build
git add dist

View File

@ -20,6 +20,10 @@ inputs:
required: false
default: 'all'
description: 'The type of tests to be run by the test runner.'
coverageOptions:
required: false
default: 'generateAdditionalMetrics;generateHtmlReport;generateBadgeReport'
description: 'Optional coverage parameters for the -coverageOptions argument.'
artifactsPath:
required: false
default: 'artifacts'
@ -50,7 +54,9 @@ inputs:
description: 'Whether the tests are being run for a Unity package instead of a Unity project. If true, any custom docker image passed to this action must have `jq` installed. NOTE: packages with dependencies outside of the Unity package registry are currently not supported.'
outputs:
artifactsPath:
description: 'Path where the artifacts are stored'
description: 'Path where the artifacts are stored.'
coveragePath:
description: 'Path where the code coverage results are stored.'
branding:
icon: 'box'
color: 'gray-dark'

17
dist/Dockerfile vendored
View File

@ -1,17 +0,0 @@
ARG IMAGE
FROM $IMAGE
LABEL "com.github.actions.name"="Unity - Test runner"
LABEL "com.github.actions.description"="Run tests for any Unity project."
LABEL "com.github.actions.icon"="box"
LABEL "com.github.actions.color"="gray-dark"
LABEL "repository"="http://github.com/webbertakken/unity-actions"
LABEL "homepage"="http://github.com/webbertakken/unity-actions"
LABEL "maintainer"="Webber Takken <webber@takken.io>"
ADD steps /steps
RUN chmod -R +x /steps
ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

112
dist/index.js generated vendored
View File

@ -41,20 +41,19 @@ function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
model_1.Action.checkCompatibility();
const { dockerfile, workspace, actionFolder } = model_1.Action;
const { unityVersion, customImage, projectPath, customParameters, testMode, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, packageMode, packageName, } = model_1.Input.getFromUser();
const baseImage = new model_1.ImageTag({ version: unityVersion, customImage });
const { workspace, actionFolder } = model_1.Action;
const { editorVersion, customImage, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, packageMode, packageName, } = model_1.Input.getFromUser();
const baseImage = new model_1.ImageTag({ editorVersion, customImage });
const runnerTemporaryPath = process.env.RUNNER_TEMP;
try {
// Build docker image
const actionImage = yield model_1.Docker.build({ path: actionFolder, dockerfile, baseImage });
// Run docker image
yield model_1.Docker.run(actionImage, {
unityVersion,
yield model_1.Docker.run(baseImage, {
actionFolder,
editorVersion,
workspace,
projectPath,
customParameters,
testMode,
coverageOptions,
artifactsPath,
useHostNetwork,
sshAgent,
@ -66,8 +65,8 @@ function run() {
});
}
finally {
// Set output
yield model_1.Output.setArtifactsPath(artifactsPath);
yield model_1.Output.setCoveragePath('CodeCoverage');
}
if (githubToken) {
const failedTestCount = yield model_1.ResultsCheck.createCheck(artifactsPath, githubToken, checkName);
@ -118,9 +117,6 @@ const Action = {
get actionFolder() {
return `${Action.rootFolder}/dist`;
},
get dockerfile() {
return `${Action.actionFolder}/Dockerfile`;
},
get workspace() {
return process.env.GITHUB_WORKSPACE;
},
@ -155,32 +151,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const fs_1 = __nccwpck_require__(7147);
const image_tag_1 = __importDefault(__nccwpck_require__(7648));
const exec_1 = __nccwpck_require__(1514);
const path_1 = __importDefault(__nccwpck_require__(1017));
const Docker = {
build(buildParameters, silent = false) {
return __awaiter(this, void 0, void 0, function* () {
const { path: buildPath, dockerfile, baseImage } = buildParameters;
const { version } = baseImage;
const tag = new image_tag_1.default({ version });
const command = `docker build ${buildPath} \
--file ${dockerfile} \
--build-arg IMAGE=${baseImage} \
--tag ${tag}`;
yield (0, exec_1.exec)(command, undefined, { silent });
return tag;
});
},
run(image, parameters, silent = false) {
return __awaiter(this, void 0, void 0, function* () {
const { unityVersion, workspace, projectPath, customParameters, testMode, artifactsPath, useHostNetwork, sshAgent, packageMode, packageName, gitPrivateToken, githubToken, runnerTemporaryPath, } = parameters;
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, packageMode, packageName, gitPrivateToken, githubToken, runnerTemporaryPath, } = parameters;
const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home');
if (!(0, fs_1.existsSync)(githubHome))
(0, fs_1.mkdirSync)(githubHome);
const githubWorkflow = path_1.default.join(runnerTemporaryPath, '_github_workflow');
if (!(0, fs_1.existsSync)(githubWorkflow))
(0, fs_1.mkdirSync)(githubWorkflow);
const testPlatforms = (testMode === 'all' ? ['playmode', 'editmode', 'COMBINE_RESULTS'] : [testMode]).join(';');
const command = `docker run \
--workdir /github/workspace \
--rm \
@ -189,10 +172,12 @@ const Docker = {
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
--env UNITY_SERIAL \
--env UNITY_VERSION="${unityVersion}" \
--env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
--env TEST_MODE="${testMode}" \
--env TEST_PLATFORMS="${testPlatforms}" \
--env COVERAGE_OPTIONS="${coverageOptions}" \
--env COVERAGE_RESULTS_PATH="CodeCoverage" \
--env ARTIFACTS_PATH="${artifactsPath}" \
--env PACKAGE_MODE="${packageMode}" \
--env PACKAGE_NAME="${packageName}" \
@ -213,15 +198,17 @@ const Docker = {
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--volume "/var/run/docker.sock":"/var/run/docker.sock" \
--volume "${githubHome}":"/root:z" \
--volume "${githubWorkflow}":"/github/workflow:z" \
--volume "${workspace}":"/github/workspace:z" \
--volume "${actionFolder}/steps":"/steps:z" \
--volume "${actionFolder}/entrypoint.sh":"/entrypoint.sh:z" \
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${image}`;
${image} \
/bin/bash /entrypoint.sh`;
yield (0, exec_1.exec)(command, undefined, { silent });
});
},
@ -243,22 +230,25 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
const platform_1 = __importDefault(__nccwpck_require__(9707));
class ImageTag {
constructor(imageProperties) {
const { repository = 'unityci', name = 'editor', version = '2019.2.11f1', platform = platform_1.default.types.StandaloneLinux64, customImage, } = imageProperties;
if (!ImageTag.versionPattern.test(version)) {
throw new Error(`Invalid version "${version}".`);
const { editorVersion = '2019.2.11f1', targetPlatform = platform_1.default.types.StandaloneLinux64, customImage, } = imageProperties;
if (!ImageTag.versionPattern.test(editorVersion)) {
throw new Error(`Invalid version "${editorVersion}".`);
}
const builderPlatform = ImageTag.getTargetPlatformToImageSuffixMap(platform, version);
this.repository = repository;
this.name = name;
this.version = version;
this.platform = platform;
this.builderPlatform = builderPlatform;
// Either
this.customImage = customImage;
// Or
this.repository = 'unityci';
this.name = 'editor';
this.editorVersion = editorVersion;
this.targetPlatform = targetPlatform;
this.targetPlatformSuffix = ImageTag.getTargetPlatformSuffix(targetPlatform, editorVersion);
this.imagePlatformPrefix = ImageTag.getImagePlatformPrefix(process.platform);
this.imageRollingVersion = 1;
}
static get versionPattern() {
return /^20\d{2}\.\d\.\w{3,4}|3$/;
}
static get imageSuffixes() {
static get targetPlatformSuffixes() {
return {
generic: '',
webgl: 'webgl',
@ -271,11 +261,19 @@ class ImageTag {
facebook: 'facebook',
};
}
static getTargetPlatformToImageSuffixMap(platform, version) {
const { generic, webgl, mac, windows, linux, linuxIl2cpp, android, ios, facebook } = ImageTag.imageSuffixes;
const [major, minor] = version.split('.').map(digit => Number(digit));
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
static getImagePlatformPrefix(platform) {
switch (platform) {
case 'linux':
return 'ubuntu';
default:
throw new Error('The Operating System of this runner is not yet supported.');
}
}
static getTargetPlatformSuffix(targetPlatform, editorVersion) {
const { generic, webgl, mac, windows, linux, linuxIl2cpp, android, ios, facebook } = ImageTag.targetPlatformSuffixes;
const [major, minor] = editorVersion.split('.').map(digit => Number(digit));
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
switch (targetPlatform) {
case platform_1.default.types.StandaloneOSX:
return mac;
case platform_1.default.types.StandaloneWindows:
@ -322,22 +320,21 @@ class ImageTag {
default:
throw new Error(`
Platform must be one of the ones described in the documentation.
"${platform}" is currently not supported.`);
"${targetPlatform}" is currently not supported.`);
}
}
get tag() {
return `${this.version}-${this.builderPlatform}`.replace(/-+$/, '');
const versionAndTarget = `${this.editorVersion}-${this.targetPlatformSuffix}`.replace(/-+$/, '');
return `${this.imagePlatformPrefix}-${versionAndTarget}-${this.imageRollingVersion}`;
}
get image() {
return `${this.repository}/${this.name}`.replace(/^\/+/, '');
}
toString() {
const { image, tag, customImage } = this;
if (customImage && customImage !== '') {
if (customImage)
return customImage;
}
const dockerRepoVersion = 0;
return `${image}:${tag}-${dockerRepoVersion}`;
return `${image}:${tag}`;
}
}
exports["default"] = ImageTag;
@ -428,11 +425,12 @@ const Input = {
},
getFromUser() {
// Input variables specified in workflow using "with" prop.
const rawUnityVersion = (0, core_1.getInput)('unityVersion') || 'auto';
const unityVersion = (0, core_1.getInput)('unityVersion') || 'auto';
const customImage = (0, core_1.getInput)('customImage') || '';
const rawProjectPath = (0, core_1.getInput)('projectPath') || '.';
const customParameters = (0, core_1.getInput)('customParameters') || '';
const testMode = ((0, core_1.getInput)('testMode') || 'all').toLowerCase();
const coverageOptions = (0, core_1.getInput)('coverageOptions') || '';
const rawArtifactsPath = (0, core_1.getInput)('artifactsPath') || 'artifacts';
const rawUseHostNetwork = (0, core_1.getInput)('useHostNetwork') || 'false';
const sshAgent = (0, core_1.getInput)('sshAgent') || '';
@ -469,14 +467,15 @@ const Input = {
// Sanitise other input
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
const useHostNetwork = rawUseHostNetwork === 'true';
const unityVersion = rawUnityVersion === 'auto' ? unity_version_parser_1.default.read(projectPath) : rawUnityVersion;
const editorVersion = unityVersion === 'auto' ? unity_version_parser_1.default.read(projectPath) : unityVersion;
// Return sanitised input
return {
unityVersion,
editorVersion,
customImage,
projectPath,
customParameters,
testMode,
coverageOptions,
artifactsPath,
useHostNetwork,
sshAgent,
@ -534,6 +533,11 @@ const Output = {
yield core.setOutput('artifactsPath', artifactsPath);
});
},
setCoveragePath(coveragePath) {
return __awaiter(this, void 0, void 0, function* () {
yield core.setOutput('coveragePath', coveragePath);
});
},
};
exports["default"] = Output;

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -77,27 +77,18 @@ fi
echo "Using artifacts path \"$ARTIFACTS_PATH\" to save test results."
FULL_ARTIFACTS_PATH=$GITHUB_WORKSPACE/$ARTIFACTS_PATH
#
# Set and display the coverage results path
#
echo "Using coverage results path \"$COVERAGE_RESULTS_PATH\" to save test coverage results."
FULL_COVERAGE_RESULTS_PATH=$GITHUB_WORKSPACE/$COVERAGE_RESULTS_PATH
#
# Display custom parameters
#
echo "Using custom parameters $CUSTOM_PARAMETERS."
# Set the modes for testing
case $TEST_MODE in
editmode)
echo "Edit mode selected for testing."
EDIT_MODE=true
;;
playmode)
echo "Play mode selected for testing."
PLAY_MODE=true
;;
*)
echo "All modes selected for testing."
EDIT_MODE=true
PLAY_MODE=true
;;
esac
echo "Using custom parameters $CUSTOM_PARAMETERS."
# The following tests are 2019 mode (requires Unity 2019.2.11f1 or later)
# Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html
@ -128,118 +119,61 @@ echo ""
ls -alh $UNITY_PROJECT_PATH
#
# Testing in EditMode
# Testing for each platform
#
EDIT_MODE_EXIT_CODE=0
if [ "$EDIT_MODE" = "true" ]; then
for platform in ${TEST_PLATFORMS//;/ }; do
echo ""
echo "###########################"
echo "# Testing in EditMode #"
echo "# Testing in $platform #"
echo "###########################"
echo ""
if [[ "$platform" != "COMBINE_RESULTS" ]]; then
runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
else
runTests="-quit"
fi
unity-editor \
-batchmode \
-logFile "$FULL_ARTIFACTS_PATH/editmode.log" \
-logFile "$FULL_ARTIFACTS_PATH/$platform.log" \
-projectPath "$UNITY_PROJECT_PATH" \
-runTests \
-testPlatform editmode \
-testResults "$FULL_ARTIFACTS_PATH/editmode-results.xml" \
-coverageResultsPath "$FULL_COVERAGE_RESULTS_PATH" \
$runTests \
-enableCodeCoverage \
-debugCodeOptimization \
-coverageOptions "$COVERAGE_OPTIONS" \
$CUSTOM_PARAMETERS
# Catch exit code
EDIT_MODE_EXIT_CODE=$?
TEST_EXIT_CODE=$?
# Print unity log output
cat "$FULL_ARTIFACTS_PATH/editmode.log"
cat "$FULL_ARTIFACTS_PATH/$platform.log"
# Display results
if [ $EDIT_MODE_EXIT_CODE -eq 0 ]; then
if [ $TEST_EXIT_CODE -eq 0 ]; then
echo "Run succeeded, no failures occurred";
elif [ $EDIT_MODE_EXIT_CODE -eq 2 ]; then
elif [ $TEST_EXIT_CODE -eq 2 ]; then
echo "Run succeeded, some tests failed";
elif [ $EDIT_MODE_EXIT_CODE -eq 3 ]; then
elif [ $TEST_EXIT_CODE -eq 3 ]; then
echo "Run failure (other failure)";
else
echo "Unexpected exit code $EDIT_MODE_EXIT_CODE";
echo "Unexpected exit code $TEST_EXIT_CODE";
fi
fi
#
# Testing in PlayMode
#
PLAY_MODE_EXIT_CODE=0
if [ "$PLAY_MODE" = "true" ]; then
echo ""
echo "###########################"
echo "# Testing in PlayMode #"
echo "###########################"
echo ""
unity-editor \
-batchmode \
-logFile "$FULL_ARTIFACTS_PATH/playmode.log" \
-projectPath "$UNITY_PROJECT_PATH" \
-runTests \
-testPlatform playmode \
-testResults "$FULL_ARTIFACTS_PATH/playmode-results.xml" \
$CUSTOM_PARAMETERS
# Catch exit code
PLAY_MODE_EXIT_CODE=$?
# Print unity log output
cat "$FULL_ARTIFACTS_PATH/playmode.log"
# Display results
if [ $PLAY_MODE_EXIT_CODE -eq 0 ]; then
echo "Run succeeded, no failures occurred";
elif [ $PLAY_MODE_EXIT_CODE -eq 2 ]; then
echo "Run succeeded, some tests failed";
elif [ $PLAY_MODE_EXIT_CODE -eq 3 ]; then
echo "Run failure (other failure)";
else
echo "Unexpected exit code $PLAY_MODE_EXIT_CODE";
if [ $TEST_EXIT_CODE -ne 0 ]; then
TEST_RUNNER_EXIT_CODE=$TEST_EXIT_CODE
fi
fi
#
# Results
#
echo ""
echo "###########################"
echo "# Project directory #"
echo "###########################"
echo ""
ls -alh $UNITY_PROJECT_PATH
if [ "$EDIT_MODE" = "true" ]; then
echo ""
echo "###########################"
echo "# Edit Mode Results #"
echo "# $platform Results #"
echo "###########################"
echo ""
cat "$FULL_ARTIFACTS_PATH/editmode-results.xml"
cat "$FULL_ARTIFACTS_PATH/editmode-results.xml" | grep test-run | grep Passed
fi
if [ "$PLAY_MODE" = "true" ]; then
echo ""
echo "###########################"
echo "# Play Mode Results #"
echo "###########################"
echo ""
cat "$FULL_ARTIFACTS_PATH/playmode-results.xml"
cat "$FULL_ARTIFACTS_PATH/playmode-results.xml" | grep test-run | grep Passed
fi
#
# Exit
#
if [ $EDIT_MODE_EXIT_CODE -gt 0 ]; then
TEST_RUNNER_EXIT_CODE=$EDIT_MODE_EXIT_CODE
fi
if [ $PLAY_MODE_EXIT_CODE -gt 0 ]; then
TEST_RUNNER_EXIT_CODE=$PLAY_MODE_EXIT_CODE
fi
if [[ "$platform" != "COMBINE_RESULTS" ]]; then
cat "$FULL_ARTIFACTS_PATH/$platform-results.xml"
cat "$FULL_ARTIFACTS_PATH/$platform-results.xml" | grep test-run | grep Passed
fi
done

View File

@ -5,13 +5,14 @@ async function run() {
try {
Action.checkCompatibility();
const { dockerfile, workspace, actionFolder } = Action;
const { workspace, actionFolder } = Action;
const {
unityVersion,
editorVersion,
customImage,
projectPath,
customParameters,
testMode,
coverageOptions,
artifactsPath,
useHostNetwork,
sshAgent,
@ -21,20 +22,18 @@ async function run() {
packageMode,
packageName,
} = Input.getFromUser();
const baseImage = new ImageTag({ version: unityVersion, customImage });
const baseImage = new ImageTag({ editorVersion, customImage });
const runnerTemporaryPath = process.env.RUNNER_TEMP;
try {
// Build docker image
const actionImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
// Run docker image
await Docker.run(actionImage, {
unityVersion,
await Docker.run(baseImage, {
actionFolder,
editorVersion,
workspace,
projectPath,
customParameters,
testMode,
coverageOptions,
artifactsPath,
useHostNetwork,
sshAgent,
@ -45,8 +44,8 @@ async function run() {
runnerTemporaryPath,
});
} finally {
// Set output
await Output.setArtifactsPath(artifactsPath);
await Output.setCoveragePath('CodeCoverage');
}
if (githubToken) {

View File

@ -26,11 +26,4 @@ describe('Action', () => {
expect(path.basename(actionFolder)).toStrictEqual('dist');
expect(fs.existsSync(actionFolder)).toStrictEqual(true);
});
it('returns the docker file', () => {
const { dockerfile } = Action;
expect(path.basename(dockerfile)).toStrictEqual('Dockerfile');
expect(fs.existsSync(dockerfile)).toStrictEqual(true);
});
});

View File

@ -29,10 +29,6 @@ const Action = {
return `${Action.rootFolder}/dist`;
},
get dockerfile() {
return `${Action.actionFolder}/Dockerfile`;
},
get workspace() {
return process.env.GITHUB_WORKSPACE;
},

View File

@ -1,21 +1,7 @@
import Action from './action';
import Docker from './docker';
import ImageTag from './image-tag';
describe('Docker', () => {
it.skip('builds', async () => {
const path = Action.actionFolder;
const dockerfile = `${path}/Dockerfile`;
const baseImage = new ImageTag({
repository: '',
name: 'alpine',
version: '3',
platform: 'Test',
});
const tag = await Docker.build({ path, dockerfile, baseImage }, true);
expect(tag).toBeInstanceOf(ImageTag);
expect(tag.toString()).toStrictEqual('unity-builder:3');
}, 240_000);
it.skip('runs', async () => {
const image = 'unity-builder:2019.2.11f1-webgl';
const parameters = {

View File

@ -1,31 +1,17 @@
import { existsSync, mkdirSync } from 'fs';
import ImageTag from './image-tag';
import { exec } from '@actions/exec';
import path from 'path';
const Docker = {
async build(buildParameters, silent = false) {
const { path: buildPath, dockerfile, baseImage } = buildParameters;
const { version } = baseImage;
const tag = new ImageTag({ version });
const command = `docker build ${buildPath} \
--file ${dockerfile} \
--build-arg IMAGE=${baseImage} \
--tag ${tag}`;
await exec(command, undefined, { silent });
return tag;
},
async run(image, parameters, silent = false) {
const {
unityVersion,
actionFolder,
editorVersion,
workspace,
projectPath,
customParameters,
testMode,
coverageOptions,
artifactsPath,
useHostNetwork,
sshAgent,
@ -40,6 +26,9 @@ const Docker = {
if (!existsSync(githubHome)) mkdirSync(githubHome);
const githubWorkflow = path.join(runnerTemporaryPath, '_github_workflow');
if (!existsSync(githubWorkflow)) mkdirSync(githubWorkflow);
const testPlatforms = (
testMode === 'all' ? ['playmode', 'editmode', 'COMBINE_RESULTS'] : [testMode]
).join(';');
const command = `docker run \
--workdir /github/workspace \
@ -49,10 +38,12 @@ const Docker = {
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
--env UNITY_SERIAL \
--env UNITY_VERSION="${unityVersion}" \
--env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
--env TEST_MODE="${testMode}" \
--env TEST_PLATFORMS="${testPlatforms}" \
--env COVERAGE_OPTIONS="${coverageOptions}" \
--env COVERAGE_RESULTS_PATH="CodeCoverage" \
--env ARTIFACTS_PATH="${artifactsPath}" \
--env PACKAGE_MODE="${packageMode}" \
--env PACKAGE_NAME="${packageName}" \
@ -73,15 +64,17 @@ const Docker = {
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--volume "/var/run/docker.sock":"/var/run/docker.sock" \
--volume "${githubHome}":"/root:z" \
--volume "${githubWorkflow}":"/github/workflow:z" \
--volume "${workspace}":"/github/workspace:z" \
--volume "${actionFolder}/steps":"/steps:z" \
--volume "${actionFolder}/entrypoint.sh":"/entrypoint.sh:z" \
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${image}`;
${image} \
/bin/bash /entrypoint.sh`;
await exec(command, undefined, { silent });
},

View File

@ -1,11 +1,11 @@
import ImageTag from './image-tag';
jest.spyOn(ImageTag, 'getImagePlatformPrefix').mockReturnValue('ubuntu');
describe('ImageTag', () => {
const some = {
repository: 'test1',
name: 'test2',
version: '2099.9.f9f9',
platform: 'Test',
editorVersion: '2099.9.f9f9',
targetPlatform: 'Test',
builderPlatform: '',
};
@ -17,40 +17,45 @@ describe('ImageTag', () => {
describe('constructor', () => {
it('can be called', () => {
const { platform } = some;
expect(() => new ImageTag({ platform })).not.toThrow();
const { targetPlatform } = some;
expect(() => new ImageTag({ platform: targetPlatform })).not.toThrow();
});
it('accepts parameters and sets the right properties', () => {
const image = new ImageTag(some);
expect(image.repository).toStrictEqual(some.repository);
expect(image.name).toStrictEqual(some.name);
expect(image.version).toStrictEqual(some.version);
expect(image.platform).toStrictEqual(some.platform);
expect(image.builderPlatform).toStrictEqual(some.builderPlatform);
expect(image.repository).toStrictEqual('unityci');
expect(image.name).toStrictEqual('editor');
expect(image.editorVersion).toStrictEqual(some.editorVersion);
expect(image.targetPlatform).toStrictEqual(some.targetPlatform);
expect(image.targetPlatformSuffix).toStrictEqual(some.builderPlatform);
});
test.each(['2000.0.0f0', '2011.1.11f1'])('accepts %p version format', version => {
expect(() => new ImageTag({ version, platform: some.platform })).not.toThrow();
test.each(['2000.0.0f0', '2011.1.11f1'])('accepts %p version format', editorVersion => {
expect(
() => new ImageTag({ editorVersion, targetPlatform: some.targetPlatform }),
).not.toThrow();
});
test.each(['some version', '', 1])('throws for incorrect versions %p', version => {
const { platform } = some;
expect(() => new ImageTag({ version, platform })).toThrow();
test.each(['some version', '', 1])('throws for incorrect versions %p', editorVersion => {
const { targetPlatform } = some;
expect(() => new ImageTag({ editorVersion, targetPlatform })).toThrow();
});
});
describe('toString', () => {
it('returns the correct version', () => {
const image = new ImageTag({ version: '2099.1.1111', platform: some.platform });
const image = new ImageTag({
editorVersion: '2099.1.1111',
targetPlatform: some.targetPlatform,
});
expect(image.toString()).toStrictEqual(`${defaults.image}:2099.1.1111-0`);
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2099.1.1111-1`);
});
it('returns customImage if given', () => {
const image = new ImageTag({
version: '2099.1.1111',
platform: some.platform,
editorVersion: '2099.1.1111',
targetPlatform: some.targetPlatform,
customImage: `${defaults.image}:2099.1.1111@347598437689743986`,
});
@ -58,15 +63,15 @@ describe('ImageTag', () => {
});
it('returns the specific build platform', () => {
const image = new ImageTag({ version: '2019.2.11f1', platform: 'WebGL' });
const image = new ImageTag({ editorVersion: '2019.2.11f1', targetPlatform: 'WebGL' });
expect(image.toString()).toStrictEqual(`${defaults.image}:2019.2.11f1-webgl-0`);
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2019.2.11f1-webgl-1`);
});
it('returns no specific build platform for generic targetPlatforms', () => {
const image = new ImageTag({ platform: 'NoTarget' });
const image = new ImageTag({ targetPlatform: 'NoTarget' });
expect(image.toString()).toStrictEqual(`${defaults.image}:2019.2.11f1-0`);
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2019.2.11f1-1`);
});
});
});

View File

@ -1,41 +1,44 @@
import Platform from './platform';
class ImageTag {
public customImage?: string;
public repository: string;
public name: string;
public version: string;
public platform: any;
public builderPlatform: string;
public customImage: any;
public editorVersion: string;
public targetPlatform: string;
public targetPlatformSuffix: string;
public imagePlatformPrefix: string;
public imageRollingVersion: number;
constructor(imageProperties) {
const {
repository = 'unityci',
name = 'editor',
version = '2019.2.11f1',
platform = Platform.types.StandaloneLinux64,
editorVersion = '2019.2.11f1',
targetPlatform = Platform.types.StandaloneLinux64,
customImage,
} = imageProperties;
if (!ImageTag.versionPattern.test(version)) {
throw new Error(`Invalid version "${version}".`);
if (!ImageTag.versionPattern.test(editorVersion)) {
throw new Error(`Invalid version "${editorVersion}".`);
}
const builderPlatform = ImageTag.getTargetPlatformToImageSuffixMap(platform, version);
this.repository = repository;
this.name = name;
this.version = version;
this.platform = platform;
this.builderPlatform = builderPlatform;
// Either
this.customImage = customImage;
// Or
this.repository = 'unityci';
this.name = 'editor';
this.editorVersion = editorVersion;
this.targetPlatform = targetPlatform;
this.targetPlatformSuffix = ImageTag.getTargetPlatformSuffix(targetPlatform, editorVersion);
this.imagePlatformPrefix = ImageTag.getImagePlatformPrefix(process.platform);
this.imageRollingVersion = 1;
}
static get versionPattern() {
return /^20\d{2}\.\d\.\w{3,4}|3$/;
}
static get imageSuffixes() {
static get targetPlatformSuffixes() {
return {
generic: '',
webgl: 'webgl',
@ -49,13 +52,22 @@ class ImageTag {
};
}
static getTargetPlatformToImageSuffixMap(platform, version) {
const { generic, webgl, mac, windows, linux, linuxIl2cpp, android, ios, facebook } =
ImageTag.imageSuffixes;
const [major, minor] = version.split('.').map(digit => Number(digit));
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
static getImagePlatformPrefix(platform) {
switch (platform) {
case 'linux':
return 'ubuntu';
default:
throw new Error('The Operating System of this runner is not yet supported.');
}
}
static getTargetPlatformSuffix(targetPlatform, editorVersion) {
const { generic, webgl, mac, windows, linux, linuxIl2cpp, android, ios, facebook } =
ImageTag.targetPlatformSuffixes;
const [major, minor] = editorVersion.split('.').map(digit => Number(digit));
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
switch (targetPlatform) {
case Platform.types.StandaloneOSX:
return mac;
case Platform.types.StandaloneWindows:
@ -103,12 +115,17 @@ class ImageTag {
default:
throw new Error(`
Platform must be one of the ones described in the documentation.
"${platform}" is currently not supported.`);
"${targetPlatform}" is currently not supported.`);
}
}
get tag() {
return `${this.version}-${this.builderPlatform}`.replace(/-+$/, '');
const versionAndTarget = `${this.editorVersion}-${this.targetPlatformSuffix}`.replace(
/-+$/,
'',
);
return `${this.imagePlatformPrefix}-${versionAndTarget}-${this.imageRollingVersion}`;
}
get image() {
@ -118,12 +135,9 @@ class ImageTag {
toString() {
const { image, tag, customImage } = this;
if (customImage && customImage !== '') {
return customImage;
}
if (customImage) return customImage;
const dockerRepoVersion = 0;
return `${image}:${tag}-${dockerRepoVersion}`;
return `${image}:${tag}`;
}
}

View File

@ -62,11 +62,12 @@ const Input = {
getFromUser() {
// Input variables specified in workflow using "with" prop.
const rawUnityVersion = getInput('unityVersion') || 'auto';
const unityVersion = getInput('unityVersion') || 'auto';
const customImage = getInput('customImage') || '';
const rawProjectPath = getInput('projectPath') || '.';
const customParameters = getInput('customParameters') || '';
const testMode = (getInput('testMode') || 'all').toLowerCase();
const coverageOptions = getInput('coverageOptions') || '';
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
const rawUseHostNetwork = getInput('useHostNetwork') || 'false';
const sshAgent = getInput('sshAgent') || '';
@ -111,16 +112,17 @@ const Input = {
// Sanitise other input
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
const useHostNetwork = rawUseHostNetwork === 'true';
const unityVersion =
rawUnityVersion === 'auto' ? UnityVersionParser.read(projectPath) : rawUnityVersion;
const editorVersion =
unityVersion === 'auto' ? UnityVersionParser.read(projectPath) : unityVersion;
// Return sanitised input
return {
unityVersion,
editorVersion,
customImage,
projectPath,
customParameters,
testMode,
coverageOptions,
artifactsPath,
useHostNetwork,
sshAgent,

View File

@ -6,4 +6,19 @@ describe('Output', () => {
await expect(Output.setArtifactsPath('')).resolves.not.toThrow();
});
});
describe('setCoveragePath', () => {
it('does not throw', async () => {
await expect(Output.setCoveragePath('')).resolves.not.toThrow();
await expect(Output.setCoveragePath('artifacts')).resolves.not.toThrow();
await expect(Output.setCoveragePath('coverage')).resolves.not.toThrow();
await expect(Output.setCoveragePath('CodeCoverage')).resolves.not.toThrow();
await expect(Output.setCoveragePath('./artifacts')).resolves.not.toThrow();
await expect(Output.setCoveragePath('./coverage')).resolves.not.toThrow();
await expect(Output.setCoveragePath('./CodeCoverage')).resolves.not.toThrow();
await expect(Output.setCoveragePath('./artifacts/coverage')).resolves.not.toThrow();
await expect(Output.setCoveragePath('./coverage/')).resolves.not.toThrow();
await expect(Output.setCoveragePath('./CodeCoverage/')).resolves.not.toThrow();
await expect(Output.setCoveragePath('./artifacts/coverage/')).resolves.not.toThrow();
});
});
});

View File

@ -4,6 +4,9 @@ const Output = {
async setArtifactsPath(artifactsPath) {
await core.setOutput('artifactsPath', artifactsPath);
},
async setCoveragePath(coveragePath) {
await core.setOutput('coveragePath', coveragePath);
},
};
export default Output;

View File

@ -6,6 +6,7 @@
"com.unity.ide.vscode": "1.1.2",
"com.unity.package-manager-ui": "2.2.0",
"com.unity.test-framework": "1.0.13",
"com.unity.testtools.codecoverage": "1.1.1",
"com.unity.textmeshpro": "2.0.1",
"com.unity.timeline": "1.1.0",
"com.unity.ugui": "1.0.0",

View File

@ -3601,9 +3601,9 @@ minimatch@^3.0.4:
brace-expansion "^1.1.7"
minimist@^1.1.1, minimist@^1.2.0, minimist@^1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602"
integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==
version "1.2.6"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44"
integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==
mixin-deep@^1.2.0:
version "1.3.2"