actions / upload-artifact

MIT License
3.23k stars 721 forks source link

Support artifact URL output #50

Closed lelegard closed 5 months ago

lelegard commented 4 years ago

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:

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 commented 4 years ago

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 commented 4 years ago

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

jperl commented 4 years ago

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

jjangga0214 commented 4 years ago

@jperl Hmm, I see. I made an independent issue, https://github.com/actions/upload-artifact/issues/60. This is just letting you know, for the case you want to subscribe or participate in it :)

lanyizi commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

+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 commented 4 years ago

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 commented 4 years ago

šŸ’Æ 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.

jeacott1 commented 4 years ago

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

jerrymarino commented 4 years ago

@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 commented 4 years ago

@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 commented 3 years ago

@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 commented 2 years ago

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

mckrava commented 2 years ago

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.

cdanek commented 2 years ago

+1 for this feature request.

matthewcrozier commented 2 years ago

+1 - this would be a very useful feature!

cansavvy commented 2 years ago

+1 This feature would save me so many headaches! Would be so awesome!

shink commented 2 years ago

+1 Looking forward to this useful feature!!!

mattpopa commented 2 years ago

This feature would be nice, looking forward to it too

lelegard commented 2 years ago

I originally posted this topic more than two years ago. It got 134 šŸ‘ and 23 responses, mostly "I would like it too". The suggestion does not seem too difficult. And we got zero feedback from the Github team. They probably follow their own track and ignore users' requests. This is a bit frustrating. But, let's be realistic, this is a free service, we have no influence.

ghutchis commented 2 years ago

Yes, it's a bit frustrating. I've used @tonyhallett action as linked above. It works well for https://github.com/openchemistry/avogadrolibs - It would be great if GitHub added this support, but in the meantime, there is a workaround.

TWiStErRob commented 2 years ago

Off topic a bit: but @lelegard free?. Yes, there's a free tier, but there are many paid users.

On topic: this is the second most voted issue in this repo, with an easy fix, I think it deserves an @actions to please check this TL;DR and respond.

@lelegard a tip: in OP you were asking for env., but actions have outputs. Here is live example.

lelegard commented 2 years ago

Off topic a bit: but @lelegard free?. Yes, there's a free tier, but there are many paid users.

@TWiStErRob, is there any kind of "premium support" channel for corporate users who pay, where this kind of request could get some response?

Open source developers and free users acknowledge their lack of influence.

vwcruzeiro commented 2 years ago

+1 : this feature would be useful to me.

maksimonishchenko commented 2 years ago

+1 lol its fantastik and only feature lack that stops my super duper company to buy github organization license

deco-dev commented 2 years ago

+1 : this would be useful to me.

geek-kb commented 2 years ago

+1 : this feature would be useful to me.

anatoliykant commented 2 years ago

Do you have any information for us? šŸ¤” We have a paid subscription and spend a lot of money on a github action. I have a lot of experience in setting up ci/cd of different services and we are easily ready to switch to another one (for example, gitlab ci / bitrise / xcode cloud for ios). The only problem is getting the url for the artifact that our testers use. šŸ˜¢ The fact that you simply ignore the developers and users of your service for 2 years does not say anything good about you. šŸ˜¤ At least you could notify us about the approximate dates or write that this feature will never be made. Then we wouldn't bother you.

iflederick commented 2 years ago

+1: need the artifact id (or download url) as an output too

TWiStErRob commented 2 years ago

Off-topic

@TWiStErRob, is there any kind of "premium support" channel for corporate users who pay, where this kind of request could get some response?

@lelegard There's this: https://github.com/premium-support, but it doesn't guarantee any prioritization, just a +1. With bugs, it might be different, but this isn't broken, it's just missing šŸ˜ž → backlog.

sebastiandg7 commented 1 year ago

+1! Keeping this alive.

sammcj commented 1 year ago

Any update on this?

lelegard commented 1 year ago

Any update on this?

Nope. Almost 3 years since I opened it. Still watching it. No news. Most probably, will never be implemented.

saerosV commented 1 year ago

@konradpabjan any comments on this? This feature would be really useful.

The Actions API doesn't seem to properly adress the problem (in an easy manner).

Here's a similar issue, that was (in my opinion) mistakenly closed.

gpavlov2016 commented 1 year ago

+1: need it too

gilzow commented 1 year ago

I would love to be able to link the artifacts to the pull request for people to download.

This is exactly what I've been trying to do and finally came across this issue. Seems like a reasonable request. If I run a test, and the test fails, I'd like to store the test results as an artifact and post a link to those results as a comment on the PR so people can see why a test failed.

mxxk commented 1 year ago

