Refactor action to typescript (#226)
* Refactor to typescript (config part) * Refactor to typescript (convert extensions, minor fixes) * Refactor to typescript (move from `action` to `dist`) * Re-enable integrity-check for dist index.js * Fix all tests and lints * fix parsing major versions * Test patch level to be digits only * debug * debug * uncache * manual compile * debug * debug * Debug * Build lib - doh * remove diff check * Make kubernetes workflow manual * Properly generate 3 digit for simple major tags * Remove ts-ignore * re-enable cache
This commit is contained in:
33
src/model/unity-versioning.ts
Normal file
33
src/model/unity-versioning.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export default class UnityVersioning {
|
||||
static get versionPattern() {
|
||||
return /20\d{2}\.\d\.\w{3,4}|3/;
|
||||
}
|
||||
|
||||
static determineUnityVersion(projectPath, unityVersion) {
|
||||
if (unityVersion === 'auto') {
|
||||
return UnityVersioning.read(projectPath);
|
||||
}
|
||||
return unityVersion;
|
||||
}
|
||||
|
||||
static read(projectPath) {
|
||||
const filePath = path.join(projectPath, 'ProjectSettings', 'ProjectVersion.txt');
|
||||
if (!fs.existsSync(filePath)) {
|
||||
core.warning(`Could not find "${filePath}", keeping unityVersion as "auto"`);
|
||||
return 'auto';
|
||||
}
|
||||
return UnityVersioning.parse(fs.readFileSync(filePath, 'utf8'));
|
||||
}
|
||||
|
||||
static parse(projectVersionTxt) {
|
||||
const matches = projectVersionTxt.match(UnityVersioning.versionPattern);
|
||||
if (!matches || matches.length === 0) {
|
||||
throw new Error(`Failed to parse version from "${projectVersionTxt}".`);
|
||||
}
|
||||
return matches[0];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user