This commit is contained in:
Rob Herley
2023-12-03 06:24:49 +00:00
committed by GitHub
parent c94ca49c9c
commit c11a7cdeac
5 changed files with 220 additions and 33 deletions

View File

@@ -56,12 +56,9 @@ export async function getArtifactPublic(
let artifact = getArtifactResp.data.artifacts[0]
if (getArtifactResp.data.artifacts.length > 1) {
artifact = getArtifactResp.data.artifacts.reduce((prev, current) => {
new Date(prev.created_at) > new Date(current.created_at) ? prev : current
})
artifact = getArtifactResp.data.artifacts.sort((a, b) => b.id - a.id)[0]
core.debug(
`more than one artifact found for a single name, returning newest (id: ${artifact.id})`
`More than one artifact found for a single name, returning newest (id: ${artifact.id})`
)
}
@@ -101,11 +98,9 @@ export async function getArtifactInternal(
let artifact = res.artifacts[0]
if (res.artifacts.length > 1) {
artifact = res.artifacts.reduce((prev, current) => {
const prevDate = Timestamp.toDate(prev.createdAt || Timestamp.now())
const currentDate = Timestamp.toDate(current.createdAt || Timestamp.now())
return prevDate > currentDate ? prev : current
})
artifact = res.artifacts.sort(
(a, b) => Number(b.databaseId) - Number(a.databaseId)
)[0]
core.debug(
`more than one artifact found for a single name, returning newest (id: ${artifact.databaseId})`

View File

@@ -152,19 +152,7 @@ export async function listArtifactsInternal(
* @returns The filtered list of artifacts
*/
function filterLatest(artifacts: Artifact[]): Artifact[] {
artifacts.sort((a, b) => {
if (!a.createdAt && !b.createdAt) {
return 0
}
if (!a.createdAt) {
return -1
}
if (!b.createdAt) {
return 1
}
return b.createdAt.getTime() - a.createdAt.getTime()
})
artifacts.sort((a, b) => b.id - a.id)
const latestArtifacts: Artifact[] = []
const seenArtifactNames = new Set<string>()
for (const artifact of artifacts) {
@@ -173,6 +161,5 @@ function filterLatest(artifacts: Artifact[]): Artifact[] {
seenArtifactNames.add(artifact.name)
}
}
return latestArtifacts
}