Skip to content

Commit

Permalink
Adapt for new artifact API
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz committed Dec 24, 2023
1 parent 90a8902 commit 05d06b0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/dependency-graph.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as core from '@actions/core'
import * as artifact from '@actions/artifact'
import * as github from '@actions/github'
import * as glob from '@actions/glob'
import * as toolCache from '@actions/tool-cache'
import {DefaultArtifactClient} from '@actions/artifact'
import {GitHub} from '@actions/github/lib/utils'
import {RequestError} from '@octokit/request-error'
import type {PullRequestEvent} from '@octokit/webhooks-types'
Expand Down Expand Up @@ -59,7 +59,7 @@ async function uploadDependencyGraphs(): Promise<string[]> {
const relativeGraphFiles = graphFiles.map(x => getRelativePathFromWorkspace(x))
core.info(`Uploading dependency graph files: ${relativeGraphFiles}`)

const artifactClient = artifact.create()
const artifactClient = new DefaultArtifactClient()
artifactClient.uploadArtifact(DEPENDENCY_GRAPH_ARTIFACT, graphFiles, workspaceDirectory, {
retentionDays: getArtifactRetentionDays()
})
Expand Down Expand Up @@ -157,15 +157,24 @@ async function retrieveDependencyGraphsForWorkflowRun(runId: number, workspaceDi
}

async function retrieveDependencyGraphsForCurrentWorkflow(workspaceDirectory: string): Promise<string[]> {
const artifactClient = artifact.create()
const artifactClient = new DefaultArtifactClient()
const downloadPath = path.resolve(workspaceDirectory, 'dependency-graph')
await artifactClient.downloadArtifact(DEPENDENCY_GRAPH_ARTIFACT, downloadPath)
return await findDependencyGraphFiles(downloadPath)
const artifact = await artifactClient.getArtifact(DEPENDENCY_GRAPH_ARTIFACT)
core.info(`Downloading dependency-graph artifact to ${downloadPath}`)
const downloadedArtifact = await artifactClient.downloadArtifact(artifact.artifact.id, {
path: downloadPath
})
if (!downloadedArtifact.downloadPath) {
throw new Error(`Dependency graph artifact not found.`)
}
core.info(`Downloaded dependency-graph artifact to ${downloadedArtifact.downloadPath}`)
return await findDependencyGraphFiles(downloadedArtifact.downloadPath)
}

async function findDependencyGraphFiles(dir: string): Promise<string[]> {
const globber = await glob.create(`${dir}/dependency-graph-reports/*.json`)
const graphFiles = globber.glob()
core.info(`Found dependency graph files: ${graphFiles}`)
return graphFiles
}

Expand Down

0 comments on commit 05d06b0

Please sign in to comment.