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

Support artifact URL output #50

Open
lelegard opened this issue Jan 28, 2020 · 68 comments
Open

Support artifact URL output #50

lelegard opened this issue Jan 28, 2020 · 68 comments
Labels
enhancement New feature or request

Comments

@lelegard
Copy link

Hi,

This suggestion has been discussed here in the GitHub community forum.

In a Github Actions job, after an upload-artifact step, I would like to get the URL of the published artifact in a subsequent step.

The idea is a job using the following steps:

  • Build a binary.
  • Upload the binary as artifact.
  • Trigger a REST API in some Web server, passing the URL of the artifact in a POST parameter, so that the remote server can download the artifact.

How would you get the URL of the artifact in a subsequent step?

I know that there is an Actions API currently in development. But, here, the question is about passing information from the upload-artifact step to the next step.

It could be something like this:

    - name: Upload build
      uses: actions/upload-artifact@master
      with:
        name: installer
        path: installer.exe
        env-url: FOOBAR
    - name: Use URL for something
      run: echo "${{ env.FOOBAR }}"

The last command would display something like:

https://github.com/user/repo/suites/123456/artifacts/789123
@jperl
Copy link

jperl commented Jan 31, 2020

Ideally you could set it so the links do not expire, and they would serve the correct Content-Type so you could link to images/gifs/videos.

It seems you can get an artifact url via https://developer.github.com/v3/actions/artifacts but the links expire within 1 minute.

@jjangga0214
Copy link

@jperl Do you know why it's to be expired after 1 minute?

@jperl
Copy link

jperl commented Mar 8, 2020

I do not know why, that is just what their documentation says.

@jjangga0214
Copy link

jjangga0214 commented Mar 9, 2020

@jperl Hmm, I see. I made an independent issue, #60.
This is just letting you know, for the case you want to subscribe or participate in it :)

@lanyizi
Copy link

lanyizi commented Jun 4, 2020

It seems you can get an artifact url via https://developer.github.com/v3/actions/artifacts but the links expire within 1 minute.

Unfortunately you can't retrieve the artifact during current workflow run, it will become available in the API only after the current run finishes...

@chshersh
Copy link

This would be a really nice feature to have! I'm working on a Docker image GitHub Action and I want to upload some assets before running my action so they can be used inside the Docker container. If the upload-artifact action provides a URL to the asset as an output, the I can pass this output as an argument to my action and download the asset using curl from inside Docker container.

@ghutchis
Copy link

I'm going to bump this again. Many people have asked for this feature - both here, discussions, even Stack Overflow

For example, I'd really like to have the artifact URLs posted as a comment for pull requests. At the moment, this seems impossible because the URL is not available to the current workflow.

@domenkozar
Copy link

It seems you can get an artifact url via https://developer.github.com/v3/actions/artifacts but the links expire within 1 minute.

Unfortunately you can't retrieve the artifact during current workflow run, it will become available in the API only after the current run finishes...

I wonder if you could use https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_run then to process that

@abhijitvalluri
Copy link

I'm going to bump this again. Many people have asked for this feature - both here, discussions, even Stack Overflow

For example, I'd really like to have the artifact URLs posted as a comment for pull requests. At the moment, this seems impossible because the URL is not available to the current workflow.

I was hoping to do this exact thing! I would love to be able to link the artifacts to the pull request for people to download.

@jeacott1
Copy link

jeacott1 commented Sep 30, 2020

+1 for this, or at least the artifact id.
@jjangga0214 @jperl the timeout is only for the redirect url. the actual rest endpoint is constant. ref https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-an-artifact

I'd find this especially useful to use if I split my pull request and release workflows. I could then reference the artifact built and tested in the PR and publish that directly on release.

@DanRunfola
Copy link

Just adding a +1 here - right now, we're considering all sorts of hacky things (uploading artifacts to a seperate FTP server so we can serve links in PRs, woo...).

@jerrymarino
Copy link

💯 would love to see this feature. I attempted to run curl on the artifact for XCHammer in the browser and was surprised to see it wasn't working. The use case of this feature would be to pull the artifact into Bazel, but it'd need some stable URL to do this.

It seems like the only alternative is to create a release to create a stable URL but that might be confusing and spam the watchers if we end up doing a release per commit.

jerrymarino added a commit to bazel-xcode/xchammer that referenced this issue Oct 1, 2020
The github actions API doesn't play well with per commit artifacts. For
now we create a release when pushing a tag.

Consuming the per commit artifacts w/o the github actions API is blocked
by this: actions/upload-artifact#50
jerrymarino added a commit to bazel-xcode/xchammer that referenced this issue Oct 1, 2020
* Binary release creation workflows

This PR adds the ability to upload release artifact via XCHammer's github
CI and it creates a release when pushing a tag to v*

