Skip to content

Commit

Permalink
Fix artifact download
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Dorner committed Feb 15, 2021
1 parent 064a15c commit 1f5bb98
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
40 changes: 24 additions & 16 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

43 changes: 25 additions & 18 deletions src/utils/github-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,35 @@ export async function downloadArtifact(
artifactId: number,
fileName: string
): Promise<void> {
const resp = await octokit.actions.downloadArtifact({
...github.context.repo,
artifact_id: artifactId,
archive_format: 'zip'
})

const url = resp.headers.location
core.startGroup(`Downloading artifact ${fileName}`)
try {
core.info(`Artifact ID: ${artifactId}`)

if (url === undefined) {
throw new Error('Location header was not found in API response')
}
const resp = await octokit.actions.downloadArtifact({
...github.context.repo,
artifact_id: artifactId,
archive_format: 'zip'
})

const downloadStream = got.stream(url)
const fileWriterStream = createWriteStream(fileName)
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}`)
}

downloadStream.on('downloadProgress', ({transferred, total, percent}) => {
const percentage = Math.round(percent * 100)
core.info(`progress: ${transferred}/${total} (${percentage}%)`)
})
const downloadStream = got.stream(url)
const fileWriterStream = createWriteStream(fileName)

core.startGroup(`Downloading ${fileName} from ${url}`)
try {
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)
} finally {
core.endGroup()
Expand Down

0 comments on commit 1f5bb98

Please sign in to comment.