feat: upgrade to images of version 1 (rolling tag)

pull/179/head
Webber 2022-04-03 17:11:46 +02:00
parent 50a3bd4138
commit 301fbaf78d
6 changed files with 1868 additions and 1850 deletions

3560
dist/index.js generated vendored

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ async function run() {
const { workspace, actionFolder } = Action; const { workspace, actionFolder } = Action;
const { const {
unityVersion, editorVersion,
customImage, customImage,
projectPath, projectPath,
customParameters, customParameters,
@ -19,13 +19,13 @@ async function run() {
githubToken, githubToken,
checkName, checkName,
} = Input.getFromUser(); } = Input.getFromUser();
const baseImage = new ImageTag({ version: unityVersion, customImage }); const baseImage = new ImageTag({ editorVersion, customImage });
const runnerTempPath = process.env.RUNNER_TEMP; const runnerTemporaryPath = process.env.RUNNER_TEMP;
try { try {
await Docker.run(baseImage, { await Docker.run(baseImage, {
actionFolder, actionFolder,
unityVersion, editorVersion,
workspace, workspace,
projectPath, projectPath,
customParameters, customParameters,
@ -35,10 +35,9 @@ async function run() {
sshAgent, sshAgent,
gitPrivateToken, gitPrivateToken,
githubToken, githubToken,
runnerTempPath, runnerTemporaryPath,
}); });
} finally { } finally {
// Set output
await Output.setArtifactsPath(artifactsPath); await Output.setArtifactsPath(artifactsPath);
} }

View File

@ -6,7 +6,7 @@ const Docker = {
async run(image, parameters, silent = false) { async run(image, parameters, silent = false) {
const { const {
actionFolder, actionFolder,
unityVersion, editorVersion,
workspace, workspace,
projectPath, projectPath,
customParameters, customParameters,
@ -16,12 +16,12 @@ const Docker = {
sshAgent, sshAgent,
gitPrivateToken, gitPrivateToken,
githubToken, githubToken,
runnerTempPath, runnerTemporaryPath,
} = parameters; } = parameters;
const githubHome = path.join(runnerTempPath, '_github_home'); const githubHome = path.join(runnerTemporaryPath, '_github_home');
if (!existsSync(githubHome)) mkdirSync(githubHome); if (!existsSync(githubHome)) mkdirSync(githubHome);
const githubWorkflow = path.join(runnerTempPath, '_github_workflow'); const githubWorkflow = path.join(runnerTemporaryPath, '_github_workflow');
if (!existsSync(githubWorkflow)) mkdirSync(githubWorkflow); if (!existsSync(githubWorkflow)) mkdirSync(githubWorkflow);
const command = `docker run \ const command = `docker run \
@ -32,7 +32,7 @@ const Docker = {
--env UNITY_EMAIL \ --env UNITY_EMAIL \
--env UNITY_PASSWORD \ --env UNITY_PASSWORD \
--env UNITY_SERIAL \ --env UNITY_SERIAL \
--env UNITY_VERSION="${unityVersion}" \ --env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \ --env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \ --env CUSTOM_PARAMETERS="${customParameters}" \
--env TEST_MODE="${testMode}" \ --env TEST_MODE="${testMode}" \

View File

@ -1,11 +1,11 @@
import ImageTag from './image-tag'; import ImageTag from './image-tag';
jest.spyOn(ImageTag, 'getImagePlatformPrefix').mockReturnValue('ubuntu');
describe('ImageTag', () => { describe('ImageTag', () => {
const some = { const some = {
repository: 'test1', editorVersion: '2099.9.f9f9',
name: 'test2', targetPlatform: 'Test',
version: '2099.9.f9f9',
platform: 'Test',
builderPlatform: '', builderPlatform: '',
}; };
@ -17,40 +17,45 @@ describe('ImageTag', () => {
describe('constructor', () => { describe('constructor', () => {
it('can be called', () => { it('can be called', () => {
const { platform } = some; const { targetPlatform } = some;
expect(() => new ImageTag({ platform })).not.toThrow(); expect(() => new ImageTag({ platform: targetPlatform })).not.toThrow();
}); });
it('accepts parameters and sets the right properties', () => { it('accepts parameters and sets the right properties', () => {
const image = new ImageTag(some); const image = new ImageTag(some);
expect(image.repository).toStrictEqual(some.repository); expect(image.repository).toStrictEqual('unityci');
expect(image.name).toStrictEqual(some.name); expect(image.name).toStrictEqual('editor');
expect(image.version).toStrictEqual(some.version); expect(image.editorVersion).toStrictEqual(some.editorVersion);
expect(image.platform).toStrictEqual(some.platform); expect(image.targetPlatform).toStrictEqual(some.targetPlatform);
expect(image.builderPlatform).toStrictEqual(some.builderPlatform); expect(image.targetPlatformSuffix).toStrictEqual(some.builderPlatform);
}); });
test.each(['2000.0.0f0', '2011.1.11f1'])('accepts %p version format', version => { test.each(['2000.0.0f0', '2011.1.11f1'])('accepts %p version format', editorVersion => {
expect(() => new ImageTag({ version, platform: some.platform })).not.toThrow(); expect(
() => new ImageTag({ editorVersion, targetPlatform: some.targetPlatform }),
).not.toThrow();
}); });
test.each(['some version', '', 1])('throws for incorrect versions %p', version => { test.each(['some version', '', 1])('throws for incorrect versions %p', editorVersion => {
const { platform } = some; const { targetPlatform } = some;
expect(() => new ImageTag({ version, platform })).toThrow(); expect(() => new ImageTag({ editorVersion, targetPlatform })).toThrow();
}); });
}); });
describe('toString', () => { describe('toString', () => {
it('returns the correct version', () => { 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', () => { it('returns customImage if given', () => {
const image = new ImageTag({ const image = new ImageTag({
version: '2099.1.1111', editorVersion: '2099.1.1111',
platform: some.platform, targetPlatform: some.targetPlatform,
customImage: `${defaults.image}:2099.1.1111@347598437689743986`, customImage: `${defaults.image}:2099.1.1111@347598437689743986`,
}); });
@ -58,15 +63,15 @@ describe('ImageTag', () => {
}); });
it('returns the specific build platform', () => { 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', () => { 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'; import Platform from './platform';
class ImageTag { class ImageTag {
public customImage?: string;
public repository: string; public repository: string;
public name: string; public name: string;
public version: string; public editorVersion: string;
public platform: any; public targetPlatform: string;
public builderPlatform: string; public targetPlatformSuffix: string;
public customImage: any; public imagePlatformPrefix: string;
public imageRollingVersion: number;
constructor(imageProperties) { constructor(imageProperties) {
const { const {
repository = 'unityci', editorVersion = '2019.2.11f1',
name = 'editor', targetPlatform = Platform.types.StandaloneLinux64,
version = '2019.2.11f1',
platform = Platform.types.StandaloneLinux64,
customImage, customImage,
} = imageProperties; } = imageProperties;
if (!ImageTag.versionPattern.test(version)) { if (!ImageTag.versionPattern.test(editorVersion)) {
throw new Error(`Invalid version "${version}".`); throw new Error(`Invalid version "${editorVersion}".`);
} }
const builderPlatform = ImageTag.getTargetPlatformToImageSuffixMap(platform, version); // Either
this.repository = repository;
this.name = name;
this.version = version;
this.platform = platform;
this.builderPlatform = builderPlatform;
this.customImage = customImage; 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() { static get versionPattern() {
return /^20\d{2}\.\d\.\w{3,4}|3$/; return /^20\d{2}\.\d\.\w{3,4}|3$/;
} }
static get imageSuffixes() { static get targetPlatformSuffixes() {
return { return {
generic: '', generic: '',
webgl: 'webgl', webgl: 'webgl',
@ -49,13 +52,22 @@ class ImageTag {
}; };
} }
static getTargetPlatformToImageSuffixMap(platform, version) { static getImagePlatformPrefix(platform) {
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
switch (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: case Platform.types.StandaloneOSX:
return mac; return mac;
case Platform.types.StandaloneWindows: case Platform.types.StandaloneWindows:
@ -103,12 +115,17 @@ class ImageTag {
default: default:
throw new Error(` throw new Error(`
Platform must be one of the ones described in the documentation. Platform must be one of the ones described in the documentation.
"${platform}" is currently not supported.`); "${targetPlatform}" is currently not supported.`);
} }
} }
get tag() { get tag() {
return `${this.version}-${this.builderPlatform}`.replace(/-+$/, ''); const versionAndTarget = `${this.editorVersion}-${this.targetPlatformSuffix}`.replace(
/-+$/,
'',
);
return `${this.imagePlatformPrefix}-${versionAndTarget}-${this.imageRollingVersion}`;
} }
get image() { get image() {
@ -118,12 +135,9 @@ class ImageTag {
toString() { toString() {
const { image, tag, customImage } = this; const { image, tag, customImage } = this;
if (customImage && customImage !== '') { if (customImage) return customImage;
return customImage;
}
const dockerRepoVersion = 0; return `${image}:${tag}`;
return `${image}:${tag}-${dockerRepoVersion}`;
} }
} }

View File

@ -14,7 +14,7 @@ const Input = {
getFromUser() { getFromUser() {
// Input variables specified in workflow using "with" prop. // Input variables specified in workflow using "with" prop.
const rawUnityVersion = getInput('unityVersion') || 'auto'; const unityVersion = getInput('unityVersion') || 'auto';
const customImage = getInput('customImage') || ''; const customImage = getInput('customImage') || '';
const rawProjectPath = getInput('projectPath') || '.'; const rawProjectPath = getInput('projectPath') || '.';
const customParameters = getInput('customParameters') || ''; const customParameters = getInput('customParameters') || '';
@ -47,12 +47,12 @@ const 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 = const editorVersion =
rawUnityVersion === 'auto' ? UnityVersionParser.read(projectPath) : rawUnityVersion; unityVersion === 'auto' ? UnityVersionParser.read(projectPath) : unityVersion;
// Return sanitised input // Return sanitised input
return { return {
unityVersion, editorVersion,
customImage, customImage,
projectPath, projectPath,
customParameters, customParameters,