Skip to content

Commit e539b31

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

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

src/actions.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,37 @@ 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+
DownloadArtifactOptions,
10+
GetArtifactResponse,
11+
UploadArtifactResponse,
12+
} from '@actions/artifact'
713

814
const artifact = new DefaultArtifactClient()
915

10-
export function uploadArtifact(
11-
artifactName: string,
12-
...files: string[]
13-
): Promise<UploadArtifactResponse> {
16+
export async function uploadArtifact(artifactName: string, ...files: string[]) {
1417
startGroup('Uploading artifact ' + artifactName)
15-
var reponse = artifact.uploadArtifact(artifactName, files, '.')
18+
await artifact.uploadArtifact(artifactName, files, '.')
1619
endGroup()
17-
return reponse
1820
}
1921

20-
export async function downloadArtifact(artifactName: string) {
22+
export async function downloadArtifact(artifactName: string): Promise<string> {
2123
startGroup('Downloading artifact ' + artifactName)
22-
await create.getArtifact(artifactName)
24+
const getReponse: GetArtifactResponse = await artifact.getArtifact(artifactName)
25+
const option: DownloadArtifactOptions = {
26+
path: path.join(process.env['GITHUB_WORKSPACE'], artifactName),
27+
}
28+
const downloadReponse: DownloadArtifactOptions = await artifact.downloadArtifact(
29+
getReponse.artifact.id,
30+
option
31+
)
32+
if (downloadReponse.downloadPath === undefined) {
33+
throw new Error('Failed to download artifact ' + artifactName)
34+
}
2335
endGroup()
36+
return downloadReponse.downloadPath
2437
}
2538

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

src/index.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -89,32 +89,22 @@ 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+
const artifactOld = await downloadArtifact('results-old')
93+
const artifactNew = await downloadArtifact('results-new')
9494
telemetryCollector.addField(
9595
'duration.download-artifacts',
9696
(Date.now() - downloadStart).toString()
9797
)
98+
const sarifFileOld = path.join(artifactOld, scaReport)
99+
const sarifFileNew = path.join(artifactNew, scaReport)
100+
console.log('Artifact old: ', sarifFileOld)
101+
console.log('Artifact new: ', sarifFileNew)
102+
98103
const issuesByTool: { [tool: string]: string } = {}
99-
if (existsSync(`results-old/${scaReport}`) && existsSync(`results-new/${scaReport}`)) {
100-
issuesByTool['sca'] = await compareResults(
101-
'sca',
102-
`results-old/${scaReport}`,
103-
`results-new/${scaReport}`
104-
)
104+
if (existsSync(sarifFileOld) && existsSync(sarifFileNew)) {
105+
issuesByTool['sca'] = await compareResults('sca', sarifFileOld, sarifFileNew)
105106
} else {
106-
exec('ls -R -lh', (error, stdout, stderr) => {
107-
if (error) {
108-
console.error(`Error: ${error.message}`)
109-
return
110-
}
111-
if (stderr) {
112-
console.error(`Stderr: ${stderr}`)
113-
return
114-
}
115-
console.log(`Output:\n${stdout}`)
116-
})
117-
throw new Error('No results found for SCA')
107+
throw new Error('SARIF file not found for SCA')
118108
}
119109

120110
const commentStart = Date.now()

0 commit comments

Comments
 (0)