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

Download an artifact from the command line? #89

Closed
lava opened this issue Jun 22, 2020 · 11 comments
Closed

Download an artifact from the command line? #89

lava opened this issue Jun 22, 2020 · 11 comments
Labels
question Further information is requested

Comments

@lava
Copy link

lava commented Jun 22, 2020

This seems fairly simple, but I'm stumped: I want to download an artifact from the command line.

I have a public repository generating artifacts from a workflow run. By going to the Github Actions UI and navigating to the workflow, I get URL like this and can download the artifacts using my browser:

https://github.com/tenzir/vast/suites/818406657/artifacts/9003143

On the command line, trying to curl the same URL leads to a 404 error.

From #51 we know that this needs a github user account, so I registered a new bot account and gave it "read" access to the repository, and generated a personalized access token with repo scope.

However, using this token I still get a 404 error when trying to download above url. I believe that is due to the fact that the access token is valid for api.github.com, but not for the "regular" github site.

So, my problem is: How do I go from the artifact URL shown in the Github UI to the corresponding api URL that can be used to download the artifact from the command line? Or alternatively, what kind of token do I need to be able to download from the location shown above?

@konradpabjan
Copy link
Collaborator

We have some APIs for artifacts, you can check them out here: https://developer.github.com/v3/actions/artifacts/

A combination of the list and the download artifact APIs should give you all of the information you need and this will work from any command line. With the download API you can get a redirect URL that will allow you do download an artifact. You just need to make sure to pass in an appropriate token token: https://developer.github.com/v3/#authentication

The APIs are a little bit limited though (the redirect URL is only valid for a minute), and you can't use these APIs when a workflow hasn't finished as the artifacts won't show up yet.

@konradpabjan konradpabjan added the question Further information is requested label Jul 6, 2020
@lava
Copy link
Author

lava commented Jul 6, 2020

@konradpabjan I'm afraid you misunderstood the issue. I know how to download an artifact given an API url and how to authenticate that request. A stated in the original description, I created a bot account with correct permissions for that purpose.

The question is, when I go to the Github Actions UI and see one specific artifact that I would like to download, how do I get to a download link for that artifact? The download link that is displayed in the browser is for github.com and not for api.github.com, like this:

https://github.com/tenzir/vast/suites/818406657/artifacts/9003143

and I don't know the mapping between this url and the API url that I would need.

@konradpabjan
Copy link
Collaborator

Apologies for the misunderstanding

The first part of the URL, 818406657 is the check suite id. https://developer.github.com/v3/checks/suites/

The second part of the URL, 9003143 is this artifact ID, you can get that using the list artifact API: https://developer.github.com/v3/actions/artifacts/#list-artifacts-for-a-repository

What you probably need to do to get the artifact ID is to search using the workflow run id: https://developer.github.com/v3/actions/artifacts/#list-workflow-run-artifacts

And to get the workflow run id, you need to use some of our other APIs: https://developer.github.com/v3/actions/workflow-runs/

It might be a little painful, but if you really want to construct the URL yourself you can try this out 😀

@agabor
Copy link

agabor commented Jun 2, 2021

@89z Great, thanks!

@jelmd
Copy link

jelmd commented Apr 7, 2022

curl -u ${user}:${token} ${archive_download_url}

{
  "message": "You must have the actions scope to download artifacts.",
  "documentation_url": "https://docs.github.com/rest/reference/actions#download-an-artifact"
}

What in hell does it mean? There is no artifact scope in https://github.com/settings/tokens/$tokenid ...

@howlowck
Copy link

curl -u ${user}:${token} ${archive_download_url}

{
  "message": "You must have the actions scope to download artifacts.",
  "documentation_url": "https://docs.github.com/rest/reference/actions#download-an-artifact"
}

What in hell does it mean? There is no artifact scope in https://github.com/settings/tokens/$tokenid ...

Maybe the message meant the workflow scope.

@dz0ny
Copy link

dz0ny commented Jul 25, 2022

If you are using GitHub Action, you can download artifact via token that is always present

curl -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -L -o firmware.zip "https://api.github.com/repos/ExpressLRS/ExpressLRS/actions/artifacts/308108746/zip" 

@dimaslanjaka
Copy link

dimaslanjaka commented Feb 24, 2024

If you are using GitHub Action, you can download artifact via token that is always present

curl -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -L -o firmware.zip "https://api.github.com/repos/ExpressLRS/ExpressLRS/actions/artifacts/308108746/zip" 

just tried, and only got 1kb of downloaded file

curl -H "Accept: application/vnd.github+json" -H "Authorization: token github_pat_xxxxxxxx" -L -o tmp.zip "https://github.com/dimaslanjaka/android-traffic-exchange/actions/runs/8029763220/artifacts/1271862961"

@DutchKevv
Copy link

Same.. What is the trick?

@andronat
Copy link

@dimaslanjaka You need the /zip at the end.

@michal2612
Copy link

just tried, and only got 1kb of downloaded file

If you use GHSE make sure that you selected correct Host server.

curl -H "Accept: application/vnd.github+json" -H "Authorization: token github_pat_xxxxxxxx" -L -o tmp.zip "https://<your-GHSE-domain>/dimaslanjaka/android-traffic-exchange/actions/runs/8029763220/artifacts/1271862961"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

11 participants