Added Windows Support (#184)

* Modifying js files to account for win support

* Added new powershell scripts to support windows invocation

* Fixed undefined error in stack trace logic

* Added new func for resolving image tag default

* Changed structure of docker.js to match new standard
pull/185/head
Matthew Shiroma 2022-05-23 16:41:36 -07:00 committed by GitHub
parent d95f760d49
commit e8774f3837
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 3257 additions and 2729 deletions

48
dist/entrypoint.ps1 vendored 100644
View File

@ -0,0 +1,48 @@
#
# Create directory for license activation
#
$ACTIVATE_LICENSE_PATH = "${env:GITHUB_WORKSPACE}/_activate-license"
New-Item -Path "$ACTIVATE_LICENSE_PATH" -ItemType Directory
#
# Run steps
#
& $PSScriptRoot\steps\activate.ps1
& $PSScriptRoot\steps\set_gitcredential.ps1
& $PSScriptRoot\steps\run_tests.ps1
& $PSScriptRoot\steps\return_license.ps1
#
# Remove license activation directory
#
Remove-Item "$ACTIVATE_LICENSE_PATH" -Recurse -Force
#
# Instructions for debugging
#
if ($TEST_RUNNER_EXIT_CODE -gt 0)
{
Write-Output ""
Write-Output "###########################"
Write-Output "# Failure #"
Write-Output "###########################"
Write-Output ""
Write-Output "Please note that the exit code is not very descriptive."
Write-Output "Most likely it will not help you solve the issue."
Write-Output ""
Write-Output "To find the reason for failure: please search for errors in the log above."
Write-Output ""
}
#
# Exit with code from the build step.
#
if ( ($USE_EXIT_CODE -eq "true") -and ($TEST_RUNNER_EXIT_CODE -ne 2) )
{
exit $TEST_RUNNER_EXIT_CODE
}

5440
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

110
dist/steps/activate.ps1 vendored 100644
View File

@ -0,0 +1,110 @@
# Run in ACTIVATE_LICENSE_PATH directory
Write-Output "Changing to $ACTIVATE_LICENSE_PATH directory."
Push-Location "$ACTIVATE_LICENSE_PATH"
if ( ($null -ne ${env:UNITY_LICENSE}) -or ($null -ne ${env:UNITY_LICENSE_FILE}) )
{
#
# PERSONAL LICENSE MODE
#
# This will activate Unity, using a license file
#
# Note that this is the ONLY WAY for PERSONAL LICENSES in 2020.
# * See for more details: https://gitlab.com/gableroux/unity3d-gitlab-ci-example/issues/5#note_72815478
#
# The license file can be acquired using `game-ci/request-manual-activation-file` action.
Write-Output "Requesting activation (personal license)"
# Set the license file path
$FILE_PATH = "$ACTIVATE_LICENSE_PATH\UnityLicenseFile.ulf"
if ($null -ne ${env:UNITY_LICENSE})
{
# Copy license file from Github variables
Add-Content -Path $FILE_PATH -Value ${env:UNITY_LICENSE}
}
elseif ($null -ne ${env:UNITY_LICENSE_FILE})
{
# Copy license file from file system
Add-Content -Path $FILE_PATH -Value ${env:UNITY_LICENSE_FILE}
}
$convert = (Get-Content -Raw $FILE_PATH) -replace "`r`n","`n"
[io.file]::WriteAllText($FILE_PATH, $convert)
Get-ChildItem -Path $FILE_PATH
# Activate license
$ACTIVATION_OUTPUT = Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity\Hub\Editor\${env:UNITY_VERSION}\editor\Unity.exe" -ArgumentList "-batchmode -nographics -logFile $ACTIVATE_LICENSE_PATH\activate.log -quit -manualLicenseFile $FILE_PATH"
# Store the exit code from the verify command
$UNITY_EXIT_CODE = $ACTIVATION_OUTPUT.ExitCode
# The exit code for personal activation is always 1;
# Determine whether activation was successful.
#
# Successful output should include the following:
#
# "LICENSE SYSTEM [2020120 18:51:20] Next license update check is after 2019-11-25T18:23:38"
#
$ACTIVATION_SUCCESSFUL = (Get-Content $ACTIVATE_LICENSE_PATH\activate.log | Select-String 'Next license update check is after' | Measure-Object -line | Select-Object -Expand Lines)
# Set exit code to 0 if activation was successful
if ($ACTIVATION_SUCCESSFUL -eq 1)
{
$UNITY_EXIT_CODE = 0
}
# Remove license file
Remove-Item -Force $FILE_PATH
}
elseif ( ($null -ne ${env:UNITY_SERIAL}) -and ($null -ne ${env:UNITY_EMAIL}) -and ($null -ne ${env:UNITY_PASSWORD}) )
{
#
# PROFESSIONAL (SERIAL) LICENSE MODE
#
# This will activate unity, using the activating process.
#
# Note: This is the preferred way for PROFESSIONAL LICENSES.
#
Write-Output "Requesting activation (professional license)"
# Activate license
$ACTIVATION_OUTPUT = Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity\Hub\Editor\${env:UNITY_VERSION}\editor\Unity.exe" -ArgumentList "-batchmode -nographics -logFile $ACTIVATE_LICENSE_PATH\activate.log -quit -serial ${env:UNITY_SERIAL} -username ${env:UNITY_EMAIL} -password ${env:UNITY_PASSWORD}"
# Store the exit code from the verify command
$UNITY_EXIT_CODE = $ACTIVATION_OUTPUT.ExitCode
}
else
{
#
# NO LICENSE ACTIVATION STRATEGY MATCHED
#
# This will exit since no activation strategies could be matched.
#
Write-Output "License activation strategy could not be determined."
Write-Output ""
Write-Output "Visit https://game.ci/docs/github/getting-started for more"
Write-Output "details on how to set up one of the possible activation strategies."
# Immediately exit as no UNITY_EXIT_CODE can be derived.
exit 1;
}
#
# Display information about the result
#
Get-Content $ACTIVATE_LICENSE_PATH\activate.log
if ($UNITY_EXIT_CODE -eq 0)
{
# Activation was a success
Write-Output "Activation complete."
}
else
{
# Activation failed so exit with the code from the license verification step
Write-Output "Unclassified error occured while trying to activate license."
Write-Output "Exit code was: $UNITY_EXIT_CODE"
exit $UNITY_EXIT_CODE
}
# Return to previous working directory
Pop-Location

18
dist/steps/return_license.ps1 vendored 100644
View File

@ -0,0 +1,18 @@
# Run in ACTIVATE_LICENSE_PATH directory
Write-Output "Changing to $ACTIVATE_LICENSE_PATH directory."
Push-Location "$ACTIVATE_LICENSE_PATH"
if ($null -ne ${env:UNITY_SERIAL})
{
#
# PROFESSIONAL (SERIAL) LICENSE MODE
#
# This will return the license that is currently in use.
#
$RETURN_OUTPUT = Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity\Hub\Editor\${env:UNITY_VERSION}\editor\Unity.exe" -ArgumentList "-batchmode -nographics -logFile $FULL_ARTIFACTS_PATH\deactivate.log -quit -returnlicense"
Get-Content $FULL_ARTIFACTS_PATH\deactivate.log
}
# Return to previous working directory
Pop-Location

118
dist/steps/run_tests.ps1 vendored 100644
View File

@ -0,0 +1,118 @@
#
# Set and display project path
#
$UNITY_PROJECT_PATH = "${env:GITHUB_WORKSPACE}/${env:PROJECT_PATH}"
Write-Output "Using project path $UNITY_PROJECT_PATH"
#
# Set and display the artifacts path
#
Write-Output "Using artifacts path ${env:ARTIFACTS_PATH} to save test results."
$FULL_ARTIFACTS_PATH = "${env:GITHUB_WORKSPACE}\${env:ARTIFACTS_PATH}"
#
# Set and display the coverage results path
#
Write-Output "Using coverage results path ${env:COVERAGE_RESULTS_PATH} to save test coverage results."
$FULL_COVERAGE_RESULTS_PATH = "${env:GITHUB_WORKSPACE}\${env:COVERAGE_RESULTS_PATH}"
#
# Display custom parameters
#
Write-Output "Using custom parameters ${env: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
#
# Display the unity version
#
Write-Output "Using Unity version ${env:UNITY_VERSION} to test."
#
# Overall info
#
Write-Output ""
Write-Output "###########################"
Write-Output "# Artifacts folder #"
Write-Output "###########################"
Write-Output ""
Write-Output "Creating $FULL_ARTIFACTS_PATH if it does not exist."
New-Item -Path "$FULL_ARTIFACTS_PATH" -ItemType Directory
Write-Output ""
Write-Output "###########################"
Write-Output "# Project directory #"
Write-Output "###########################"
Write-Output ""
Get-ChildItem -Hidden -Path $UNITY_PROJECT_PATH
#
# Testing for each platform
#
foreach ( $platform in ${env:TEST_PLATFORMS}.Split(";") )
{
Write-Output ""
Write-Output "###########################"
Write-Output "# Testing in $platform #"
Write-Output "###########################"
Write-Output ""
if ( $platform -ne "COMBINE_RESULTS" )
{
$runTests = "-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
}
else
{
$runTests = "-quit"
}
$TEST_OUTPUT = Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity\Hub\Editor\${env:UNITY_VERSION}\editor\Unity.exe" -ArgumentList "-batchmode -logFile $FULL_ARTIFACTS_PATH\$platform.log -projectPath $UNITY_PROJECT_PATH -coverageResultsPath $FULL_COVERAGE_RESULTS_PATH $runTests -enableCodeCoverage -debugCodeOptimization -coverageOptions ${env:COVERAGE_OPTIONS} ${env:CUSTOM_PARAMETERS}"
# Catch exit code
$TEST_EXIT_CODE = $TEST_OUTPUT.ExitCode
# Print unity log output
Get-Content "$FULL_ARTIFACTS_PATH/$platform.log"
# Display results
if ($TEST_EXIT_CODE -eq 0)
{
Write-Output "Run succeeded, no failures occurred";
}
elseif ($TEST_EXIT_CODE -eq 2)
{
Write-Output "Run succeeded, some tests failed";
}
elseif ($TEST_EXIT_CODE -eq 3)
{
Write-Output "Run failure (other failure)";
}
else
{
Write-Output "Unexpected exit code $TEST_EXIT_CODE";
}
if ( $TEST_EXIT_CODE -ne 0)
{
$TEST_RUNNER_EXIT_CODE = $TEST_EXIT_CODE
}
Write-Output ""
Write-Output "###########################"
Write-Output "# $platform Results #"
Write-Output "###########################"
Write-Output ""
if ($platform -ne "COMBINE_RESULTS")
{
Get-Content "$FULL_ARTIFACTS_PATH/$platform-results.xml"
Get-Content "$FULL_ARTIFACTS_PATH/$platform-results.xml" | Select-String "test-run" | Select-String "Passed"
}
}

View File

@ -0,0 +1,22 @@
if ($null -eq ${env:GIT_PRIVATE_TOKEN})
{
Write-Output "GIT_PRIVATE_TOKEN unset skipping"
}
else
{
Write-Output "GIT_PRIVATE_TOKEN is set configuring git credentials"
git config --global credential.helper store
git config --global --replace-all url.https://github.com/.insteadOf ssh://git@github.com/
git config --global --add url.https://github.com/.insteadOf git@github.com
git config --global url."https://token:${env:GIT_PRIVATE_TOKEN}@github.com/".insteadOf "https://github.com/"
git config --global url."https://ssh:${env:GIT_PRIVATE_TOKEN}@github.com/".insteadOf "ssh://git@github.com/"
git config --global url."https://git:${env:GIT_PRIVATE_TOKEN}@github.com/".insteadOf "git@github.com:"
}
Write-Output "---------- git config --list -------------"
git config --list
Write-Output "---------- git config --list --show-origin -------------"
git config --list --show-origin

View File

@ -4,8 +4,8 @@ import path from 'path';
describe('Action', () => {
describe('compatibility check', () => {
it('throws for anything other than linux', () => {
if (process.platform !== 'linux') {
it('throws for anything other than linux or windows', () => {
if (process.platform !== 'linux' && process.platform !== 'win32') {
expect(() => Action.checkCompatibility()).toThrow();
} else {
expect(() => Action.checkCompatibility()).not.toThrow();

View File

@ -2,7 +2,7 @@ import path from 'path';
const Action = {
get supportedPlatforms() {
return ['linux'];
return ['linux', 'win32'];
},
get isRunningLocally() {

View File

@ -4,6 +4,21 @@ import path from 'path';
const Docker = {
async run(image, parameters, silent = false) {
let runCommand = '';
switch (process.platform) {
case 'linux':
runCommand = this.getLinuxCommand(image, parameters);
break;
case 'win32':
runCommand = this.getWindowsCommand(image, parameters);
break;
default:
throw new Error(`Operation system, ${process.platform}, is not supported yet.`);
}
await exec(runCommand, undefined, { silent });
},
getLinuxCommand(image, parameters): string {
const {
actionFolder,
editorVersion,
@ -28,51 +43,125 @@ const Docker = {
testMode === 'all' ? ['playmode', 'editmode', 'COMBINE_RESULTS'] : [testMode]
).join(';');
const command = `docker run \
--workdir /github/workspace \
--rm \
--env UNITY_LICENSE \
--env UNITY_LICENSE_FILE \
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
--env UNITY_SERIAL \
--env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
--env TEST_PLATFORMS="${testPlatforms}" \
--env COVERAGE_OPTIONS="${coverageOptions}" \
--env COVERAGE_RESULTS_PATH="CodeCoverage" \
--env ARTIFACTS_PATH="${artifactsPath}" \
--env GITHUB_REF \
--env GITHUB_SHA \
--env GITHUB_REPOSITORY \
--env GITHUB_ACTOR \
--env GITHUB_WORKFLOW \
--env GITHUB_HEAD_REF \
--env GITHUB_BASE_REF \
--env GITHUB_EVENT_NAME \
--env GITHUB_WORKSPACE=/github/workspace \
--env GITHUB_ACTION \
--env GITHUB_EVENT_PATH \
--env RUNNER_OS \
--env RUNNER_TOOL_CACHE \
--env RUNNER_TEMP \
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--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} \
/bin/bash /entrypoint.sh`;
return `docker run \
--workdir /github/workspace \
--rm \
--env UNITY_LICENSE \
--env UNITY_LICENSE_FILE \
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
--env UNITY_SERIAL \
--env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
--env TEST_PLATFORMS="${testPlatforms}" \
--env COVERAGE_OPTIONS="${coverageOptions}" \
--env COVERAGE_RESULTS_PATH="CodeCoverage" \
--env ARTIFACTS_PATH="${artifactsPath}" \
--env GITHUB_REF \
--env GITHUB_SHA \
--env GITHUB_REPOSITORY \
--env GITHUB_ACTOR \
--env GITHUB_WORKFLOW \
--env GITHUB_HEAD_REF \
--env GITHUB_BASE_REF \
--env GITHUB_EVENT_NAME \
--env GITHUB_WORKSPACE="/github/workspace" \
--env GITHUB_ACTION \
--env GITHUB_EVENT_PATH \
--env RUNNER_OS \
--env RUNNER_TOOL_CACHE \
--env RUNNER_TEMP \
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--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} \
/bin/bash -c /entrypoint.sh`;
},
await exec(command, undefined, { silent });
getWindowsCommand(image, parameters): string {
const {
actionFolder,
editorVersion,
workspace,
projectPath,
customParameters,
testMode,
coverageOptions,
artifactsPath,
useHostNetwork,
sshAgent,
gitPrivateToken,
githubToken,
runnerTemporaryPath,
} = parameters;
const githubHome = path.join(runnerTemporaryPath, '_github_home');
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(';');
return `docker run \
--workdir /github/workspace \
--rm \
--env UNITY_LICENSE \
--env UNITY_LICENSE_FILE \
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
--env UNITY_SERIAL \
--env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
--env TEST_PLATFORMS="${testPlatforms}" \
--env COVERAGE_OPTIONS="${coverageOptions}" \
--env COVERAGE_RESULTS_PATH="CodeCoverage" \
--env ARTIFACTS_PATH="${artifactsPath}" \
--env GITHUB_REF \
--env GITHUB_SHA \
--env GITHUB_REPOSITORY \
--env GITHUB_ACTOR \
--env GITHUB_WORKFLOW \
--env GITHUB_HEAD_REF \
--env GITHUB_BASE_REF \
--env GITHUB_EVENT_NAME \
--env GITHUB_WORKSPACE="/github/workspace" \
--env GITHUB_ACTION \
--env GITHUB_EVENT_PATH \
--env RUNNER_OS \
--env RUNNER_TOOL_CACHE \
--env RUNNER_TEMP \
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
${sshAgent ? '--env SSH_AUTH_SOCK=c:/ssh-agent' : ''} \
--volume "${githubHome}":"c:/root" \
--volume "${githubWorkflow}":"c:/github/workflow" \
--volume "${workspace}":"c:/github/workspace" \
--volume "${actionFolder}/steps":"c:/steps" \
--volume "${actionFolder}":"c:/dist" \
${sshAgent ? `--volume ${sshAgent}:c:/ssh-agent` : ''} \
${
sshAgent
? `--volume c:/Users/Administrator/.ssh/known_hosts:c:/root/.ssh/known_hosts`
: ''
} \
${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${image} \
powershell c:/dist/entrypoint.ps1`;
},
};

View File

@ -13,7 +13,7 @@ class ImageTag {
constructor(imageProperties) {
const {
editorVersion = '2019.2.11f1',
targetPlatform = Platform.types.StandaloneLinux64,
targetPlatform = ImageTag.getImagePlatformType(process.platform),
customImage,
} = imageProperties;
@ -43,7 +43,7 @@ class ImageTag {
generic: '',
webgl: 'webgl',
mac: 'mac-mono',
windows: 'windows-mono',
windows: 'windows-il2cpp',
linux: 'base',
linuxIl2cpp: 'linux-il2cpp',
android: 'android',
@ -56,8 +56,25 @@ class ImageTag {
switch (platform) {
case 'linux':
return 'ubuntu';
case 'win32':
return 'windows';
default:
throw new Error('The Operating System of this runner is not yet supported.');
throw new Error(
`The Operating System of this runner, "${platform}", is not yet supported.`,
);
}
}
static getImagePlatformType(platform) {
switch (platform) {
case 'linux':
return Platform.types.StandaloneLinux64;
case 'win32':
return Platform.types.StandaloneWindows;
default:
throw new Error(
`The Operating System of this runner, "${platform}", is not yet supported.`,
);
}
}

View File

@ -114,6 +114,24 @@ describe('ResultsParser', () => {
expect(result.annotation).toBeUndefined();
});
test('no cdata in stack trace', () => {
const result = ResultsParser.convertTestCase('Test Suite', {
_attributes: {
name: 'Test Name',
duration: '3.14',
},
failure: {
message: { _cdata: 'Message CDATA' },
'stack-trace': {},
},
});
expect(result.suite).toBe('Test Suite');
expect(result.title).toBe('Test Name');
expect(result.duration).toBe(3.14);
expect(result.annotation).toBeUndefined();
});
test('no annotation path', () => {
const result = ResultsParser.convertTestCase('Test Suite', {
_attributes: {

View File

@ -90,6 +90,10 @@ const ResultsParser = {
}
const trace = failure['stack-trace']._cdata;
if (trace === undefined) {
core.warning(`No cdata in stack trace for test case: ${fullname}`);
return testMeta;
}
const point = ResultsParser.findAnnotationPoint(trace);
if (!point.path || !point.line) {
core.warning(`Not able to find annotation point for failed test! Test trace: ${trace}`);