mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-16 06:17:10 +01:00
Fix artifact download
This commit is contained in:
parent
064a15c405
commit
1f5bb98685
3 changed files with 53 additions and 38 deletions
40
dist/index.js
generated
vendored
40
dist/index.js
generated
vendored
|
|
@ -1370,23 +1370,31 @@ function getCheckRunContext() {
|
||||||
}
|
}
|
||||||
exports.getCheckRunContext = getCheckRunContext;
|
exports.getCheckRunContext = getCheckRunContext;
|
||||||
async function downloadArtifact(octokit, artifactId, fileName) {
|
async function downloadArtifact(octokit, artifactId, fileName) {
|
||||||
const resp = await octokit.actions.downloadArtifact({
|
core.startGroup(`Downloading artifact ${fileName}`);
|
||||||
...github.context.repo,
|
|
||||||
artifact_id: artifactId,
|
|
||||||
archive_format: 'zip'
|
|
||||||
});
|
|
||||||
const url = resp.headers.location;
|
|
||||||
if (url === undefined) {
|
|
||||||
throw new Error('Location header was not found in API response');
|
|
||||||
}
|
|
||||||
const downloadStream = got_1.default.stream(url);
|
|
||||||
const fileWriterStream = fs_1.createWriteStream(fileName);
|
|
||||||
downloadStream.on('downloadProgress', ({ transferred, total, percent }) => {
|
|
||||||
const percentage = Math.round(percent * 100);
|
|
||||||
core.info(`progress: ${transferred}/${total} (${percentage}%)`);
|
|
||||||
});
|
|
||||||
core.startGroup(`Downloading ${fileName} from ${url}`);
|
|
||||||
try {
|
try {
|
||||||
|
core.info(`Artifact ID: ${artifactId}`);
|
||||||
|
const resp = await octokit.actions.downloadArtifact({
|
||||||
|
...github.context.repo,
|
||||||
|
artifact_id: artifactId,
|
||||||
|
archive_format: 'zip'
|
||||||
|
});
|
||||||
|
core.info(`Fetch artifact URL: ${resp.status}`);
|
||||||
|
const url = resp.headers.Location;
|
||||||
|
if (url === undefined) {
|
||||||
|
const headers = Object.keys(resp.headers);
|
||||||
|
core.info(`Received headers: ${headers.join(', ')}`);
|
||||||
|
throw new Error('Location header was not found in API response');
|
||||||
|
}
|
||||||
|
if (typeof url !== 'string') {
|
||||||
|
throw new Error(`Location header has unexpected value: ${url}`);
|
||||||
|
}
|
||||||
|
const downloadStream = got_1.default.stream(url);
|
||||||
|
const fileWriterStream = fs_1.createWriteStream(fileName);
|
||||||
|
core.info(`Downloading ${url}`);
|
||||||
|
downloadStream.on('downloadProgress', ({ transferred, total, percent }) => {
|
||||||
|
const percentage = Math.round(percent * 100);
|
||||||
|
core.info(`Progress: ${transferred}/${total} (${percentage}%)`);
|
||||||
|
});
|
||||||
await asyncStream(downloadStream, fileWriterStream);
|
await asyncStream(downloadStream, fileWriterStream);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
|
||||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
|
|
@ -34,28 +34,35 @@ export async function downloadArtifact(
|
||||||
artifactId: number,
|
artifactId: number,
|
||||||
fileName: string
|
fileName: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const resp = await octokit.actions.downloadArtifact({
|
core.startGroup(`Downloading artifact ${fileName}`)
|
||||||
...github.context.repo,
|
|
||||||
artifact_id: artifactId,
|
|
||||||
archive_format: 'zip'
|
|
||||||
})
|
|
||||||
|
|
||||||
const url = resp.headers.location
|
|
||||||
|
|
||||||
if (url === undefined) {
|
|
||||||
throw new Error('Location header was not found in API response')
|
|
||||||
}
|
|
||||||
|
|
||||||
const downloadStream = got.stream(url)
|
|
||||||
const fileWriterStream = createWriteStream(fileName)
|
|
||||||
|
|
||||||
downloadStream.on('downloadProgress', ({transferred, total, percent}) => {
|
|
||||||
const percentage = Math.round(percent * 100)
|
|
||||||
core.info(`progress: ${transferred}/${total} (${percentage}%)`)
|
|
||||||
})
|
|
||||||
|
|
||||||
core.startGroup(`Downloading ${fileName} from ${url}`)
|
|
||||||
try {
|
try {
|
||||||
|
core.info(`Artifact ID: ${artifactId}`)
|
||||||
|
|
||||||
|
const resp = await octokit.actions.downloadArtifact({
|
||||||
|
...github.context.repo,
|
||||||
|
artifact_id: artifactId,
|
||||||
|
archive_format: 'zip'
|
||||||
|
})
|
||||||
|
|
||||||
|
core.info(`Fetch artifact URL: ${resp.status}`)
|
||||||
|
const url = resp.headers.Location
|
||||||
|
if (url === undefined) {
|
||||||
|
const headers = Object.keys(resp.headers)
|
||||||
|
core.info(`Received headers: ${headers.join(', ')}`)
|
||||||
|
throw new Error('Location header was not found in API response')
|
||||||
|
}
|
||||||
|
if (typeof url !== 'string') {
|
||||||
|
throw new Error(`Location header has unexpected value: ${url}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const downloadStream = got.stream(url)
|
||||||
|
const fileWriterStream = createWriteStream(fileName)
|
||||||
|
|
||||||
|
core.info(`Downloading ${url}`)
|
||||||
|
downloadStream.on('downloadProgress', ({transferred, total, percent}) => {
|
||||||
|
const percentage = Math.round(percent * 100)
|
||||||
|
core.info(`Progress: ${transferred}/${total} (${percentage}%)`)
|
||||||
|
})
|
||||||
await asyncStream(downloadStream, fileWriterStream)
|
await asyncStream(downloadStream, fileWriterStream)
|
||||||
} finally {
|
} finally {
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue