Downloading github actions workflow logs using github api
Asked Answered
H

3

12

I am trying to download the logs of a particular workflow in github. I have referenced the following link for the same. However I am getting 302 as response code. Not sure what the issue here is. Its not downloading logs as expected

 curl -v -u username:$token -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/ORGANIZATION/REPOSITORY/actions/runs/319282523477/logs
.
.
< HTTP/1.1 302 Found
< Date: Wed, 21 Oct 2020 07:47:13 GMT
< Content-Type: text/html;charset=utf-8
.
Highminded answered 21/10, 2020 at 7:58 Comment(0)
P
5

As per the same documentation that you mentioned:

Gets a redirect URL to download a plain text file of logs for a workflow job. This link expires after 1 minute. Look for Location: in the response header to find the URL for the download

Response Status: 302 Found

So you might have already got the url to download the logs as the response has a 302 http status. Please check for the Location: response header, which should give you the url that you need to download the logs.

Pentad answered 21/10, 2020 at 8:7 Comment(8)
Thanks a lot @Madhu, as you said there is one Location: header containing the url to download the logs. This URL works fine on chrome but is not working with agents like curl or wget. Any reason why ?Highminded
@Highminded Should ideally work on any http client. The link expires in a min as specified in the doc, did you try it with curl immediately after generating the link? What response did you get when you tried with curl?Pentad
yes I tried with curl actually. Its giving < HTTP/2 404 response. The same link is working with chrome.Highminded
@Highminded Might possibly be some difference with the way you are making the curl request. Can you share the url and how you're trying with curl?Pentad
was trying with this simple command curl -v $URL and also tried with wget $URL. $URL is working on chrome and downloads the file.Highminded
I won't be able to check unless you share the url. Or else you can check the network tab on developer tools of chrome while you open the url in chrome and check the request being made.Pentad
@Highminded you need to authenticate to download the log iircGrata
ah okay @riQQ, yeah this makes sense. curl -u username:password $URL should do the trick. In chrome might have worked as i was already logged in i guess. Thanks a lot @riQQ.Highminded
C
2

As a side note to Madhu Bhat's answer, you can simply add -L to your curl command to make it follow redirects.

(from curl --help)

 -L, --location      Follow redirects
Chiang answered 29/3, 2022 at 8:58 Comment(1)
That would be "curl -L -H "Authorization: ..."<url to api.github.com>" --output <filename>.zip" (ignoring that the internal quotes are wrong) with auth and entire url filled in. This will follow redirection to download the file. Standard unzipping will work on it.Bread
P
1

If anyone is looking for GitHub Action that can download the workflow logs through schedule or push, here is the GH Action: https://github.com/marketplace/actions/github-action-logs

Psychopath answered 12/11, 2023 at 22:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.