Skip to content

Commit

Permalink
fix: Generate from preceding tag if last tag is not a semantic version
Browse files Browse the repository at this point in the history
  • Loading branch information
Alorel committed Sep 21, 2023
1 parent 896814f commit 3e49811
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/lib/semver.mts
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,12 @@ class SemVer {
}

public static async resolveLastRelease(): Promise<SemVer | undefined> {
let raw: string;
try {
raw = await exec(`git tag --list`, `getting last tag`, false);
} catch {
return; // no tags created yet
}
if (!raw) {
return; // same
}

const semvers = raw.split(/\r?\n/g).map(v => SemVer.parse(v, true));
semvers.sort(SemVer.cmp);
const [last] = await SemVer.resolveReleases();

if (semvers[0]) {
info(`Last tag resolved to ${semvers[0]}`);
if (last) {
info(`Last tag resolved to ${last}`);

return semvers[0];
return last;
}
}

Expand All @@ -70,6 +59,32 @@ class SemVer {
return new SemVer(1, 0, 0);
}

/** Newest at the start of the array */
public static async resolveReleases(): Promise<SemVer[]> {
let raw: string;
try {
raw = await exec(`git tag --list`, `getting last tag`, false);
} catch {
return []; // no tags created yet
}
if (!raw) {
return []; // same
}

const semvers = raw.split(/\r?\n/g)
.reduce<SemVer[]>((acc, v) => {
const parsed = SemVer.parse(v, true);
if (parsed) {
acc.push(parsed);
}

return acc;
}, []);
semvers.sort(SemVer.cmp);

return semvers;
}

public get minor(): number {
return this.#minor ?? 0;
}
Expand Down

0 comments on commit 3e49811

Please sign in to comment.