Skip to content

Commit 999eef6

Browse files
committed
reuse the same code in downloadArtifact
1 parent ec90685 commit 999eef6

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/actions.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,29 @@ import { endGroup, getInput, startGroup } from '@actions/core'
33
import { context, getOctokit } from '@actions/github'
44
import { retry } from '@octokit/plugin-retry'
55
import { Md5 } from 'ts-md5'
6-
import { DefaultArtifactClient, UploadArtifactResponse } from '@actions/artifact'
6+
import {
7+
Artifact,
8+
DefaultArtifactClient,
9+
GetArtifactResponse,
10+
UploadArtifactResponse,
11+
} from '@actions/artifact'
712

813
const artifact = new DefaultArtifactClient()
914

10-
export function uploadArtifact(
11-
artifactName: string,
12-
...files: string[]
13-
): Promise<UploadArtifactResponse> {
15+
export async function uploadArtifact(artifactName: string, ...files: string[]) {
1416
startGroup('Uploading artifact ' + artifactName)
15-
var reponse = artifact.uploadArtifact(artifactName, files, '.')
17+
await artifact.uploadArtifact(artifactName, files, '.')
1618
endGroup()
17-
return reponse
1819
}
1920

20-
export async function downloadArtifact(artifactName: string) {
21+
export async function downloadArtifact(artifactName: string): Promise<Artifact> {
2122
startGroup('Downloading artifact ' + artifactName)
22-
await create.getArtifact(artifactName)
23+
var reponse = await artifact.getArtifact(artifactName)
24+
if (reponse === undefined) {
25+
throw new Error('Artifact not found')
26+
}
2327
endGroup()
28+
return reponse.artifact
2429
}
2530

2631
export async function postCommentIfInPr(message: string): Promise<string | undefined> {

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,14 @@ async function runAnalysis() {
8989
async function displayResults() {
9090
info('Displaying results')
9191
const downloadStart = Date.now()
92-
await downloadArtifact('results-old')
93-
await downloadArtifact('results-new')
92+
var artifactOld = await downloadArtifact('results-old')
93+
var artifactNew = await downloadArtifact('results-new')
9494
telemetryCollector.addField(
9595
'duration.download-artifacts',
9696
(Date.now() - downloadStart).toString()
9797
)
98+
console.log('Artifact old: ', artifactOld)
99+
console.log('Artifact new: ', artifactNew)
98100
const issuesByTool: { [tool: string]: string } = {}
99101
if (existsSync(`results-old/${scaReport}`) && existsSync(`results-new/${scaReport}`)) {
100102
issuesByTool['sca'] = await compareResults(

0 commit comments

Comments
 (0)