2020-01-20 23:06:14 +00:00
|
|
|
import Platform from './platform';
|
2022-04-03 15:59:14 +00:00
|
|
|
import BuildParameters from './build-parameters';
|
2019-12-22 14:05:15 +00:00
|
|
|
|
2020-01-20 23:06:14 +00:00
|
|
|
class ImageTag {
|
2021-03-13 23:44:01 +00:00
|
|
|
public repository: string;
|
|
|
|
public name: string;
|
2022-04-03 15:59:14 +00:00
|
|
|
public editorVersion: string;
|
|
|
|
public targetPlatform: any;
|
2021-03-13 23:44:01 +00:00
|
|
|
public builderPlatform: string;
|
|
|
|
public customImage: any;
|
2022-04-03 15:59:14 +00:00
|
|
|
public imageRollingVersion: number;
|
|
|
|
public imagePlatformPrefix: string;
|
2021-03-13 23:44:01 +00:00
|
|
|
|
2022-04-03 15:59:14 +00:00
|
|
|
constructor(imageProperties: Partial<BuildParameters>) {
|
|
|
|
const { editorVersion = '2019.2.11f1', targetPlatform, customImage } = imageProperties;
|
2019-12-22 14:05:15 +00:00
|
|
|
|
2022-04-03 15:59:14 +00:00
|
|
|
if (!ImageTag.versionPattern.test(editorVersion)) {
|
|
|
|
throw new Error(`Invalid version "${editorVersion}".`);
|
2019-12-22 14:05:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 15:59:14 +00:00
|
|
|
// Todo we might as well skip this class for customImage.
|
|
|
|
// Either
|
2021-03-13 23:44:01 +00:00
|
|
|
this.customImage = customImage;
|
2022-04-03 15:59:14 +00:00
|
|
|
|
|
|
|
// Or
|
|
|
|
this.repository = 'unityci';
|
|
|
|
this.name = 'editor';
|
|
|
|
this.editorVersion = editorVersion;
|
|
|
|
this.targetPlatform = targetPlatform;
|
|
|
|
this.builderPlatform = ImageTag.getTargetPlatformToTargetPlatformSuffixMap(targetPlatform, editorVersion);
|
|
|
|
this.imagePlatformPrefix = ImageTag.getImagePlatformPrefixes(process.platform);
|
|
|
|
this.imageRollingVersion = 1; // will automatically roll to the latest non-breaking version.
|
2019-12-22 14:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static get versionPattern() {
|
2019-12-22 20:15:09 +00:00
|
|
|
return /^20\d{2}\.\d\.\w{3,4}|3$/;
|
2019-12-22 14:05:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-03 15:59:14 +00:00
|
|
|
static get targetPlatformSuffixes() {
|
2019-12-22 14:05:15 +00:00
|
|
|
return {
|
|
|
|
generic: '',
|
|
|
|
webgl: 'webgl',
|
2020-10-24 06:43:29 +00:00
|
|
|
mac: 'mac-mono',
|
|
|
|
windows: 'windows-mono',
|
2022-01-25 21:18:15 +00:00
|
|
|
windowsIl2cpp: 'windows-il2cpp',
|
|
|
|
wsaPlayer: 'universal-windows-platform',
|
2020-10-24 07:39:01 +00:00
|
|
|
linux: 'base',
|
2020-11-13 23:57:44 +00:00
|
|
|
linuxIl2cpp: 'linux-il2cpp',
|
2019-12-22 14:05:15 +00:00
|
|
|
android: 'android',
|
|
|
|
ios: 'ios',
|
2022-01-25 21:18:15 +00:00
|
|
|
tvos: 'appletv',
|
2020-01-07 23:39:53 +00:00
|
|
|
facebook: 'facebook',
|
2019-12-22 14:05:15 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-03 15:59:14 +00:00
|
|
|
static getImagePlatformPrefixes(platform) {
|
|
|
|
switch (platform) {
|
|
|
|
case 'win32':
|
|
|
|
return 'windows';
|
|
|
|
case 'linux':
|
|
|
|
return 'ubuntu';
|
|
|
|
default:
|
|
|
|
throw new Error('The Operating System of this runner is not yet supported.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static getTargetPlatformToTargetPlatformSuffixMap(platform, version) {
|
2022-02-28 11:30:59 +00:00
|
|
|
const { generic, webgl, mac, windows, windowsIl2cpp, wsaPlayer, linux, linuxIl2cpp, android, ios, tvos, facebook } =
|
2022-04-03 15:59:14 +00:00
|
|
|
ImageTag.targetPlatformSuffixes;
|
2019-12-22 14:05:15 +00:00
|
|
|
|
2020-11-17 23:51:10 +00:00
|
|
|
const [major, minor] = version.split('.').map((digit) => Number(digit));
|
2020-10-24 06:43:29 +00:00
|
|
|
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
|
2020-11-13 23:57:44 +00:00
|
|
|
switch (platform) {
|
|
|
|
case Platform.types.StandaloneOSX:
|
|
|
|
return mac;
|
|
|
|
case Platform.types.StandaloneWindows:
|
|
|
|
case Platform.types.StandaloneWindows64:
|
2022-01-25 21:18:15 +00:00
|
|
|
// Can only build windows-il2cpp on a windows based system
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
// Unity versions before 2019.3 do not support il2cpp
|
|
|
|
if (major >= 2020 || (major === 2019 && minor >= 3)) {
|
|
|
|
return windowsIl2cpp;
|
|
|
|
} else {
|
|
|
|
throw new Error(`Windows-based builds are only supported on 2019.3.X+ versions of Unity.
|
|
|
|
If you are trying to build for windows-mono, please use a Linux based OS.`);
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 23:57:44 +00:00
|
|
|
return windows;
|
|
|
|
case Platform.types.StandaloneLinux64: {
|
|
|
|
// Unity versions before 2019.3 do not support il2cpp
|
|
|
|
if (major >= 2020 || (major === 2019 && minor >= 3)) {
|
|
|
|
return linuxIl2cpp;
|
|
|
|
}
|
|
|
|
return linux;
|
|
|
|
}
|
|
|
|
case Platform.types.iOS:
|
|
|
|
return ios;
|
|
|
|
case Platform.types.Android:
|
|
|
|
return android;
|
|
|
|
case Platform.types.WebGL:
|
|
|
|
return webgl;
|
|
|
|
case Platform.types.WSAPlayer:
|
2022-01-25 21:18:15 +00:00
|
|
|
if (process.platform !== 'win32') {
|
|
|
|
throw new Error(`WSAPlayer can only be built on a windows base OS`);
|
|
|
|
}
|
|
|
|
return wsaPlayer;
|
2020-11-13 23:57:44 +00:00
|
|
|
case Platform.types.PS4:
|
|
|
|
return windows;
|
|
|
|
case Platform.types.XboxOne:
|
|
|
|
return windows;
|
|
|
|
case Platform.types.tvOS:
|
2022-01-25 21:18:15 +00:00
|
|
|
if (process.platform !== 'win32') {
|
|
|
|
throw new Error(`tvOS can only be built on a windows base OS`);
|
|
|
|
}
|
|
|
|
return tvos;
|
2020-11-13 23:57:44 +00:00
|
|
|
case Platform.types.Switch:
|
|
|
|
return windows;
|
2020-01-07 23:39:53 +00:00
|
|
|
// Unsupported
|
2020-11-13 23:57:44 +00:00
|
|
|
case Platform.types.Lumin:
|
|
|
|
return windows;
|
|
|
|
case Platform.types.BJM:
|
|
|
|
return windows;
|
|
|
|
case Platform.types.Stadia:
|
|
|
|
return windows;
|
|
|
|
case Platform.types.Facebook:
|
|
|
|
return facebook;
|
|
|
|
case Platform.types.NoTarget:
|
|
|
|
return generic;
|
|
|
|
|
2020-01-07 23:39:53 +00:00
|
|
|
// Test specific
|
2020-11-13 23:57:44 +00:00
|
|
|
case Platform.types.Test:
|
|
|
|
return generic;
|
|
|
|
default:
|
|
|
|
throw new Error(`
|
|
|
|
Platform must be one of the ones described in the documentation.
|
|
|
|
"${platform}" is currently not supported.`);
|
|
|
|
}
|
2019-12-22 14:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get tag() {
|
2022-04-03 15:59:14 +00:00
|
|
|
const versionAndPlatform = `${this.editorVersion}-${this.builderPlatform}`.replace(/-+$/, '');
|
|
|
|
|
|
|
|
return `${this.imagePlatformPrefix}-${versionAndPlatform}-${this.imageRollingVersion}`;
|
2019-12-22 14:05:15 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 17:07:55 +00:00
|
|
|
get image() {
|
2021-03-13 23:44:01 +00:00
|
|
|
return `${this.repository}/${this.name}`.replace(/^\/+/, '');
|
2019-12-22 17:07:55 +00:00
|
|
|
}
|
|
|
|
|
2019-12-22 14:05:15 +00:00
|
|
|
toString() {
|
2021-03-13 23:44:01 +00:00
|
|
|
const { image, tag, customImage } = this;
|
2019-12-22 14:05:15 +00:00
|
|
|
|
2022-04-03 15:59:14 +00:00
|
|
|
if (customImage) return customImage;
|
2020-09-18 16:41:31 +00:00
|
|
|
|
2022-04-03 15:59:14 +00:00
|
|
|
return `${image}:${tag}`; // '0' here represents the docker repo version
|
2019-12-22 14:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-20 23:06:14 +00:00
|
|
|
|
|
|
|
export default ImageTag;
|