As mentioned in https://github.com/actions/upload-artifact/issues/50#issuecomment-639170787, the GitHub Actions Artifacts API does not show artifacts uploaded during a workflow until after that run has finished. And yet, this is precisely what actions/download-artifact is doing in this official example from Passing data between jobs in a workflow:

job_1:
  steps:
    - uses: actions/upload-artifact@v3
      with:
        name: homework
        path: math-homework.txt
job_2:
  steps:
    - uses: actions/download-artifact@v3
      with:
        name: homework

Interestingly, actions/download-artifact@v3 accomplishes this via @actions/artifact method downloadArtifact, which lists all artifacts for the current run and filters for the requested artifact by name:

const artifacts = await downloadHttpClient.listArtifacts()
if (artifacts.count === 0) {
  throw new Error(
    `Unable to find any artifacts for the associated workflow`
  )
}

const artifactToDownload = artifacts.value.find(artifact => {
  return artifact.name === name
})

Source: actions/toolkit@6c1f9:packages/artifact/src/internal/artifact-client.ts#L164-L173


I presume @actions/artifact can access uploaded artifacts before the run has finished because it uses a private GitHub Actions API:

export function getArtifactUrl(): string {
  const artifactUrl = `${getRuntimeUrl()}_apis/pipelines/workflows/${getWorkFlowRunId()}/artifacts?api-version=${getApiVersion()}`
  debug(`Artifact Url: ${artifactUrl}`)
  return artifactUrl
}

Source: actions/toolkit@6c1f9:packages/artifact/src/internal/utils.ts#L221-L225


Unfortunately, @actions/artifact does not provide a way to obtain the artifact URL without downloading the artifact.

Based on this, GitHub already has the means to access uploaded artifacts before the run is finished. What is missing is a way to get the artifact URL without also downloading it.

djthornton1212 commented 1 year ago

+1: Wow 1,084 day since this was requested and not a peep. I just can't fathom how GitHub thinks this is ok. If I went this long without responding to a customer request (even just to say sorry no can do) I don't think my business would last long.

At times it feels like Actions is just an after thought to them.

etaormm commented 1 year ago

Since no one picked up this issue yet, I've created a new one -- hopefully someone will see it -> https://github.com/actions/upload-artifact/issues/382

egarc12 commented 1 year ago

+1, need the download url as an output to send it in email :(

semack commented 1 year ago

+1

gilzow commented 1 year ago

makes me wonder how many up votes we need to gather before @konradpabjan (or someone else) will notice and finally implement this feature. šŸ¤”

semack commented 1 year ago

makes me wonder how many up votes we need to gather before @konradpabjan (or someone else) will notice and finally implement this feature. šŸ¤”

It could be impossible in the current GitHub design. Artefact Id could be unknown while the workflow runs. But I hope I'm wrong.

Andre601 commented 1 year ago

Hey everyone. I'm curious to know if there is an easy way to obtain the artifact URL from a former job (Not step) for a job depending on the former? Given the fact that I can download artifacts uploaded in a previous job using the download-artifact action tells me that there is a way to obtain the URL. My question is, if that way is easy to achieve within GitHub Actions...

I know this isn't really the place to ask, but my attempts at asking on the GitHub Community ended on deaf ears unfortunately.

djthornton1212 commented 1 year ago

@Andre601

You can use the gh cli to get the url.

gh api "/repos/{owner}/{repo}/actions/artifacts"

In the return json is the key archive_download_url. You can use that to download. If you're using Actions you can also use dawidd6/action-download-artifact. If you use unique names for your artifacts it will find that specific artifact and download it.

Note: The dawidd6/action-download-artifact cannot download artifacts from the same run, but can from other runs.

- name: Download PR Workspace
  uses: dawidd6/action-download-artifact@v2.26.0
  with:
    if_no_artifact_found: fail
    github_token: ${{secrets.GITHUB_TOKEN}}
    name: ${{ env.ARTIFACT_NAME }}

You can checkout the action here.

Andre601 commented 1 year ago

@Andre601

You can use the gh cli to get the url.

gh api "/repos/{owner}/{repo}/actions/artifacts"

In the return json is the key archive_download_url. You can use that to download. If you're using Actions you can also use dawidd6/action-download-artifact. If you use unique names for your artifacts it will find that specific artifact and download it.

Note: The dawidd6/action-download-artifact cannot download artifacts from the same run, but can from other runs.

- name: Download PR Workspace
  uses: dawidd6/action-download-artifact@v2.26.0
  with:
    if_no_artifact_found: fail
    github_token: ${{secrets.GITHUB_TOKEN}}
    name: ${{ env.ARTIFACT_NAME }}

You can checkout the action here.

It's not really about the download, but just getting the URL to it...