Skip to content

Commit 9ad344e

Browse files
authored
feat: support custom image (#54)
* fix: configuration for rule "import/no-cycle" is invalid airbnb/javascript#2331 (comment) * feat: support custom image
1 parent ae5a4d2 commit 9ad344e

File tree

8 files changed

+57
-9
lines changed

8 files changed

+57
-9
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ inputs:
66
required: false
77
default: '2019.2.11f1'
88
description: 'Version of unity to use for building the project.'
9+
customImage:
10+
required: false
11+
default: ''
12+
description: 'Specific docker image that should be used to request activation file'
913
outputs:
1014
filePath:
1115
description: 'Path of the manual activation file'

action/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"eslint-config-airbnb": "18.0.1",
2727
"eslint-config-prettier": "6.10.0",
2828
"eslint-plugin-flowtype": "4.6.0",
29-
"eslint-plugin-import": "2.20.1",
29+
"eslint-plugin-import": "^2.22.1",
3030
"eslint-plugin-jsx-a11y": "6.2.3",
3131
"eslint-plugin-prettier": "3.1.2",
3232
"eslint-plugin-react": "7.19.0",

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ async function action() {
66
Action.checkCompatibility();
77

88
const { dockerfile, workspace, actionFolder } = Action;
9-
const { unityVersion } = Input.getFromUser();
10-
const baseImage = ImageTag.createForBase(unityVersion);
9+
const { unityVersion, customImage } = Input.getFromUser();
10+
const baseImage = ImageTag.createForBase({ version: unityVersion, customImage });
1111

1212
// Build docker image
1313
const actionImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });

src/model/image-tag.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { trimStart } from 'lodash-es';
22

33
class ImageTag {
4-
static createForBase(version) {
4+
static createForBase({ version, customImage }) {
55
const repository = 'unityci';
66
const name = 'editor';
7-
return new this({ repository, name, version });
7+
return new this({ repository, name, version, customImage });
88
}
99

1010
static createForAction(version) {
@@ -13,12 +13,12 @@ class ImageTag {
1313
return new this({ repository, name, version });
1414
}
1515

16-
constructor({ repository = '', name, version }) {
16+
constructor({ repository = '', name, version, customImage }) {
1717
if (!ImageTag.versionPattern.test(version)) {
1818
throw new Error(`Invalid version "${version}".`);
1919
}
2020

21-
Object.assign(this, { repository, name, version });
21+
Object.assign(this, { repository, name, version, customImage });
2222
}
2323

2424
static get versionPattern() {
@@ -34,6 +34,10 @@ class ImageTag {
3434
}
3535

3636
toString() {
37+
if (this.customImage && this.customImage !== '') {
38+
return this.customImage;
39+
}
40+
3741
return `${this.image}:${this.tag}-base-0`;
3842
}
3943
}

src/model/image-tag.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ describe('UnityImageVersion', () => {
3030

3131
describe('toString', () => {
3232
it('returns the correct version', () => {
33-
const image = ImageTag.createForBase('2099.1.1111');
33+
const image = ImageTag.createForBase({ version: '2099.1.1111' });
3434

3535
expect(image.toString()).toStrictEqual(`unityci/editor:2099.1.1111-base-0`);
3636
});
37+
38+
it('returns customImage if given', () => {
39+
const image = ImageTag.createForBase({
40+
version: '2099.1.1111',
41+
customImage: 'owner/image:3099.2.2111',
42+
});
43+
44+
expect(image.toString()).toStrictEqual('owner/image:3099.2.2111');
45+
});
3746
});
3847
});

src/model/input.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ class Input {
44
static getFromUser() {
55
// Input variables specified in workflow using "with" prop.
66
const unityVersion = core.getInput('unityVersion') || '2019.2.11f1';
7+
const customImage = core.getInput('customImage') || '';
78

89
// Return sanitised input
910
return {
1011
unityVersion,
12+
customImage,
1113
};
1214
}
1315
}

src/model/input.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import * as core from '@actions/core';
2+
13
import Input from './input';
24

5+
afterEach(() => {
6+
jest.restoreAllMocks();
7+
});
8+
39
describe('Input', () => {
410
describe('getFromUser', () => {
511
it('does not throw', () => {
@@ -10,4 +16,27 @@ describe('Input', () => {
1016
expect(typeof Input.getFromUser()).toStrictEqual('object');
1117
});
1218
});
19+
20+
describe('unityVersion', () => {
21+
it('returns the default value', () => {
22+
expect(Input.getFromUser().unityVersion).toStrictEqual('2019.2.11f1');
23+
});
24+
25+
it('takes input from the users workflow', () => {
26+
const mockValue = '2020.4.99f9';
27+
jest.spyOn(core, 'getInput').mockReturnValue(mockValue);
28+
expect(Input.getFromUser().unityVersion).toStrictEqual(mockValue);
29+
});
30+
});
31+
describe('customImage', () => {
32+
it('returns the default value', () => {
33+
expect(Input.getFromUser().customImage).toStrictEqual('');
34+
});
35+
36+
it('takes input from the users workflow', () => {
37+
const mockValue = 'owner/image:2020.4.99f9';
38+
jest.spyOn(core, 'getInput').mockReturnValue(mockValue);
39+
expect(Input.getFromUser().customImage).toStrictEqual(mockValue);
40+
});
41+
});
1342
});

0 commit comments

Comments
 (0)