mirror of
https://github.com/actions/toolkit
synced 2025-05-09 16:43:02 +00:00
wip
This commit is contained in:
parent
c94ca49c9c
commit
c11a7cdeac
5 changed files with 220 additions and 33 deletions
|
@ -1,8 +1,8 @@
|
|||
import {warning} from '@actions/core'
|
||||
import {isGhes} from './shared/config'
|
||||
import {
|
||||
UploadOptions,
|
||||
UploadResponse,
|
||||
UploadArtifactOptions,
|
||||
UploadArtifactResponse,
|
||||
DownloadArtifactOptions,
|
||||
GetArtifactResponse,
|
||||
ListArtifactsOptions,
|
||||
|
@ -26,14 +26,14 @@ export interface ArtifactClient {
|
|||
* @param files A list of absolute or relative paths that denote what files should be uploaded
|
||||
* @param rootDirectory An absolute or relative file path that denotes the root parent directory of the files being uploaded
|
||||
* @param options Extra options for customizing the upload behavior
|
||||
* @returns single UploadResponse object
|
||||
* @returns single UploadArtifactResponse object
|
||||
*/
|
||||
uploadArtifact(
|
||||
name: string,
|
||||
files: string[],
|
||||
rootDirectory: string,
|
||||
options?: UploadOptions
|
||||
): Promise<UploadResponse>
|
||||
options?: UploadArtifactOptions
|
||||
): Promise<UploadArtifactResponse>
|
||||
|
||||
/**
|
||||
* Lists all artifacts that are part of the current workflow run.
|
||||
|
@ -96,8 +96,8 @@ export class Client implements ArtifactClient {
|
|||
name: string,
|
||||
files: string[],
|
||||
rootDirectory: string,
|
||||
options?: UploadOptions
|
||||
): Promise<UploadResponse> {
|
||||
options?: UploadArtifactOptions
|
||||
): Promise<UploadArtifactResponse> {
|
||||
if (isGhes()) {
|
||||
warning(
|
||||
`@actions/artifact v2.0.0+ and upload-artifact@v4+ are not currently supported on GHES.`
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* UploadArtifact *
|
||||
* *
|
||||
*****************************************************************************/
|
||||
export interface UploadResponse {
|
||||
export interface UploadArtifactResponse {
|
||||
/**
|
||||
* Denotes if an artifact was successfully uploaded
|
||||
*/
|
||||
|
@ -21,7 +21,7 @@ export interface UploadResponse {
|
|||
id?: number
|
||||
}
|
||||
|
||||
export interface UploadOptions {
|
||||
export interface UploadArtifactOptions {
|
||||
/**
|
||||
* Duration after which artifact will expire in days.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue