Get unityVersion from ProjectVersion.txt (#84)
parent
a067c3d5ab
commit
0c3e710069
|
@ -4,8 +4,8 @@ description: 'Run tests for any Unity project.'
|
|||
inputs:
|
||||
unityVersion:
|
||||
required: false
|
||||
default: '2019.2.11f1'
|
||||
description: 'Version of unity to use for testing the project.'
|
||||
default: 'auto'
|
||||
description: 'Version of unity to use for testing the project. Use "auto" to get from your ProjectSettings/ProjectVersion.txt'
|
||||
customImage:
|
||||
required: false
|
||||
default: ''
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
import ImageTag from './image-tag';
|
||||
|
||||
describe('UnityImageVersion', () => {
|
||||
describe('ImageTag', () => {
|
||||
describe('constructor', () => {
|
||||
const some = {
|
||||
name: 'someName',
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { getInput } from '@actions/core';
|
||||
import { includes } from 'lodash-es';
|
||||
import UnityVersionParser from './unity-version-parser';
|
||||
|
||||
class Input {
|
||||
static get testModes() {
|
||||
|
@ -14,7 +15,7 @@ class Input {
|
|||
|
||||
static getFromUser() {
|
||||
// Input variables specified in workflow using "with" prop.
|
||||
const unityVersion = getInput('unityVersion') || '2019.2.11f1';
|
||||
const rawUnityVersion = getInput('unityVersion') || 'auto';
|
||||
const customImage = getInput('customImage') || '';
|
||||
const testMode = getInput('testMode') || 'all';
|
||||
const rawProjectPath = getInput('projectPath') || '.';
|
||||
|
@ -43,6 +44,8 @@ class Input {
|
|||
const projectPath = rawProjectPath.replace(/\/$/, '');
|
||||
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
||||
const useHostNetwork = rawUseHostNetwork === 'true';
|
||||
const unityVersion =
|
||||
rawUnityVersion === 'auto' ? UnityVersionParser.read(projectPath) : rawUnityVersion;
|
||||
|
||||
// Return sanitised input
|
||||
return {
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
class UnityVersionParser {
|
||||
static get versionPattern() {
|
||||
return /20\d{2}\.\d\.\w{3,4}|3/;
|
||||
}
|
||||
|
||||
static parse(projectVersionTxt) {
|
||||
const matches = projectVersionTxt.match(UnityVersionParser.versionPattern);
|
||||
if (!matches || matches.length === 0) {
|
||||
throw new Error(`Failed to parse version from "${projectVersionTxt}".`);
|
||||
}
|
||||
return matches[0];
|
||||
}
|
||||
|
||||
static read(projectPath) {
|
||||
const filePath = path.join(projectPath, 'ProjectSettings', 'ProjectVersion.txt');
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return 'auto';
|
||||
}
|
||||
return UnityVersionParser.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
}
|
||||
}
|
||||
|
||||
export default UnityVersionParser;
|
|
@ -0,0 +1,25 @@
|
|||
import UnityVersionParser from './unity-version-parser';
|
||||
|
||||
describe('UnityVersionParser', () => {
|
||||
describe('parse', () => {
|
||||
it('throws for empty string', () => {
|
||||
expect(() => UnityVersionParser.parse('')).toThrow(Error);
|
||||
});
|
||||
|
||||
it('parses from ProjectVersion.txt', () => {
|
||||
const projectVersionContents = `m_EditorVersion: 2019.2.11f1
|
||||
m_EditorVersionWithRevision: 2019.2.11f1 (5f859a4cfee5)`;
|
||||
expect(UnityVersionParser.parse(projectVersionContents)).toBe('2019.2.11f1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('read', () => {
|
||||
it('does not throw', () => {
|
||||
expect(() => UnityVersionParser.read('')).not.toThrow();
|
||||
});
|
||||
|
||||
it('reads from unity-project-with-correct-tests', () => {
|
||||
expect(UnityVersionParser.read('./unity-project-with-correct-tests')).toBe('2019.2.11f1');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue