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

artifacts-helper alias does not work in shell scripts #55

Open
tudatnms opened this issue Apr 22, 2024 · 3 comments
Open

artifacts-helper alias does not work in shell scripts #55

tudatnms opened this issue Apr 22, 2024 · 3 comments

Comments

@tudatnms
Copy link

Hi, I am using the artifacts-helper to get auth token for .npmrc. It works fine if I run yarn directly from the terminal. However, I see an error when trying to call yarn in a shell script.

error An unexpected error occurred: "Failed to replace env in config: ${ARTIFACTS_ACCESSTOKEN}"

I believe this is because an alias for yarn set in bashrc: alias yarn=/usr/local/bin/run-yarn.sh does not work if I call yarn from a shell script. Currently, as a workaround, I need to have a check if /usr/local/bin/run-yarn.sh exists then run it instead of yarn, something like:

# this is to support codespace (should find a better way to not have codespace specific code in the repo)
if [ -f "/usr/local/bin/run-yarn.sh" ]; then
    /usr/local/bin/run-yarn.sh lint-staged
else
    yarn lint-staged
fi

But I wonder if there is any recommendation to get over this issue to not have this check in all scripts, and also not have codespace specific code in the source repo.

Thanks.

@markphip
Copy link
Contributor

markphip commented Apr 22, 2024

Open to ideas but it is just a hack using bash aliases. Maybe your shell scripts are not using bash? If they are using sh that could be why. Adding the shebang for bash to your scripts would at least not be codespaces specific.

#!/usr/bin/env bash

@tudatnms
Copy link
Author

Unfortunately using shebang (e.g. #!/usr/bin/env bash) does not work. I don't think alias will work across either bash/shell scripts, but I'm not sure. Agree that using bash aliases is hacky. I don't have a better idea than calling run-yarn.sh directly in scripts. Will report back if I find a better way. Thanks.

@cmbrose
Copy link
Contributor

cmbrose commented Jul 29, 2024

#65 might help here - in v2.0.2+ functions are used instead of aliases which should behave better.

Another trick that I found useful when running into a similar issue was to use BASH_ENV to set up default shell imports even for non-interactive shells.

@fanee030 fanee030 linked a pull request Aug 23, 2024 that will close this issue
@fanee030 fanee030 removed a link to a pull request Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants