Skip to content

Commit

Permalink
refactor: use human readable date for canary versions (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Sep 19, 2024
1 parent 19a862c commit 9998f10
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export async function bumpVersion(
const suffix =
typeof opts.suffix === "string"
? `-${opts.suffix}`
: `-${Math.round(Date.now() / 1000)}.${commits[0].shortHash}`;
: `+${fmtDate(new Date())}-${commits[0].shortHash}`;
pkg.version = config.newVersion = config.newVersion.split("-")[0] + suffix;
}

Expand All @@ -85,3 +85,14 @@ export async function bumpVersion(

return pkg.version;
}

function fmtDate(d: Date): string {
// YYMMDD-HHMMSS: 20240919-140954
const date = joinNumbers([d.getFullYear(), d.getMonth() + 1, d.getDate()]);
const time = joinNumbers([d.getHours(), d.getMinutes(), d.getSeconds()]);
return `${date}-${time}`;
}

function joinNumbers(items: number[]): string {
return items.map((i) => (i + "").padStart(2, "0")).join("");
}

0 comments on commit 9998f10

Please sign in to comment.