MichaelCurrin / dev-cheatsheets

A collection of code snippets and CLI guides for quick and easy reference while coding
https://michaelcurrin.github.io/dev-cheatsheets/
MIT License
78 stars 27 forks source link

"npm outdated" may span across multiple lines #49

Open rkrisztian opened 1 year ago

rkrisztian commented 1 year ago

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 commented 11 months ago

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 commented 11 months ago

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