Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL of the last artifact of a GitHub-action build

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?

like image 887
sab Avatar asked Mar 21 '20 15:03

sab


People also ask

Where are GitHub Actions artifacts stored?

By default, the download-artifact action downloads artifacts to the workspace directory that the step is executing in. You can use the path input parameter to specify a different download directory.

Where do you store building artifacts?

We recommend using Artifact Registry for storing build artifacts. Artifact Registry is a Google Cloud product that you can integrate with Cloud Build to securely store and manage your artifacts in private or public repositories.

What is Nightly link?

link for GitHub. This service lets you get a shareable link to download a build artifact from the latest successful GitHub Actions build of a repository. Any public repository is accessible by default and visitors don't need to log in.


2 Answers

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

like image 181
Geoff Hutchison Avatar answered Sep 20 '22 16:09

Geoff Hutchison


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
like image 43
Oleh Prypin Avatar answered Sep 20 '22 16:09

Oleh Prypin