Call node from powershell

90 views Asked by At

I am trying to create a yml file for a Github locally hosted action runner that calls an npm module called "terser" to minify js and css.

  - name: Minify_JS
  if:  ${{ contains(inputs.SHOULD_MINIFY, 'true') }}
  run: | 
      $folder = "C:\Build\${{inputs.REPOS_NAME}}"
      $files = get-childitem $folder -recurse -force -include *.js    
      foreach($file in $files){ D:\Progra~1\nodejs\node.exe C:\Build\node_modules\terser\bin\terser --compress --mangle --output $file.FullName -- $file.FullName    }
      echo "JS minified!"
      #java -jar  D:\Atlassian\Bamboo-Ant-Tasks\lib\yuicompressor-2.4.7.jar $file.FullName -o $file.FullName

So the operative line of code is D:\Progra~1\nodejs\node.exe C:\Build\node_modules\terser\bin\terser --compress --mangle --output $file.FullName -- $file.FullName

That line will work from the command line but when I run it via the action runner I get the error below.

D:\Progra~1\nodejs\node.exe : The term 'D:\Progra~1\nodejs\node.exe' is not recognized as the name of a cmdlet, 

function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\actions-runner_work_temp\beb4cf2f-8512-429c-8624-a9493ed16748.ps1:4 char:27

  • foreach($file in $files){ D:\Progra~1\nodejs\node.exe C:\Build\node_m ...
  •                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (D:\Progra~1\nodejs\node.exe:String) [], ParentContainsErrorRecordExcept ion
    • FullyQualifiedErrorId : CommandNotFoundException
1

There are 1 answers

0
gabriel On

it turned out that "Environment variables are not hot reloaded so every time new commands get added to the path, power shell, cmd or the GitHub service need to be restarted so they can load the new environment..." so in our case we just restarted the Github Action Runner Service that gets installed on windows and that fixed the issue