Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix problematic retransmission of authentication token (alternative solution) #438

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions dist/index.js

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

26 changes: 5 additions & 21 deletions src/utils/github-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,33 +50,17 @@ export async function downloadArtifact(
const headers = {
Authorization: `Bearer ${token}`
}
const resp = await got(req.url, {
headers,
followRedirect: false
})

core.info(`Fetch artifact URL: ${resp.statusCode} ${resp.statusMessage}`)
if (resp.statusCode !== 302) {
throw new Error('Fetch artifact URL failed: received unexpected status code')
}

const url = resp.headers.location
if (url === undefined) {
const receivedHeaders = Object.keys(resp.headers)
core.info(`Received headers: ${receivedHeaders.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, {headers})
const downloadStream = got.stream(req.url, {headers})
const fileWriterStream = createWriteStream(fileName)

core.info(`Downloading ${url}`)
downloadStream.on('redirect', response => {
core.info(`Downloading ${response.headers.location}`)
})
downloadStream.on('downloadProgress', ({transferred}) => {
core.info(`Progress: ${transferred} B`)
})

await asyncStream(downloadStream, fileWriterStream)
} finally {
core.endGroup()
Expand Down
Loading