Fix artifact download

This commit is contained in:
Michal Dorner 2021-02-15 16:28:28 +01:00
parent 064a15c405
commit 1f5bb98685
No known key found for this signature in database
GPG key ID: 9EEE04B48DA36786
3 changed files with 53 additions and 38 deletions

16
dist/index.js generated vendored
View file

@ -1370,23 +1370,31 @@ function getCheckRunContext() {
}
exports.getCheckRunContext = getCheckRunContext;
async function downloadArtifact(octokit, artifactId, fileName) {
core.startGroup(`Downloading artifact ${fileName}`);
try {
core.info(`Artifact ID: ${artifactId}`);
const resp = await octokit.actions.downloadArtifact({
...github.context.repo,
artifact_id: artifactId,
archive_format: 'zip'
});
const url = resp.headers.location;
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}%)`);
core.info(`Progress: ${transferred}/${total} (${percentage}%)`);
});
core.startGroup(`Downloading ${fileName} from ${url}`);
try {
await asyncStream(downloadStream, fileWriterStream);
}
finally {

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -34,28 +34,35 @@ export async function downloadArtifact(
artifactId: number,
fileName: string
): Promise<void> {
core.startGroup(`Downloading artifact ${fileName}`)
try {
core.info(`Artifact ID: ${artifactId}`)
const resp = await octokit.actions.downloadArtifact({
...github.context.repo,
artifact_id: artifactId,
archive_format: 'zip'
})
const url = resp.headers.location
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}%)`)
core.info(`Progress: ${transferred}/${total} (${percentage}%)`)
})
core.startGroup(`Downloading ${fileName} from ${url}`)
try {
await asyncStream(downloadStream, fileWriterStream)
} finally {
core.endGroup()