Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update windows images and add docker parameters #244

Merged
merged 2 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ inputs:
required: false
default: ''
description: 'User and optionally group (user or user:group or uid:gid) to give ownership of the resulting build artifacts'
dockerCpuLimit:
required: false
default: ''
description: 'Number of CPU cores to assign the docker container. Defaults to all available cores on all platforms.'
dockerMemoryLimit:
required: false
default: ''
description:
'Amount of memory to assign the docker container. Defaults to 95% of total system memory rounded down to the
nearest megabyte on Linux and 80% on Windows. On unrecognized platforms, defaults to 75% of total system memory.
To manually specify a value, use the format <number><unit>, where unit is either m or g. ie: 512m = 512 megabytes'
dockerIsolationMode:
required: false
default: 'default'
description:
'Isolation mode to use for the docker container. Can be one of process, hyperv, or default. Default will pick the
default mode as described by Microsoft where server versions use process and desktop versions use hyperv. Only
applicable on Windows'
unityLicensingServer:
required: false
default: ''
Expand Down
2,407 changes: 1,218 additions & 1,189 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ module.exports = {
'^.+\\.ts$': 'ts-jest',
},
verbose: true,
modulePathIgnorePatterns: ['<rootDir>/lib/', '<rootDir>/dist/'],
setupFilesAfterEnv: ['<rootDir>/src/jest.setup.ts'],
};
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unity-test-runner",
"version": "2.0.0",
"version": "3.0.0",
"description": "Run tests for any Unity project.",
"main": "dist/index.js",
"repository": "git@github.com:game-ci/unity-test-runner.git",
Expand All @@ -24,7 +24,7 @@
},
"devDependencies": {
"@types/jest": "^26.0.15",
"@types/node": "^14.14.9",
"@types/node": "^20.8.10",
"@types/semver": "^7.3.5",
"@typescript-eslint/parser": "^5.9.0",
"@vercel/ncc": "^0.33.1",
Expand All @@ -37,11 +37,14 @@
"husky": "^7.0.4",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"jest-fail-on-console": "^3.0.2",
"js-yaml": "^3.14.0",
"lint-staged": "^12.1.2",
"prettier": "^2.2.1",
"ts-jest": "^26.4.4",
"typescript": "^4.1.5"
"ts-node": "10.4.0",
"typescript": "^4.1.5",
"yarn-audit-fix": "^9.3.8"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand Down
9 changes: 9 additions & 0 deletions src/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import failOnConsole from 'jest-fail-on-console';

// Fail when console logs something inside a test - use spyOn instead
failOnConsole({
shouldFailOnWarn: true,
shouldFailOnError: true,
shouldFailOnLog: true,
shouldFailOnAssert: true,
});
6 changes: 6 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export async function run() {
packageMode,
packageName,
chownFilesTo,
dockerCpuLimit,
dockerMemoryLimit,
dockerIsolationMode,
unityLicensingServer,
} = Input.getFromUser();
const baseImage = new ImageTag({ editorVersion, customImage });
Expand All @@ -46,6 +49,9 @@ export async function run() {
gitPrivateToken,
githubToken,
chownFilesTo,
dockerCpuLimit,
dockerMemoryLimit,
dockerIsolationMode,
unityLicensingServer,
...runnerContext,
});
Expand Down
10 changes: 10 additions & 0 deletions src/model/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const Docker = {
githubToken,
runnerTemporaryPath,
chownFilesTo,
dockerCpuLimit,
dockerMemoryLimit,
unityLicensingServer,
} = parameters;

Expand Down Expand Up @@ -126,6 +128,8 @@ const Docker = {
--volume "${actionFolder}/steps:/steps:z" \
--volume "${actionFolder}/entrypoint.sh:/entrypoint.sh:z" \
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
--cpus=${dockerCpuLimit} \
--memory=${dockerMemoryLimit} \
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
${
sshAgent && !sshPublicKeysDirectoryPath
Expand Down Expand Up @@ -161,6 +165,9 @@ const Docker = {
githubToken,
runnerTemporaryPath,
chownFilesTo,
dockerCpuLimit,
dockerMemoryLimit,
dockerIsolationMode,
unityLicensingServer,
} = parameters;

Expand Down Expand Up @@ -222,6 +229,9 @@ const Docker = {
? `--volume c:/Users/Administrator/.ssh/known_hosts:c:/root/.ssh/known_hosts`
: ''
} \
--cpus=${dockerCpuLimit} \
--memory=${dockerMemoryLimit} \
--isolation=${dockerIsolationMode} \
${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${image} \
Expand Down
6 changes: 3 additions & 3 deletions src/model/image-tag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('ImageTag', () => {
targetPlatform: some.targetPlatform,
});

expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2099.1.1111-2`);
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2099.1.1111-3`);
});
it('returns customImage if given', () => {
const image = new ImageTag({
Expand All @@ -65,13 +65,13 @@ describe('ImageTag', () => {
it('returns the specific build platform', () => {
const image = new ImageTag({ editorVersion: '2022.3.7f1', targetPlatform: 'WebGL' });

expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2022.3.7f1-webgl-2`);
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2022.3.7f1-webgl-3`);
});

it('returns no specific build platform for generic targetPlatforms', () => {
const image = new ImageTag({ targetPlatform: 'NoTarget' });

expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2022.3.7f1-2`);
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2022.3.7f1-3`);
});
});
});
2 changes: 1 addition & 1 deletion src/model/image-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ImageTag {
this.targetPlatform = targetPlatform;
this.targetPlatformSuffix = ImageTag.getTargetPlatformSuffix(targetPlatform, editorVersion);
this.imagePlatformPrefix = ImageTag.getImagePlatformPrefix(process.platform);
this.imageRollingVersion = 2;
this.imageRollingVersion = 3;
}

static get versionPattern() {
Expand Down
22 changes: 22 additions & 0 deletions src/model/input.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import UnityVersionParser from './unity-version-parser';
import fs from 'fs';
import { getInput } from '@actions/core';
import os from 'os';

const Input = {
get testModes() {
Expand Down Expand Up @@ -85,6 +86,24 @@ const Input = {
const rawPackageMode = getInput('packageMode') || 'false';
let packageName = '';
const chownFilesTo = getInput('chownFilesTo') || '';
const dockerCpuLimit = getInput('dockerCpuLimit') || os.cpus().length.toString();
const bytesInMegabyte = 1024 * 1024;
let memoryMultiplier;
switch (os.platform()) {
case 'linux':
memoryMultiplier = 0.95;
break;
case 'win32':
memoryMultiplier = 0.8;
break;
default:
memoryMultiplier = 0.75;
break;
}
const dockerMemoryLimit =
getInput('dockerMemoryLimit') ||
`${Math.floor((os.totalmem() / bytesInMegabyte) * memoryMultiplier)}m`;
const dockerIsolationMode = getInput('dockerIsolationMode') || 'default';

// Validate input
if (!this.testModes.includes(testMode)) {
Expand Down Expand Up @@ -159,6 +178,9 @@ const Input = {
packageMode,
packageName,
chownFilesTo,
dockerCpuLimit,
dockerMemoryLimit,
dockerIsolationMode,
unityLicensingServer,
};
},
Expand Down
Loading
Loading