Skip to content
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
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ inputs:
required: false
default: '2019.2.11f1'
description: 'Version of unity to use for building the project.'
customImage:
required: false
default: ''
description: 'Specific docker image that should be used to request activation file'
outputs:
filePath:
description: 'Path of the manual activation file'
Expand Down
2 changes: 1 addition & 1 deletion action/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"eslint-config-airbnb": "18.0.1",
"eslint-config-prettier": "6.10.0",
"eslint-plugin-flowtype": "4.6.0",
"eslint-plugin-import": "2.20.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-prettier": "3.1.2",
"eslint-plugin-react": "7.19.0",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ async function action() {
Action.checkCompatibility();

const { dockerfile, workspace, actionFolder } = Action;
const { unityVersion } = Input.getFromUser();
const baseImage = ImageTag.createForBase(unityVersion);
const { unityVersion, customImage } = Input.getFromUser();
const baseImage = ImageTag.createForBase({ version: unityVersion, customImage });

// Build docker image
const actionImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
Expand Down
12 changes: 8 additions & 4 deletions src/model/image-tag.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { trimStart } from 'lodash-es';

class ImageTag {
static createForBase(version) {
static createForBase({ version, customImage }) {
const repository = 'unityci';
const name = 'editor';
return new this({ repository, name, version });
return new this({ repository, name, version, customImage });
}

static createForAction(version) {
Expand All @@ -13,12 +13,12 @@ class ImageTag {
return new this({ repository, name, version });
}

constructor({ repository = '', name, version }) {
constructor({ repository = '', name, version, customImage }) {
if (!ImageTag.versionPattern.test(version)) {
throw new Error(`Invalid version "${version}".`);
}

Object.assign(this, { repository, name, version });
Object.assign(this, { repository, name, version, customImage });
}

static get versionPattern() {
Expand All @@ -34,6 +34,10 @@ class ImageTag {
}

toString() {
if (this.customImage && this.customImage !== '') {
return this.customImage;
}

return `${this.image}:${this.tag}-base-0`;
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/model/image-tag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ describe('UnityImageVersion', () => {

describe('toString', () => {
it('returns the correct version', () => {
const image = ImageTag.createForBase('2099.1.1111');
const image = ImageTag.createForBase({ version: '2099.1.1111' });

expect(image.toString()).toStrictEqual(`unityci/editor:2099.1.1111-base-0`);
});

it('returns customImage if given', () => {
const image = ImageTag.createForBase({
version: '2099.1.1111',
customImage: 'owner/image:3099.2.2111',
});

expect(image.toString()).toStrictEqual('owner/image:3099.2.2111');
});
});
});
2 changes: 2 additions & 0 deletions src/model/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ class Input {
static getFromUser() {
// Input variables specified in workflow using "with" prop.
const unityVersion = core.getInput('unityVersion') || '2019.2.11f1';
const customImage = core.getInput('customImage') || '';

// Return sanitised input
return {
unityVersion,
customImage,
};
}
}
Expand Down
29 changes: 29 additions & 0 deletions src/model/input.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import * as core from '@actions/core';

import Input from './input';

afterEach(() => {
jest.restoreAllMocks();
});

describe('Input', () => {
describe('getFromUser', () => {
it('does not throw', () => {
Expand All @@ -10,4 +16,27 @@ describe('Input', () => {
expect(typeof Input.getFromUser()).toStrictEqual('object');
});
});

describe('unityVersion', () => {
it('returns the default value', () => {
expect(Input.getFromUser().unityVersion).toStrictEqual('2019.2.11f1');
});

it('takes input from the users workflow', () => {
const mockValue = '2020.4.99f9';
jest.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.getFromUser().unityVersion).toStrictEqual(mockValue);
});
});
describe('customImage', () => {
it('returns the default value', () => {
expect(Input.getFromUser().customImage).toStrictEqual('');
});

it('takes input from the users workflow', () => {
const mockValue = 'owner/image:2020.4.99f9';
jest.spyOn(core, 'getInput').mockReturnValue(mockValue);
expect(Input.getFromUser().customImage).toStrictEqual(mockValue);
});
});
});