URL of the last artifact of a GitHub-action build

让人想犯罪 __ 提交于 2021-01-01 04:23:31

问题


I use GitHub-action for my build, and it generates multiple artifacts (with a different name).

Is there a way to predict the URL of the artifacts of the last successful build? Without knowing the sha1, only the name of the artifact and the repo?


回答1:


At the moment, no, according to comments from staff although this may change with future versions of the upload-artifact action.

After poking around myself, it is possible to get this using the GitHub actions API: https://developer.github.com/v3/actions/artifacts/

GET /repos/:owner/:repo/actions/runs/:run_id/artifacts

So you can receive a JSON reply and iterate through the "artifacts" array to get the corresponding "archive_download_url". A workflow can fill in the URL like so:

/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts




回答2:


I have developed a service that exposes predictable URLs to either the latest or a particular artifact of a repository's branch+workflow.

https://nightly.link/
https://github.com/oprypin/nightly.link

This is implemented as a GitHub App, and communication with GitHub is authenticated, but users that only download don't need to even log in to GitHub.


The implementation goes and fetches this through the API, in 3 steps:

  • https://api.github.com/repos/:owner/:repo/actions/workflows/someworkflow.yml/runs?per_page=1&branch=master&event=push&status=success
  • https://api.github.com/repos/:owner/:repo/actions/runs/123456789/artifacts?per_page=100
  • https://api.github.com/repos/:owner/:repo/actions/artifacts/87654321/zip

(the last one redirects you to an ephemeral direct download URL)

Note that authentication is required. For OAuth that's public_repo (or repo if appropriate). For GitHub Apps that's "Actions"/"Read-only".


There is indeed no more direct way to do this.

Some relevant issues are

  • https://github.com/actions/upload-artifact/issues/51
  • https://github.com/actions/upload-artifact/issues/27


来源:https://stackoverflow.com/questions/60789862/url-of-the-last-artifact-of-a-github-action-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!