|
1 | 1 | import { DefaultArtifactClient } from "@actions/artifact"; |
2 | 2 | import * as github from "@actions/github"; |
3 | 3 | import * as path from "path"; |
4 | | -import { getOctokit } from "./octokit.ts"; |
5 | 4 | import { writeFile } from "./utilities.ts"; |
| 5 | +import { type Repository } from "./repositories.ts"; |
6 | 6 |
|
7 | 7 | export async function uploadToArtifact( |
8 | | - texts: string[], |
| 8 | + reports: { repository: Repository; diff: string }[], |
9 | 9 | ): Promise<string | undefined> { |
10 | | - if (texts.length === 0) { |
11 | | - return undefined; |
12 | | - } |
13 | | - |
14 | 10 | const GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE!; |
15 | 11 |
|
16 | 12 | const files = await Promise.all( |
17 | | - texts.map(async (text) => { |
18 | | - const file = Date.now().toString() + ".diff"; |
19 | | - |
20 | | - await writeFile(path.join(GITHUB_WORKSPACE, file), text); |
21 | | - |
| 13 | + reports.map(async ({ repository, diff }) => { |
| 14 | + const file = `${repository.directoryName}.path`; |
| 15 | + await writeFile(path.join(GITHUB_WORKSPACE, file), diff); |
22 | 16 | return file; |
23 | 17 | }), |
24 | 18 | ); |
25 | 19 |
|
26 | 20 | const artifactClient = new DefaultArtifactClient(); |
27 | | - const artifactName = "reports-" + Date.now().toString(); |
28 | | - await artifactClient.uploadArtifact(artifactName, files, GITHUB_WORKSPACE); |
29 | | - |
30 | | - const octokit = getOctokit(); |
31 | | - const { |
32 | | - data: { artifacts }, |
33 | | - } = await octokit.rest.actions.listWorkflowRunArtifacts({ |
34 | | - owner: github.context.repo.owner, |
35 | | - repo: github.context.repo.repo, |
36 | | - run_id: github.context.runId, |
37 | | - }); |
38 | | - console.log(artifacts); |
| 21 | + const artifactName = "Partial reports"; |
| 22 | + const uploaded = await artifactClient.uploadArtifact( |
| 23 | + artifactName, |
| 24 | + files, |
| 25 | + GITHUB_WORKSPACE, |
| 26 | + ); |
39 | 27 |
|
40 | | - const artifactData = artifacts.find((a) => a.name === artifactName); |
41 | | - console.log(artifactData); |
| 28 | + const url = `https://github.com/${github.context.repo.owner}/${github.context.repo.repo}/actions/runs/${github.context.runId}/artifacts/${uploaded.id}`; |
42 | 29 |
|
43 | | - return artifactData!.archive_download_url; |
| 30 | + return url; |
44 | 31 | } |
0 commit comments