Properly generate 3 digit for simple major tags

pull/226/head
Webber 2021-03-13 23:31:08 +01:00
parent 9dbfe1d58d
commit 2c892a612e
4 changed files with 17 additions and 20 deletions

15
dist/index.js vendored
View File

@ -152,13 +152,7 @@ class AndroidVersioning {
return inputVersionCode; return inputVersionCode;
} }
static versionToVersionCode(version) { static versionToVersionCode(version) {
core.warning(version); const parsedVersion = semver.parse(version);
const [major, minor, patch] = version.split('.');
const threeDigitVersion = /^\d+$/.test(patch) ? version : `${major}.0.${minor}`;
core.warning(threeDigitVersion);
const parsedVersion = semver.parse(threeDigitVersion);
// @ts-ignore
core.warning(parsedVersion);
if (!parsedVersion) { if (!parsedVersion) {
core.warning(`Could not parse "${version}" to semver, defaulting android version code to 1`); core.warning(`Could not parse "${version}" to semver, defaulting android version code to 1`);
return 1; return 1;
@ -1483,8 +1477,11 @@ class Versioning {
const versionDescriptor = yield this.parseSemanticVersion(); const versionDescriptor = yield this.parseSemanticVersion();
if (versionDescriptor) { if (versionDescriptor) {
const { tag, commits, hash } = versionDescriptor; const { tag, commits, hash } = versionDescriptor;
core.info(`Found semantic version ${tag}.${commits} for ${this.branch}@${hash}`); // Ensure 3 digits (commits should always be patch level)
return `${tag}.${commits}`; const [major, minor, patch] = `${tag}.${commits}`.split('.');
const threeDigitVersion = /^\d+$/.test(patch) ? `${major}.${minor}.${patch}` : `${major}.0.${minor}`;
core.info(`Found semantic version ${threeDigitVersion} for ${this.branch}@${hash}`);
return `${threeDigitVersion}`;
} }
const version = `0.0.${yield this.getTotalNumberOfCommits()}`; const version = `0.0.${yield this.getTotalNumberOfCommits()}`;
core.info(`Generated version ${version} (semantic version couldn't be determined).`); core.info(`Generated version ${version} (semantic version couldn't be determined).`);

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -10,14 +10,8 @@ export default class AndroidVersioning {
} }
static versionToVersionCode(version) { static versionToVersionCode(version) {
core.warning(version); const parsedVersion = semver.parse(version);
const [major, minor, patch] = version.split('.');
const threeDigitVersion = /^\d+$/.test(patch) ? version : `${major}.0.${minor}`;
core.warning(threeDigitVersion);
const parsedVersion = semver.parse(threeDigitVersion);
// @ts-ignore
core.warning(parsedVersion);
if (!parsedVersion) { if (!parsedVersion) {
core.warning(`Could not parse "${version}" to semver, defaulting android version code to 1`); core.warning(`Could not parse "${version}" to semver, defaulting android version code to 1`);
return 1; return 1;

View File

@ -134,12 +134,18 @@ export default class Versioning {
} }
const versionDescriptor = await this.parseSemanticVersion(); const versionDescriptor = await this.parseSemanticVersion();
if (versionDescriptor) { if (versionDescriptor) {
const { tag, commits, hash } = versionDescriptor; const { tag, commits, hash } = versionDescriptor;
core.info(`Found semantic version ${tag}.${commits} for ${this.branch}@${hash}`);
return `${tag}.${commits}`; // Ensure 3 digits (commits should always be patch level)
const [major, minor, patch] = `${tag}.${commits}`.split('.');
const threeDigitVersion = /^\d+$/.test(patch) ? `${major}.${minor}.${patch}` : `${major}.0.${minor}`;
core.info(`Found semantic version ${threeDigitVersion} for ${this.branch}@${hash}`);
return `${threeDigitVersion}`;
} }
const version = `0.0.${await this.getTotalNumberOfCommits()}`; const version = `0.0.${await this.getTotalNumberOfCommits()}`;
core.info(`Generated version ${version} (semantic version couldn't be determined).`); core.info(`Generated version ${version} (semantic version couldn't be determined).`);
return version; return version;