Skip to content

Commit cbc9928

Browse files
committed
Simplify artifacts
1 parent fee16af commit cbc9928

File tree

2 files changed

+33
-61
lines changed

2 files changed

+33
-61
lines changed

src/artifact.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,14 @@ import {
66
import * as core from '@actions/core'
77
import * as github from '@actions/github'
88
import type { GitBranch } from '@code-pushup/ci'
9-
import { DEFAULT_PERSIST_FILENAME } from '@code-pushup/models'
10-
import { projectToFilename } from '@code-pushup/utils'
119
import type { RequestError } from '@octokit/request-error'
1210
import { readdir, rm } from 'node:fs/promises'
13-
import { join } from 'node:path'
11+
import path from 'node:path'
1412
import type { ActionInputs } from './inputs'
1513

16-
const REPORT_ARTIFACT_NAME = 'code-pushup-report'
17-
const DIFF_ARTIFACT_NAME = 'code-pushup-report-diff'
14+
export const REPORT_ARTIFACT_NAME = 'code-pushup-report'
1815
const ARTIFACT_DIR = 'tmp'
1916

20-
export function createReportArtifactName(project?: string): string {
21-
return createArtifactName(REPORT_ARTIFACT_NAME, project)
22-
}
23-
24-
export function createDiffArtifactName(project?: string): string {
25-
return createArtifactName(DIFF_ARTIFACT_NAME, project)
26-
}
27-
28-
function createArtifactName(base: string, project: string | undefined): string {
29-
if (!project) {
30-
return base
31-
}
32-
const suffix = projectToFilename(project)
33-
return `${base}-${suffix}`
34-
}
35-
3617
export async function uploadArtifact(
3718
artifact: ArtifactClient,
3819
name: string,
@@ -96,7 +77,7 @@ export async function downloadReportArtifact(
9677
}
9778

9879
const { artifact: reportArtifact } = await artifact.getArtifact(
99-
createReportArtifactName(project),
80+
REPORT_ARTIFACT_NAME,
10081
{ findBy }
10182
)
10283
core.debug(
@@ -111,18 +92,25 @@ export async function downloadReportArtifact(
11192
if (!downloadPath) {
11293
throw new Error('Unexpected empty downloadPath')
11394
}
114-
const files = await readdir(downloadPath)
95+
const files = await readdir(downloadPath, { recursive: true })
11596
core.debug(
11697
`Downloaded artifact to ${downloadPath}, contains files: ${files.join(', ')}`
11798
)
11899

119-
const reportJsonFile = `${DEFAULT_PERSIST_FILENAME}.json`
120-
if (!files.includes(reportJsonFile)) {
121-
core.warning(`Downloaded artifact doesn't contain ${reportJsonFile}`)
100+
const expectedFile = path.join(
101+
'.code-pushup',
102+
'.ci',
103+
project ?? '',
104+
'.current',
105+
'report.json'
106+
)
107+
108+
if (!files.includes(expectedFile)) {
109+
core.warning(`Downloaded artifact doesn't contain ${expectedFile}`)
122110
return null
123111
}
124112

125-
return join(downloadPath, reportJsonFile)
113+
return path.join(downloadPath, expectedFile)
126114
} catch (err) {
127115
if (err instanceof ArtifactNotFoundError) {
128116
core.info(

src/main.ts

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import { runInCI } from '@code-pushup/ci'
55
import { simpleGit } from 'simple-git'
66
import { createAnnotationsFromIssues } from './annotations'
77
import { GitHubApiClient } from './api'
8-
import {
9-
createDiffArtifactName,
10-
createReportArtifactName,
11-
uploadArtifact
12-
} from './artifact'
8+
import { REPORT_ARTIFACT_NAME, uploadArtifact } from './artifact'
139
import { parseInputs } from './inputs'
1410
import { createOptions } from './options'
1511
import { parseGitRefs } from './refs'
@@ -57,42 +53,30 @@ export async function run(
5753
core.info(`Commented on PR #${github.context.issue.number}`)
5854
}
5955

60-
const diffFiles =
56+
const artifactFiles =
6157
result.mode === 'standalone'
62-
? Object.values(result.files.diff ?? {})
63-
: result.diffPath
64-
? [result.diffPath]
65-
: []
58+
? [
59+
...Object.values(result.files.current),
60+
...Object.values(result.files.previous ?? {}),
61+
...Object.values(result.files.comparison ?? {})
62+
]
63+
: [
64+
...Object.values(result.files?.comparison ?? {}),
65+
...result.projects.flatMap(({ files }) => [
66+
...Object.values(files.current),
67+
...Object.values(files.previous ?? {}),
68+
...Object.values(files.comparison ?? {})
69+
])
70+
]
6671

67-
if (diffFiles.length > 0) {
68-
await uploadArtifact(artifact, createDiffArtifactName(), diffFiles, inputs)
69-
}
70-
71-
if (result.mode === 'standalone') {
72+
if (artifactFiles.length > 0) {
7273
const id = await uploadArtifact(
7374
artifact,
74-
createReportArtifactName(),
75-
Object.values(result.files.report),
75+
REPORT_ARTIFACT_NAME,
76+
artifactFiles,
7677
inputs
7778
)
7879
core.setOutput('artifact-id', id)
79-
} else {
80-
for (const project of result.projects) {
81-
await uploadArtifact(
82-
artifact,
83-
createReportArtifactName(project.name),
84-
Object.values(project.files.report),
85-
inputs
86-
)
87-
if (project.files.diff) {
88-
await uploadArtifact(
89-
artifact,
90-
createDiffArtifactName(project.name),
91-
Object.values(project.files.diff),
92-
inputs
93-
)
94-
}
95-
}
9680
}
9781

9882
if (inputs.annotations) {

0 commit comments

Comments
 (0)