feat: upgrade to images of version 1 (rolling tag) (#179)
* feat: upgrade to images of version 1 (rolling tag) * fix: broken husky hookpull/180/head v2.0.0
parent
50a3bd4138
commit
67402dce6f
|
@ -8,4 +8,6 @@ fi
|
|||
yarn lint-staged
|
||||
yarn lint
|
||||
yarn test
|
||||
|
||||
yarn build
|
||||
git add dist
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
11
src/index.ts
11
src/index.ts
|
@ -7,7 +7,7 @@ async function run() {
|
|||
|
||||
const { workspace, actionFolder } = Action;
|
||||
const {
|
||||
unityVersion,
|
||||
editorVersion,
|
||||
customImage,
|
||||
projectPath,
|
||||
customParameters,
|
||||
|
@ -19,13 +19,13 @@ async function run() {
|
|||
githubToken,
|
||||
checkName,
|
||||
} = Input.getFromUser();
|
||||
const baseImage = new ImageTag({ version: unityVersion, customImage });
|
||||
const runnerTempPath = process.env.RUNNER_TEMP;
|
||||
const baseImage = new ImageTag({ editorVersion, customImage });
|
||||
const runnerTemporaryPath = process.env.RUNNER_TEMP;
|
||||
|
||||
try {
|
||||
await Docker.run(baseImage, {
|
||||
actionFolder,
|
||||
unityVersion,
|
||||
editorVersion,
|
||||
workspace,
|
||||
projectPath,
|
||||
customParameters,
|
||||
|
@ -35,10 +35,9 @@ async function run() {
|
|||
sshAgent,
|
||||
gitPrivateToken,
|
||||
githubToken,
|
||||
runnerTempPath,
|
||||
runnerTemporaryPath,
|
||||
});
|
||||
} finally {
|
||||
// Set output
|
||||
await Output.setArtifactsPath(artifactsPath);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ const Docker = {
|
|||
async run(image, parameters, silent = false) {
|
||||
const {
|
||||
actionFolder,
|
||||
unityVersion,
|
||||
editorVersion,
|
||||
workspace,
|
||||
projectPath,
|
||||
customParameters,
|
||||
|
@ -16,12 +16,12 @@ const Docker = {
|
|||
sshAgent,
|
||||
gitPrivateToken,
|
||||
githubToken,
|
||||
runnerTempPath,
|
||||
runnerTemporaryPath,
|
||||
} = parameters;
|
||||
|
||||
const githubHome = path.join(runnerTempPath, '_github_home');
|
||||
const githubHome = path.join(runnerTemporaryPath, '_github_home');
|
||||
if (!existsSync(githubHome)) mkdirSync(githubHome);
|
||||
const githubWorkflow = path.join(runnerTempPath, '_github_workflow');
|
||||
const githubWorkflow = path.join(runnerTemporaryPath, '_github_workflow');
|
||||
if (!existsSync(githubWorkflow)) mkdirSync(githubWorkflow);
|
||||
|
||||
const command = `docker run \
|
||||
|
@ -32,7 +32,7 @@ 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}" \
|
||||
|
|
|
@ -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`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ 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') || '';
|
||||
|
@ -47,12 +47,12 @@ const Input = {
|
|||
const projectPath = rawProjectPath.replace(/\/$/, '');
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue