1
0
Fork 0

update GHES warning behavior

pull/1593/head
Rob Herley 2023-12-05 18:42:36 +00:00 committed by GitHub
parent ce9eae0785
commit b9872153b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 51 deletions

View File

@ -17,6 +17,7 @@ import {
} from './download/download-artifact' } from './download/download-artifact'
import {getArtifactPublic, getArtifactInternal} from './find/get-artifact' import {getArtifactPublic, getArtifactInternal} from './find/get-artifact'
import {listArtifactsPublic, listArtifactsInternal} from './find/list-artifacts' import {listArtifactsPublic, listArtifactsInternal} from './find/list-artifacts'
import {GHESNotSupportError} from './shared/errors'
export interface ArtifactClient { export interface ArtifactClient {
/** /**
@ -52,6 +53,7 @@ export interface ArtifactClient {
/** /**
* Finds an artifact by name. * Finds an artifact by name.
* If there are multiple artifacts with the same name in the same workflow run, this will return the latest. * If there are multiple artifacts with the same name in the same workflow run, this will return the latest.
* If the artifact is not found, it will throw.
* *
* If options.findBy is specified, this will use the public List Artifacts API with a name filter which can get artifacts from other runs. * If options.findBy is specified, this will use the public List Artifacts API with a name filter which can get artifacts from other runs.
* https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts * https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts
@ -99,16 +101,11 @@ export class Client implements ArtifactClient {
rootDirectory: string, rootDirectory: string,
options?: UploadArtifactOptions options?: UploadArtifactOptions
): Promise<UploadArtifactResponse> { ): Promise<UploadArtifactResponse> {
if (isGhes()) {
warning(
`@actions/artifact v2.0.0+ and upload-artifact@v4+ are not currently supported on GHES.`
)
return {
success: false
}
}
try { try {
if (isGhes()) {
throw new GHESNotSupportError()
}
return uploadArtifact(name, files, rootDirectory, options) return uploadArtifact(name, files, rootDirectory, options)
} catch (error) { } catch (error) {
warning( warning(
@ -118,9 +115,8 @@ Errors can be temporary, so please try again and optionally run the action with
If the error persists, please check whether Actions is operating normally at [https://githubstatus.com](https://www.githubstatus.com).` If the error persists, please check whether Actions is operating normally at [https://githubstatus.com](https://www.githubstatus.com).`
) )
return {
success: false throw error
}
} }
} }
@ -131,16 +127,11 @@ If the error persists, please check whether Actions is operating normally at [ht
artifactId: number, artifactId: number,
options?: DownloadArtifactOptions & FindOptions options?: DownloadArtifactOptions & FindOptions
): Promise<DownloadArtifactResponse> { ): Promise<DownloadArtifactResponse> {
if (isGhes()) {
warning(
`@actions/artifact v2.0.0+ and download-artifact@v4+ are not currently supported on GHES.`
)
return {
success: false
}
}
try { try {
if (isGhes()) {
throw new GHESNotSupportError()
}
if (options?.findBy) { if (options?.findBy) {
const { const {
findBy: {repositoryOwner, repositoryName, token}, findBy: {repositoryOwner, repositoryName, token},
@ -159,16 +150,14 @@ If the error persists, please check whether Actions is operating normally at [ht
return downloadArtifactInternal(artifactId, options) return downloadArtifactInternal(artifactId, options)
} catch (error) { } catch (error) {
warning( warning(
`Artifact download failed with error: ${error}. `Download Artifact failed with error: ${error}.
Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information. Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information.
If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).` If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).`
) )
return { throw error
success: false
}
} }
} }
@ -178,16 +167,11 @@ If the error persists, please check whether Actions and API requests are operati
async listArtifacts( async listArtifacts(
options?: ListArtifactsOptions & FindOptions options?: ListArtifactsOptions & FindOptions
): Promise<ListArtifactsResponse> { ): Promise<ListArtifactsResponse> {
if (isGhes()) {
warning(
`@actions/artifact v2.0.0+ and download-artifact@v4+ are not currently supported on GHES.`
)
return {
artifacts: []
}
}
try { try {
if (isGhes()) {
throw new GHESNotSupportError()
}
if (options?.findBy) { if (options?.findBy) {
const { const {
findBy: {workflowRunId, repositoryOwner, repositoryName, token} findBy: {workflowRunId, repositoryOwner, repositoryName, token}
@ -212,9 +196,7 @@ Errors can be temporary, so please try again and optionally run the action with
If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).` If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).`
) )
return { throw error
artifacts: []
}
} }
} }
@ -225,16 +207,11 @@ If the error persists, please check whether Actions and API requests are operati
artifactName: string, artifactName: string,
options?: FindOptions options?: FindOptions
): Promise<GetArtifactResponse> { ): Promise<GetArtifactResponse> {
if (isGhes()) {
warning(
`@actions/artifact v2.0.0+ and download-artifact@v4+ are not currently supported on GHES.`
)
return {
success: false
}
}
try { try {
if (isGhes()) {
throw new GHESNotSupportError()
}
if (options?.findBy) { if (options?.findBy) {
const { const {
findBy: {workflowRunId, repositoryOwner, repositoryName, token} findBy: {workflowRunId, repositoryOwner, repositoryName, token}
@ -252,15 +229,13 @@ If the error persists, please check whether Actions and API requests are operati
return getArtifactInternal(artifactName) return getArtifactInternal(artifactName)
} catch (error: unknown) { } catch (error: unknown) {
warning( warning(
`Fetching Artifact failed with error: ${error}. `Get Artifact failed with error: ${error}.
Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information. Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information.
If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).` If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).`
) )
return { throw error
success: false
}
} }
} }
} }

View File

@ -26,3 +26,12 @@ export class ArtifactNotFoundError extends Error {
this.name = 'ArtifactNotFoundError' this.name = 'ArtifactNotFoundError'
} }
} }
export class GHESNotSupportError extends Error {
constructor(
message = '@actions/artifact v2.0.0+ and download-artifact@v4+ are not currently supported on GHES.'
) {
super(message)
this.name = 'NotSupportedGHESError'
}
}

View File

@ -56,7 +56,7 @@ export interface GetArtifactResponse {
/** /**
* Metadata about the artifact that was found * Metadata about the artifact that was found
*/ */
artifact?: Artifact artifact: Artifact
} }
/***************************************************************************** /*****************************************************************************