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

Is it possible to not fail the workflow if the artifact doesn't exist? #42

Open
benjamincharity opened this issue Jul 9, 2020 · 13 comments · May be fixed by #208, #286 or #301
Open

Is it possible to not fail the workflow if the artifact doesn't exist? #42

benjamincharity opened this issue Jul 9, 2020 · 13 comments · May be fixed by #208, #286 or #301

Comments

@benjamincharity
Copy link

benjamincharity commented Jul 9, 2020

We've been having intermittent issues uploading our coverage reports from our GitHub action. These issues are displayed as 403s which cause really, really long jobs. In order for this to not block steps that come after test coverage, we are moving the coverage upload to a final step after all other.

The issue we have is that coverage is not always generated. In those cases, download artifact fails that final step and the entire workflow is marked as failed.

Screen Shot 2020-07-09 at 9 31 03 AM

Our flow:

a) check if any packages have changes since last run
b) if changed, run tests
c) upload coverage (if no test are run, no coverage exists but the uploader does gracefully exit)
d) all other steps
e) attempt to upload coverage (FAIL if no coverage is found)

Is there a way to gracefully fail if the artifact hasn't been uploaded since in some cases this is not a failure from our standpoint?


Ninja edit: I did see the option continue-on-error, but the overall workflow is still shown with the red 'x' so at a glance it appears our entire release is failing to consumers.

@konradpabjan
Copy link
Collaborator

konradpabjan commented Jul 29, 2020

Currently it is not possible to not fail the workflow if no artifact is found

Some customization is on the way for upload-artifact: actions/upload-artifact#104

Perhaps a similar option could prove useful for download-artifact. Something like if-no-artifact: with options error, warn or ignore? 🤔

@mdreizin
Copy link

Any updates on this issue?

@raymiranda
Copy link

Currently it is not possible to not fail the workflow if no artifact is found

Some customization is on the way for upload-artifact: actions/upload-artifact#104

Perhaps a similar option could prove useful for download-artifact. Something like if-no-artifact: with options error, warn or ignore? 🤔

I was having the same issue. After reviewing the method used, I can see that if you don't specific a name on the download, it will attempt to create the directories regardless.

const artifactClient = artifact.create() if (!name) { // download all artifacts core.info('No artifact name specified, downloading all artifacts') core.info( 'Creating an extra directory for each artifact that is being downloaded' )

This worked for me as a work around.

@jkowalleck
Copy link

@benjamincharity maybe use
continue-on-error: true -- see https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepscontinue-on-error

@benjamincharity
Copy link
Author

@benjamincharity maybe use
continue-on-error: true -- see docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepscontinue-on-error

I called this out in the original edit. There are multiple ways to functionally unblock ourselves to get around this, but from what I've seen each method will still mark our workflow as failed in the PR and primary repo badge. So any contributor or consumer needs to actually go see if our build is really failing or if it is just one optional step that is failing.

@jkowalleck
Copy link

jkowalleck commented Aug 24, 2020

@benjamincharity you should check on this again.

i dd a quick playground to replicate the behavior you described.

i used continue-on-error: true
it marks the workflow as passed, badges are passed.
even the step is marked as passed. see https://github.com/jkowalleck/playground_download-artifact_issue-42/runs/1022858445?check_suite_focus=true

PS:
nevertheless i like idea of @konradpabjan as of #42 (comment)

@benjamincharity
Copy link
Author

benjamincharity commented Aug 24, 2020

@jkowalleck thanks for calling this out. From your test it sure does looks like you are correct. I'll be happy to be wrong on this 😄 I will give it a test as soon as I can. Thanks!

@maapteh
Copy link

maapteh commented Oct 28, 2020

Hi, we fixed it in if statement. We check for existence of coverage file:

      - name: Check file existence for sonar integration
        id: sonar
        uses: andstor/file-existence-action@v1
        with:
          files: "sonar-project.properties, coverage/lcov.info"

      - name: Upload coverage file
        if: steps.sonar.outputs.files_exists == 'true'
        uses: actions/upload-artifact@v2
        with:
          name: coverage-file
          path: coverage/lcov.info

hope it helps someone, we made it defensive since its a pipeline for multiple apps. Some are mature and some not :)

@rethab
Copy link

rethab commented Mar 23, 2022

@konradpabjan would you accept a PR that adds the if-no-artifact input as you suggested?

@0xJohnnyboy
Copy link

Hi, we fixed it in if statement. We check for existence of coverage file:

      - name: Check file existence for sonar integration
        id: sonar
        uses: andstor/file-existence-action@v1
        with:
          files: "sonar-project.properties, coverage/lcov.info"

      - name: Upload coverage file
        if: steps.sonar.outputs.files_exists == 'true'
        uses: actions/upload-artifact@v2
        with:
          name: coverage-file
          path: coverage/lcov.info

hope it helps someone, we made it defensive since its a pipeline for multiple apps. Some are mature and some not :)

Actually not sure it solves anything because we're talking about download here. How would you check that the file in the artifact exists if it isn't downloaded yet ?

Did someone find a workaround ?

@benjamincharity maybe use continue-on-error: true -- see https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepscontinue-on-error

This would be the best solution imho.

I'll probably make an action myself returning true or false as an output if there are artifacts. I can't think of another way to do it for now

@xSAVIKx
Copy link

xSAVIKx commented Jun 9, 2022

Stumbled across this need and found no way of checking if some artifact exists. So created a new action: https://github.com/marketplace/actions/check-artifact-existence

You can add a new step that is going to expose and output denoting if an artifact exists or not by the given artifact name:

uses: actions/xSAVIKx/artifact-exists-action@v0
id: check_coverage_artifact
with:
  name: 'coverage-artifact'

Then you can use steps.check_coverage_artifact.outputs.exists (true/false) in the conditions.

@iSuslov
Copy link

iSuslov commented May 21, 2023

Just don't use this action and call gh directly:

      - name: Download artifact
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: echo $(gh run download -n my-artifact-name)

https://cli.github.com/manual/gh_run_download

@jsoref jsoref linked a pull request Jan 30, 2024 that will close this issue
@croemheld croemheld linked a pull request Feb 24, 2024 that will close this issue
@ryooo
Copy link

ryooo commented May 11, 2024

In my case, I was able to do the following.

      - id: check-artifact-exist
        run: |
          url="https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${run-id}/artifacts"
          echo "artifact-name=$(curl -fsSL "$url" | jq -r '.artifacts[0].name')" >> $GITHUB_OUTPUT
      - uses: actions/download-artifact@v4
        if:
          ${{ steps.check-artifact-exist.outputs.artifact-name ==
          'xxx' }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
12 participants