Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@corporateuser
Copy link
Contributor

fix: do not fail command if grep has not found any version

fix: do not fail command if grep has not found any version
@corporateuser
Copy link
Contributor Author

Fix #45

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @corporateuser! Left a comment.

action.yml Outdated
if [ $len -gt 1 ]; then
PACKAGE_MANAGER=$(echo "$INPUT_PM" | grep -o '^[^@]*')
VERSION=$(echo "$INPUT_PM" | grep -o '@.*' | sed 's/^@//')
VERSION=$(echo "$INPUT_PM" | grep -o '@.*' || true | sed 's/^@//')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran a quick test locally and this seems to change the output of this command.

# current command:
echo "[email protected]" | grep -o '@.*' | sed 's/^@//'
# output:
14.7.0

# PR change:
echo "[email protected]" | grep -o '@.*' || true | sed 's/^@//'
# output:
@14.7.0

Grouping the central command does seem to work though:

Suggested change
VERSION=$(echo "$INPUT_PM" | grep -o '@.*' || true | sed 's/^@//')
VERSION=$(echo "$INPUT_PM" | (grep -o '@.*' || true) | sed 's/^@//')

(Although I am 100% not a shell script expert so this may not be the correct fix)

Copy link
Contributor Author

@corporateuser corporateuser Aug 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right
my command is equal to:
echo "[email protected]" | grep -o '@.*' || { true | sed 's/^@//'; }
The proper command will be
echo "[email protected]" | { grep -o '@.*' || true; } | sed 's/^@//'

Fix: proper grouping for grep
Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @corporateuser — the updated command works for me locally 👍

@delucis delucis changed the title Update action.yml Support shorthand for package-manager option Aug 5, 2024
@delucis delucis merged commit 6046791 into withastro:main Aug 5, 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

Successfully merging this pull request may close these issues.

2 participants