appleboy / ssh-action

GitHub Actions for executing remote ssh commands.
https://github.com/marketplace/actions/ssh-remote-commands
MIT License
4.66k stars 567 forks source link

Clean-up log lines via actions core grouping mechanism OR ability to mute log excessive output #254

Open Stas-AbsoluteDesign opened 1 year ago

Stas-AbsoluteDesign commented 1 year ago

Currently, when you execute ssh-action, it outputs the whole screen of log lines that can't be collapsed! Including completely excessive lines with your ssh script passed to execute on the remote server 😮

This is a real example of just a small script that is a part of ~200 lines of bash script for release logic:

======CMD======
#!/bin/bash
set -e

#### extract the Artifact and remove on success
cd $RELEASE
tar -mxf release.tar.gz
tar -mxf release-file1.tar.gz
tar -mxf release-file2.tar.gz
rm -f release.tar.gz
rm -f release-file1.tar.gz
rm -f release-file2.tar.gz

#### map new symlinks for specified shared folders
echo "INFO: trying to map shared folders in $ROOT."
for FOLDER in $FOLDERS; do
  if [ ! -z "$FOLDER" ] && [ -e "$RELEASE/$FOLDER" ]; then
    cd $RELEASE && rm -rf $FOLDER
    echo "INFO: Removed existing folder $RELEASE/$FOLDER"
  else
    echo "INFO: No existing folder found on $RELEASE/$FOLDER. Skipping removal."
  fi
  if [ ! -z "$FOLDER" ] && [ -e "$ROOT/shared/$FOLDER" ]; then
    cd $RELEASE && ln -nsf ../../../shared/$FOLDER $FOLDER
    echo "INFO: Mapped folder ../shared/$FOLDER."
  else
    echo "INFO: No symlink folder found for ../shared/$FOLDER. Skipping mapping."
  fi
done
......................................................
.............there goes LOTS MORE LINES...............
......................................................
======END======
out: INFO: trying to map shared folders in ***.
out: INFO: No existing folder found on ***/releases/2023_06_12_15_05_28/pub/media. Skipping removal.
out: INFO: Mapped folder ../shared/pub/media.
out: INFO: Removed existing folder ***/releases/2023_06_12_15_05_28/pub/showroom
out: INFO: Mapped folder ../shared/pub/showroom.
out: INFO: No existing folder found on ***/releases/2023_06_12_15_05_28/var/log. Skipping removal.
out: INFO: Mapped folder ../shared/var/log.
out: INFO: No existing folder found on ***/releases/2023_06_12_15_05_28/var/import. Skipping removal.
out: INFO: Mapped folder ../shared/var/import.
out: INFO: No existing folder found on ***/releases/2023_06_12_15_05_28/var/export. Skipping removal.
out: INFO: Mapped folder ../shared/var/export.
out: INFO: No existing folder found on ***/releases/2023_06_12_15_05_28/var/importexport. Skipping removal.
out: INFO: Mapped folder ../shared/var/importexport.
......................................................
.............there goes LOTS MORE LINES...............
.............there goes LOTS MORE LINES...............
.............there goes LOTS MORE LINES...............
.............there goes LOTS MORE LINES...............
.............there goes LOTS MORE LINES...............
......................................................
==============================================
✅ Successfully executed commands to all host.
==============================================

As you can see, there are a couple of issues:

  1. Script for execution is being passed right into output at the very beginning
  2. Lines can't be collapsed

So if you have along script like mine with about ~200 lines long shell script that is messing around releasing.. and it producing even longer output (hundreds of lines!).. it all of a sudden becomes super messy to check the general log.


SOLUTION proposal is simple: make a collapsible grouping using core Actions functionality for grouping log lines

Official documentation: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines

Example:

echo "::group::Rsync process started"
echo "Inside group, executing commands, the whole lot of things echoing here"
echo "::endgroup::"

That will make a nice and clean log grouping. For example, self-made grouping for my custom action\step, which is collapsed by default and can be opened by clicking: image

P.S. Probably, the only vital thing without grouping would be DONE or FAIL status in the end. The current executing script (that is being dumped at the beginning) can be definitely collapsed, as well as the execution log output.

P.P.S. Also, if you can't add line grouping - it would be super great to have a param that will mute everything but the final result output (ok\fail)! e.g. it is unclear how the default debug param now works... but for example, once set to "false" it will group output, but if you pass "true" it will just dump the whole lot in the actions log.

Regards, Stas

Stas-AbsoluteDesign commented 1 year ago

Pretty please, can we add this? Logging is relatively easy to implement (theoretically) :)