unity-builder/src/model/input.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

import Platform from './platform';
import ValidationError from './error/validation-error';
2019-12-22 14:05:15 +00:00
const core = require('@actions/core');
const versioningStrategies = ['None', 'Semantic', 'Tag', 'Custom'];
class Input {
2019-12-22 14:05:15 +00:00
static getFromUser() {
// Input variables specified in workflows using "with" prop.
const unityVersion = core.getInput('unityVersion');
const targetPlatform = core.getInput('targetPlatform') || Platform.default;
const rawProjectPath = core.getInput('projectPath') || '.';
const buildName = core.getInput('buildName') || targetPlatform;
const buildsPath = core.getInput('buildsPath') || 'build';
const buildMethod = core.getInput('buildMethod'); // processed in docker file
const versioning = core.getInput('versioning') || 'Semantic';
const version = core.getInput('version') || '';
2020-01-27 18:39:49 +00:00
const customParameters = core.getInput('customParameters') || '';
2019-12-22 14:05:15 +00:00
// Sanitise input
const projectPath = rawProjectPath.replace(/\/$/, '');
// Validate input
if (!versioningStrategies.includes(versioning)) {
throw new ValidationError(
`Versioning strategy should be one of ${versioningStrategies.join(', ')}.`,
);
}
// Return sanitised input
2019-12-22 14:05:15 +00:00
return {
unityVersion,
targetPlatform,
2019-12-22 14:05:15 +00:00
projectPath,
buildName,
buildsPath,
buildMethod,
versioning,
version,
2020-01-27 18:39:49 +00:00
customParameters,
2019-12-22 14:05:15 +00:00
};
}
}
export default Input;