The github actions API doesn't play well with per commit artifacts. For
now we create a release when pushing a tag.

Consuming the per commit artifacts w/o the github actions API is blocked
by this: actions/upload-artifact#50
@jeacott1
Copy link

jeacott1 commented Oct 1, 2020

@jerrymarino afaict the url is stable, but you have to follow the redirect to get the artifact.

@jerrymarino
Copy link

jerrymarino commented Oct 2, 2020

@jeacott1 It'd be awesome for the workflow in question it'd work! Perhaps we're talking about different URLs then - I'm hoping to consume the artifact urls on the github website found via browser and they seem incompatible with curl and bazel:

I've attempted to do the following steps to pull artifacts with curl and Bazel

  1. navigate to https://github.com/pinterest/xchammer/actions/runs/283307177 in a web browser
  2. under Artifacts get the link for xchammer by right clicking xchammer ( https://github.com/pinterest/xchammer/suites/1276155763/artifacts/19716224 )
  3. try to pull with curl following redirects curl -L https://github.com/pinterest/xchammer/suites/1276155763/artifacts/19716224
    When I ran that command a few mins ago I get Not Found

I circulated though a few other issues and found mentions of artifact URL from a github actions API that lasts 1 minute. Is this the URL you're pointing to?

@jeacott1
Copy link

jeacott1 commented Oct 2, 2020

@jerrymarino yeah, you are using the wrong initial url. you need to use the one here which is stable:
https://docs.github.com/en/free-pro-team@latest/rest/reference/actions#download-an-artifact

tldr: GET /repos/{owner}/{repo}/actions/artifacts/{artifact_id}/{archive_format}

and then follow the redirect

the real issue is that when you save an artifact you dont get the id in a response as reference later.

@tonyhallett
Copy link

@ghutchis @abhijitvalluri
I have created this action that creates a comment in pull request and/or associated issues with the link to all / subset of artifacts
https://github.com/marketplace/actions/workflow-artifact-pull-request-comment

@Kalgros20
Copy link

Any updates? There's a real intention to provide the ID after the upload?

@mckrava
Copy link

mckrava commented Mar 5, 2022

It would be really useful to have access to artifacts before run completion. In my case I need retrieve artifacts download URLs and publish it in custom issue comment. And it must be done in one workflow run, I cannot use 2 separate workflows for generating artifacts and publication comment.

@Andre601
Copy link

(This is a personal thing, so don't take it as anything official or as representation of anyone else)

Rant: [On]

Would apreciate if you wouldn't comment with "+1" here... If you have something important to contribute, do that. But posting just "+1" is not contributing anything.
If you want to support this idea, add a +1 reaction to the OP.

Also, I'm sure we would've gotten a reply by a maintainer if there were any updates whatsoever.
From what I understand is this feature currently not possible due to lacking API endpoints on GitHub's end (Iirc is the issue, that the (final) download URL for artifacts isn't available/generated until the job has ended, making it not accessible in-between steps).

So, please safe me and probs other peoples time (and storage on the mail inbox) by not replying with "+1" or alike... It doesn't help.

Rant: [Off]

@NJannasch
Copy link

It would be great to have this feature available.

@sujanp-kr
Copy link

+1
I need.
Plus, essentially a necessary feature.
When happening 🤔

@lyskouski
Copy link

Thanks to @djthornton1212
https://github.com/orgs/community/discussions/51403#discussioncomment-5515349

I've been able to reproduce the capability of taking artifacts URL [ref] . The main case that artifacts are not accessible via gh api "/repos/${{ github.repository }}/actions/artifacts for ongoing workflows. And the second tip, that referenced pipe should be merged into the targeted branch, otherwise, it won't be recognized by "on: workflow_run:".

@konradpabjan
Copy link
Collaborator

konradpabjan commented Dec 14, 2023

So v4 just released today: https://github.blog/changelog/2023-12-14-github-actions-artifacts-v4-is-now-generally-available/

With it there is an artifact ID output that is immediately available and it's the same ID that is used in the current URL: https://github.com/actions/upload-artifact?tab=readme-ov-file#using-outputs So with another API call to get the check suite ID it should be possible to construct an artifact URL.

The current URL that is in the format of https://github.com/user/repo/suites/123456/artifacts/789123 is pretty bad though as it is unintuitive and we're planning on changing it to something like https://github.com/user/repo/actions/runs/123456/artifacts/789123 since the workflow run ID is available in the job and in the UI everywhere. We have an issue internally to change this (the old URLs will continue to work), and once we do that it should be pretty easy. We could have a URL output similar to the ID with V4. No estimate as to when this will come around but at least the artifact ID is immediately available now with v4 and that was the big limitation. Took a lot of work with v4 to make that work. Recommend switching to it as there are a number of big improvements!

Renamed the issue but long term this should look like this:

    - uses: actions/upload-artifact@v4
      id: artifact-upload-step
      with:
        name: my-artifact
        path: path/to/artifact/content/

    - name: Output artifact URL
      run:  echo 'Artifact URL is ${{ steps.artifact-upload-step.outputs.artifact-url }}'

@konradpabjan konradpabjan added the enhancement New feature or request label Dec 14, 2023
@konradpabjan konradpabjan changed the title Getting artifact URL in steps after upload-artifact Support artifact URL output Dec 14, 2023
@lukasc-ubc
Copy link

Thank you for the improvements to the Artifact upload/download.

I am wondering if it is possible to have the Artifact go into a permanent URL? I would like my GitHub repo Readme.md file have the URL in the main document, so people can download the Artifact directly. Similar to how the Releases / Latest buttom works. But ideally it would be just a fixed URL, and where the latest Artifact always overwrites the fixed URL.

thank you
Lukas

@wosc
Copy link

wosc commented Jan 8, 2024

Thanks @konradpabjan for the heavy lifting that has gone into v4! I've just tried the following, and that simply worked, I could download the artifact from the URL this generated, no suite-ID or other complications required. So to me this says, the main usecase as outlined in the issue description is now supported by v4 (even if it might be made more convenient to use later on :), which is great news if true! 🎉 (Or did I misunderstand your message, is this a happy accident that is not guaranteed to work, or something else entirely?)

    - uses: actions/upload-artifact@v4
      id: artifact-upload-step
      with:
        name: my-artifact
        path: path/to/artifact/content/

    - name: Output artifact URL
      run:  echo 'Artifact URL is ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}'

@konradpabjan
Copy link
Collaborator

@wosc Yeah so another teammate recently made the URL changes I described and the artifact URLs in the UI now doesn't rely on the check suite ID so things are much simpler! 🎉

Creating a URL with the run ID and artifact ID is now reliable and users can use this to potentially embed artifact links in a host of different places such as PR descriptions, READMEs or issues. I've gone ahead and merged in changes that support an artifact-url output: #496

The PR was merged into main and once we cut a new release then it will be accessible via the @v4 tag at which point we can close out this issue as officially done (We're working on a few more fixes/PRs before cutting a new release).

As described in my earlier content, with @main (and soon @v4) you can now get a URL with something like this.

    - uses: actions/upload-artifact@v4 (right now @main but hang tight until the next release)
      id: artifact-upload-step
      with:
        name: my-artifact
        path: path/to/artifact/content/

    - name: Output artifact URL
      run:  echo 'Artifact URL is ${{ steps.artifact-upload-step.outputs.artifact-url }}'

An important thing to keep in mind is that this URL behavior is exactly as if downloading artifacts from the run summary page in the UI. You must be logged into GitHub for it to work (if browsing as incognito than the URL doesn't even show up). If you do get your hands on a URL while not logged in than it will 404 and prompt you to login. This is for a few scenarios i've seen mentioned where if you take this URL and embed it in some external website and a non-GitHub users tries to click it (anonymous request) than it will 404 and prompt for a download. That's the way it is due to bad actors/security. Logs follows the same pattern where anonymous users/bots can't view & download logs as this opens up a DDOS/attack vector that we can protect ourselves by requiring a simple login. If you really need a download URL that works for users/services that are aren't authenticated with GitHub then the existing API that generates a 1 minute download URL is your only option. If you want some download URL for anonymous downloads for an extended period of time than unfortunately we aren't planning on supporting that due to the security concerns outlined earlier.

The plus side of this URL that is now outputted is that it will work as long as the artifact has not expired. The only other caveats are the run must not be deleted alongside the repository. If your artifact has a retention period of 100 days for example than you can add this URL to a README or somewhere in GitHub like an issue and it will work for 100 days until the artifact expires.

@TWiStErRob
Copy link

Amazing Konrad, thank you for the update!


Friendly reminder for users not to use this new feature for stable releasing... download the artifact from a workflow run and upload the files to the release as (different type of) artifacts for permanent storage on the Releases.

@wosc
Copy link

wosc commented Jan 11, 2024

Thank you Konrad and team, that's excellent news!

jdevalk added a commit to jdevalk/action-wordpress-plugin-build-zip that referenced this issue Jan 23, 2024
1. Make `id` more descriptive so there's less chance of a name clash. 
2. Update to version 4 of the `upload-artifact` action, as [that brings with it the rather cool option to get the artifact URL immediately](actions/upload-artifact#50 (comment)).
@pinpox
Copy link

pinpox commented May 22, 2024

What is the correct syntax to include the URL in a markdown README.md file?
I tried adding ${{ steps.artifact-upload-step.outputs.artifact-url }} to the markdown, but the variable is not being inserted and the markdown renders as is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests