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

"npm outdated" may span across multiple lines #49

Open
rkrisztian opened this issue Oct 2, 2023 · 2 comments
Open

"npm outdated" may span across multiple lines #49

rkrisztian opened this issue Oct 2, 2023 · 2 comments

Comments

@rkrisztian
Copy link

rkrisztian commented Oct 2, 2023

I see the following at https://michaelcurrin.github.io/dev-cheatsheets/cheatsheets/ci-cd/github-actions/persist.html :

Examples

Get output from npm outdated command, if any.

steps:
 - name: Check for outdated packages
   id: vars
   run: |
     OUTDATED=$(npm outdated) || true
     
     echo "OUTDATED={OUTDATED}" >> $GITHUB_OUTPUT
      
 - name: Upgrade
   if: ${{ steps.vars.outputs.OUTDATED != '' }}
   run: npm upgrade

I think this example is just wrong and misleading. The output of npm outdated may span across multiple lines, breaking the expected syntax of GITHUB_OUTPUT.

AFAIK, the right solution is this:
https://github.com/github/docs/pull/21599/files

@MichaelCurrin
Copy link
Owner

What do you think about this?

echo "OUTDATED='$OUTDATED'" >> $GITHUB_OUTPUT

To give this.

OUTPUT='Package                           Current  Wanted  Latest  Location                                       Depended by
@types/mocha                       10.0.1  10.0.3  10.0.3  node_modules/@types/mocha                      ...
...
'

@rkrisztian
Copy link
Author

rkrisztian commented Oct 27, 2023

Well, unfortunately the problem is that the syntax expected to be stored in GITHUB_OUTPUT is not bash code. The apostrophes would be literal characters stored in the value of property OUTDATED, breaking the condition ${{ steps.vars.outputs.OUTDATED != '' }} as well.
See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings

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

2 participants