Skip to content

Commit

Permalink
tag latest
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codes authored Jun 10, 2024
1 parent d50df6a commit 33a10d3
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions libs/versioning/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,20 @@ const getDockerTags = async (version, ref) => {
tags.push(version)

const major = semver.major(version)
tags.push(`${major}-latest`)

const minor = semver.minor(version)
tags.push(`${major}.${minor}-latest`)

const latestMajors = Object.entries(
groupBy(
sh
.exec(`git tag --sort=-creatordate`)
.stdout.split('\n')
.filter((tag) => tag)
.map((tag) => tag.replace(/^v/, ''))
.sort(semver.rcompare),
semver.major,
),
).map(([major, tags]) => [
major,
tags.find((tag) => !semver.eq(version, tag)),
])
debug(`latestMajors: ${JSON.stringify(latestMajors, null, 2)}`)

const matchingLatestMajor = latestMajors.find(
([major, tag]) =>
major === semver.major(version).toString() &&
(tag === null || semver.gt(version, tag)),
)
if (matchingLatestMajor) {
tags.push(`${matchingLatestMajor[0]}-latest`)
const latestVersion = sh
.exec(`git tag --sort=-creatordate`)
.stdout.split('\n')
.filter((tag) => tag)
.map((tag) => tag.replace(/^v/, ''))
.sort(semver.rcompare)[0]

if (latestVersion === version) {
tags.push('latest')
}
} else if (/^refs\/heads\/main$/.test(ref)) {
tags.push(`dev`)
Expand Down

0 comments on commit 33a10d3

Please sign in to comment.