Skip to content

Commit ed2a32e

Browse files
authored
Merge pull request #438 from JojOatXGME/fix-artifact-download-alternative
Fix problematic retransmission of authentication token (alternative solution) #438
2 parents 477942d + f763877 commit ed2a32e

File tree

2 files changed

+9
-40
lines changed

2 files changed

+9
-40
lines changed

dist/index.js

Lines changed: 4 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/github-utils.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,17 @@ export async function downloadArtifact(
5050
const headers = {
5151
Authorization: `Bearer ${token}`
5252
}
53-
const resp = await got(req.url, {
54-
headers,
55-
followRedirect: false
56-
})
57-
58-
core.info(`Fetch artifact URL: ${resp.statusCode} ${resp.statusMessage}`)
59-
if (resp.statusCode !== 302) {
60-
throw new Error('Fetch artifact URL failed: received unexpected status code')
61-
}
62-
63-
const url = resp.headers.location
64-
if (url === undefined) {
65-
const receivedHeaders = Object.keys(resp.headers)
66-
core.info(`Received headers: ${receivedHeaders.join(', ')}`)
67-
throw new Error('Location header was not found in API response')
68-
}
69-
if (typeof url !== 'string') {
70-
throw new Error(`Location header has unexpected value: ${url}`)
71-
}
7253

73-
const downloadStream = got.stream(url, {headers})
54+
const downloadStream = got.stream(req.url, {headers})
7455
const fileWriterStream = createWriteStream(fileName)
7556

76-
core.info(`Downloading ${url}`)
57+
downloadStream.on('redirect', response => {
58+
core.info(`Downloading ${response.headers.location}`)
59+
})
7760
downloadStream.on('downloadProgress', ({transferred}) => {
7861
core.info(`Progress: ${transferred} B`)
7962
})
63+
8064
await asyncStream(downloadStream, fileWriterStream)
8165
} finally {
8266
core.endGroup()

0 commit comments

Comments
 (0)