1
0
Fork 0
mirror of https://github.com/dorny/test-reporter.git synced 2026-02-04 13:37:56 +01:00

artifact-provider: improve logging

This commit is contained in:
Michal Dorner 2021-02-15 20:46:28 +01:00
parent da9cc2c0d9
commit 1ae86a176d
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
4 changed files with 65 additions and 35 deletions

29
dist/index.js generated vendored
View file

@ -85,16 +85,27 @@ class ArtifactProvider {
return {}; return {};
} }
for (const art of artifacts) { for (const art of artifacts) {
await github_utils_1.downloadArtifact(this.octokit, art.id, art.name, this.token); const fileName = `${art.name}.zip`;
await github_utils_1.downloadArtifact(this.octokit, art.id, fileName, art.size_in_bytes, this.token);
core.startGroup(`Reading archive ${fileName}`);
try {
const reportName = this.getReportName(art.name); const reportName = this.getReportName(art.name);
core.info(`Report name: ${reportName}`);
const files = []; const files = [];
const zip = new adm_zip_1.default(art.name); const zip = new adm_zip_1.default(fileName);
for (const entry of zip.getEntries()) { for (const entry of zip.getEntries()) {
const file = entry.name; const file = entry.name;
if (entry.isDirectory || !this.fileNameMatch(file)) if (entry.isDirectory) {
core.info(`Skipping ${file}: entry is a directory`);
continue; continue;
}
if (!this.fileNameMatch(file)) {
core.info(`Skipping ${file}: filename does not match pattern`);
continue;
}
const content = zip.readAsText(entry); const content = zip.readAsText(entry);
files.push({ file, content }); files.push({ file, content });
core.info(`Read ${file}: ${content.length} chars`);
} }
if (result[reportName]) { if (result[reportName]) {
result[reportName].push(...files); result[reportName].push(...files);
@ -103,6 +114,10 @@ class ArtifactProvider {
result[reportName] = files; result[reportName] = files;
} }
} }
finally {
core.endGroup();
}
}
return result; return result;
} }
async listTrackedFiles() { async listTrackedFiles() {
@ -1370,7 +1385,7 @@ function getCheckRunContext() {
return { sha: github.context.sha, runId }; return { sha: github.context.sha, runId };
} }
exports.getCheckRunContext = getCheckRunContext; exports.getCheckRunContext = getCheckRunContext;
async function downloadArtifact(octokit, artifactId, fileName, token) { async function downloadArtifact(octokit, artifactId, fileName, size, token) {
core.startGroup(`Downloading artifact ${fileName}`); core.startGroup(`Downloading artifact ${fileName}`);
try { try {
core.info(`Artifact ID: ${artifactId}`); core.info(`Artifact ID: ${artifactId}`);
@ -1402,9 +1417,9 @@ async function downloadArtifact(octokit, artifactId, fileName, token) {
const downloadStream = got_1.default.stream(url, { headers }); const downloadStream = got_1.default.stream(url, { headers });
const fileWriterStream = fs_1.createWriteStream(fileName); const fileWriterStream = fs_1.createWriteStream(fileName);
core.info(`Downloading ${url}`); core.info(`Downloading ${url}`);
downloadStream.on('downloadProgress', ({ transferred, total, percent }) => { downloadStream.on('downloadProgress', ({ transferred }) => {
const percentage = Math.round(percent * 100); const percentage = Math.round(transferred / size * 100);
core.info(`Progress: ${transferred}/${total} (${percentage}%)`); core.info(`Progress: ${transferred}/${size} (${percentage}%)`);
}); });
await asyncStream(downloadStream, fileWriterStream); await asyncStream(downloadStream, fileWriterStream);
} }

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -67,21 +67,36 @@ export class ArtifactProvider implements InputProvider {
} }
for (const art of artifacts) { for (const art of artifacts) {
await downloadArtifact(this.octokit, art.id, art.name, art.size_in_bytes, this.token) const fileName = `${art.name}.zip`
await downloadArtifact(this.octokit, art.id, fileName, art.size_in_bytes, this.token)
core.startGroup(`Reading archive ${fileName}`)
try {
const reportName = this.getReportName(art.name) const reportName = this.getReportName(art.name)
core.info(`Report name: ${reportName}`)
const files: FileContent[] = [] const files: FileContent[] = []
const zip = new Zip(art.name) const zip = new Zip(fileName)
for (const entry of zip.getEntries()) { for (const entry of zip.getEntries()) {
const file = entry.name const file = entry.name
if (entry.isDirectory || !this.fileNameMatch(file)) continue if (entry.isDirectory) {
core.info(`Skipping ${file}: entry is a directory`)
continue
}
if (!this.fileNameMatch(file)) {
core.info(`Skipping ${file}: filename does not match pattern`)
continue
}
const content = zip.readAsText(entry) const content = zip.readAsText(entry)
files.push({file, content}) files.push({file, content})
core.info(`Read ${file}: ${content.length} chars`)
} }
if (result[reportName]) { if (result[reportName]) {
result[reportName].push(...files) result[reportName].push(...files)
} else { } else {
result[reportName] = files result[reportName] = files
} }
} finally {
core.endGroup()
}
} }
return result return result

View file

@ -74,7 +74,7 @@ export async function downloadArtifact(
core.info(`Downloading ${url}`) core.info(`Downloading ${url}`)
downloadStream.on('downloadProgress', ({transferred}) => { downloadStream.on('downloadProgress', ({transferred}) => {
const percentage = Math.round(transferred / size * 100) const percentage = Math.round((transferred / size) * 100)
core.info(`Progress: ${transferred}/${size} (${percentage}%)`) core.info(`Progress: ${transferred}/${size} (${percentage}%)`)
}) })
await asyncStream(downloadStream, fileWriterStream) await asyncStream(downloadStream, fileWriterStream)