mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-04 12:25:19 -04:00
allow versions with -alpha,-rc,-rc.0 .... + don't fail build on version cannot be determined (#196)
Closes #163
This commit is contained in:
parent
5b2e80e1a4
commit
56b9864426
File diff suppressed because one or more lines are too long
@ -67,10 +67,18 @@ export default class Versioning {
|
||||
/**
|
||||
* Regex to parse version description into separate fields
|
||||
*/
|
||||
static get descriptionRegex() {
|
||||
static get descriptionRegex1() {
|
||||
return /^v([\d.]+)-(\d+)-g(\w+)-?(\w+)*/g;
|
||||
}
|
||||
|
||||
static get descriptionRegex2() {
|
||||
return /^v([\d.]+-\w+)-(\d+)-g(\w+)-?(\w+)*/g;
|
||||
}
|
||||
|
||||
static get descriptionRegex3() {
|
||||
return /^v([\d.]+-\w+\.\d+)-(\d+)-g(\w+)-?(\w+)*/g;
|
||||
}
|
||||
|
||||
static async determineVersion(strategy, inputVersion) {
|
||||
// Validate input
|
||||
if (!Object.hasOwnProperty.call(this.strategies, strategy)) {
|
||||
@ -125,10 +133,16 @@ export default class Versioning {
|
||||
return version;
|
||||
}
|
||||
|
||||
const { tag, commits, hash } = await this.parseSemanticVersion();
|
||||
core.info(`Found semantic version ${tag}.${commits} for ${this.branch}@${hash}`);
|
||||
const versionDescriptor = await this.parseSemanticVersion();
|
||||
|
||||
return `${tag}.${commits}`;
|
||||
if (versionDescriptor) {
|
||||
const { tag, commits, hash } = versionDescriptor;
|
||||
core.info(`Found semantic version ${tag}.${commits} for ${this.branch}@${hash}`);
|
||||
return `${tag}.${commits}`;
|
||||
}
|
||||
const version = `0.0.${await this.getTotalNumberOfCommits()}`;
|
||||
core.info(`Generated version ${version} (semantic version couldn't be determined).`);
|
||||
return version;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,7 +165,7 @@ export default class Versioning {
|
||||
const description = await this.getVersionDescription();
|
||||
|
||||
try {
|
||||
const [match, tag, commits, hash] = this.descriptionRegex.exec(description);
|
||||
const [match, tag, commits, hash] = this.descriptionRegex1.exec(description);
|
||||
|
||||
return {
|
||||
match,
|
||||
@ -160,7 +174,32 @@ export default class Versioning {
|
||||
hash,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new Error(`Failed to parse git describe output: "${description}".`);
|
||||
try {
|
||||
const [match, tag, commits, hash] = this.descriptionRegex2.exec(description);
|
||||
|
||||
return {
|
||||
match,
|
||||
tag,
|
||||
commits,
|
||||
hash,
|
||||
};
|
||||
} catch (error_) {
|
||||
try {
|
||||
const [match, tag, commits, hash] = this.descriptionRegex3.exec(description);
|
||||
|
||||
return {
|
||||
match,
|
||||
tag,
|
||||
commits,
|
||||
hash,
|
||||
};
|
||||
} catch (error__) {
|
||||
core.warning(
|
||||
`Failed to parse git describe output or version can not be determined through: "${description}".`,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,22 +124,22 @@ describe('Versioning', () => {
|
||||
|
||||
describe('descriptionRegex', () => {
|
||||
it('is a valid regex', () => {
|
||||
expect(Versioning.descriptionRegex).toBeInstanceOf(RegExp);
|
||||
expect(Versioning.descriptionRegex1).toBeInstanceOf(RegExp);
|
||||
});
|
||||
|
||||
test.each(['v1.1-1-g12345678', 'v0.1-2-g12345678', 'v0.0-500-gA9B6C3D0-dirty'])(
|
||||
'is happy with valid %s',
|
||||
(description) => {
|
||||
expect(Versioning.descriptionRegex.test(description)).toBeTruthy();
|
||||
expect(Versioning.descriptionRegex1.test(description)).toBeTruthy();
|
||||
},
|
||||
);
|
||||
|
||||
test.each([undefined, 'v0', 'v0.1', 'v0.1.2', 'v0.1-2', 'v0.1-2-g'])(
|
||||
'does not like %s',
|
||||
(description) => {
|
||||
expect(Versioning.descriptionRegex.test(description)).toBeFalsy();
|
||||
expect(Versioning.descriptionRegex1.test(description)).toBeFalsy();
|
||||
// Also never expect without the v to work for any of these cases.
|
||||
expect(Versioning.descriptionRegex.test(description?.substr(1))).toBeFalsy();
|
||||
expect(Versioning.descriptionRegex1.test(description?.substr(1))).toBeFalsy();
|
||||
},
|
||||
);
|
||||
});
|
||||
@ -225,9 +225,7 @@ describe('Versioning', () => {
|
||||
it('throws when no match could be made', async () => {
|
||||
jest.spyOn(Versioning, 'getVersionDescription').mockResolvedValue('no-match-can-be-made');
|
||||
|
||||
await expect(Versioning.parseSemanticVersion()).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Failed to parse git describe output: \\"no-match-can-be-made\\"."`,
|
||||
);
|
||||
await expect(Versioning.parseSemanticVersion()).toMatchObject({});
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user