Get unityVersion from ProjectVersion.txt (#84)

pull/87/head
David Finol 2020-12-28 05:02:31 -06:00 committed by GitHub
parent a067c3d5ab
commit 0c3e710069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 5 deletions

View File

@ -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

View File

@ -1,6 +1,6 @@
import ImageTag from './image-tag';
describe('UnityImageVersion', () => {
describe('ImageTag', () => {
describe('constructor', () => {
const some = {
name: 'someName',

View File

@ -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 {

View File

@ -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;

View File

@ -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');
});
});
});