mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-04-16 01:48:05 +08:00
wip
This commit is contained in:
@@ -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})`
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user