mirror of
https://git.mirrors.martin98.com/https://github.com/actions/toolkit
synced 2026-05-07 00:38:05 +08:00
rewrite artifacts client to have public and internal implementations
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
import {GetArtifactResponse} from '../shared/interfaces'
|
||||
import {getOctokit} from '@actions/github'
|
||||
import {getUserAgentString} from '../shared/user-agent'
|
||||
import {defaults as defaultGitHubOptions} from '@actions/github/lib/utils'
|
||||
import {getRetryOptions} from './retry-options'
|
||||
import {requestLog} from '@octokit/plugin-request-log'
|
||||
import {retry} from '@octokit/plugin-retry'
|
||||
import * as core from '@actions/core'
|
||||
import {OctokitOptions} from '@octokit/core/dist-types/types'
|
||||
import {defaults as defaultGitHubOptions} from '@actions/github/lib/utils'
|
||||
import {getRetryOptions} from './retry-options'
|
||||
import {requestLog} from '@octokit/plugin-request-log'
|
||||
import {GetArtifactResponse} from '../shared/interfaces'
|
||||
import {getBackendIdsFromToken} from '../shared/util'
|
||||
import {getUserAgentString} from '../shared/user-agent'
|
||||
import {internalArtifactTwirpClient} from '../shared/artifact-twirp-client'
|
||||
import {ListArtifactsRequest} from '../../generated'
|
||||
|
||||
export async function getArtifact(
|
||||
export async function getArtifactPublic(
|
||||
artifactName: string,
|
||||
workflowRunId: number,
|
||||
repositoryOwner: string,
|
||||
@@ -62,8 +65,55 @@ export async function getArtifact(
|
||||
artifact: {
|
||||
name: getArtifactResp.data.artifacts[0].name,
|
||||
id: getArtifactResp.data.artifacts[0].id,
|
||||
url: getArtifactResp.data.artifacts[0].url,
|
||||
size: getArtifactResp.data.artifacts[0].size_in_bytes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getArtifactInternal(
|
||||
artifactName: string
|
||||
): Promise<GetArtifactResponse> {
|
||||
const artifactClient = internalArtifactTwirpClient()
|
||||
|
||||
const {workflowRunBackendId, workflowJobRunBackendId} =
|
||||
getBackendIdsFromToken()
|
||||
|
||||
const req: ListArtifactsRequest = {
|
||||
workflowRunBackendId,
|
||||
workflowJobRunBackendId,
|
||||
nameFilter: artifactName,
|
||||
idFilter: '0' // TODO(robherley): int64 zero value, change this to be optional
|
||||
}
|
||||
|
||||
const res = await artifactClient.ListArtifacts(req)
|
||||
|
||||
if (res.artifacts.length === 0) {
|
||||
core.warning('no artifacts found')
|
||||
return {
|
||||
success: false
|
||||
}
|
||||
}
|
||||
|
||||
if (res.artifacts.length > 1) {
|
||||
core.warning(
|
||||
'more than one artifact found for a single name, returning first'
|
||||
)
|
||||
}
|
||||
|
||||
// In the case of reruns, we may have artifacts with the same name scoped under the same workflow run.
|
||||
// Let's prefer the artifact closest scoped to this run.
|
||||
// If it doesn't exist (e.g. partial rerun) we'll use the first match.
|
||||
const artifact =
|
||||
res.artifacts.find(
|
||||
artifact => artifact.workflowRunBackendId === workflowRunBackendId
|
||||
) || res.artifacts[0]
|
||||
|
||||
return {
|
||||
success: true,
|
||||
artifact: {
|
||||
name: artifact.name,
|
||||
id: Number(artifact.databaseId),
|
||||
size: Number(artifact.size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user