gruntwork-io / fetch

Download files, folders, and release assets from a specific git commit, branch, or tag of public and private GitHub repos.
https://www.gruntwork.io/
MIT License
587 stars 90 forks source link

Prevent silent fail #104

Open MohammedAl-Mahdawi opened 2 years ago

MohammedAl-Mahdawi commented 2 years ago

Hi!,

We are using this command in our CI/CD pipeline:

fetch --repo="https://github.com/..." --tag="1.0.9" --github-oauth-token="****" --release-asset="example-v1.0.9.zip" tmp-path

Yesterday this command fails because of a GitHub authorization error, however, it only logs the error instead of exiting with non-zero code this causes the pipeline to continue then exist on another step that depends on what has been downloaded by fetch.

Please we need an option to exit on error.

denis256 commented 2 years ago

Hi, I was trying to check this issue, however, on the last version exit code is 1 in case of an error:

$ fetch --repo="https://github.com/gruntwork-io/terraform-aws-ci" --tag="v0.41.1" --github-oauth-token="***" --release-asset "infrastructure-deployer_linux_386" tmp-path
[fetch] ERRO[2022-01-26T23:21:59+02:00] 
Received an HTTP 401 Response when attempting to query the repo for its tags.

This means that either your GitHub oAuth Token is invalid, or that the token is valid but is being used to request access
to either a public repo or a private repo to which you don't have access.

Underlying error message:
Received HTTP Response 401 while fetching releases for GitHub URL https://api.github.com/repos/gruntwork-io/terraform-aws-ci/tags?per_page=100. Full HTTP response: {"message":"Bad credentials","documentation_url":"https://docs.github.com/rest"}

$ echo $?
1

On which version occurred this issue?

MohammedAl-Mahdawi commented 2 years ago

Hi!

Thank you for the quick reply!

We are using v0.4.2

I read the release notes of version v0.4.3 before posting this and did not found anything related.

So it has been fixed in the new release?

denis256 commented 2 years ago

Hi, so from the above message, in my test exit code wasn't 0 in case of failure:

...
$ echo $?
1

Exiting with non-zero code is already implemented, may be an issue with code which call fetch that is not handling error code? like missing set -euxo pipefail?

MohammedAl-Mahdawi commented 2 years ago

Hi!

Weird, I believe the commands in pipeline steps get wrapped in #!/usr/bin/env bash and executed.

We are using it as a step alone so it is executed like this:

#!/usr/bin/env bash

fetch --repo="https://github.com/..." --tag="1.0.9" --github-oauth-token="****" --release-asset="example-v1.0.9.zip" tmp-path

But everything works fine with other commands/steps!

What makes things weirder, I just tried to reproduce the issue and this time it exited with a non-zero code!