fix: add debug option for SSH remote shell wrapper to assist with troubleshooting
This commit is contained in:
parent
5ca29a1899
commit
4861d65a3c
3 changed files with 64 additions and 6 deletions
32
action.yml
32
action.yml
|
|
@ -35,6 +35,10 @@ inputs:
|
|||
description: 'Shell to use on remote server (bash, sh, zsh, etc.)'
|
||||
required: false
|
||||
default: 'bash'
|
||||
debug-shell-wrapper:
|
||||
description: 'Enable debug logging in the SSH remote wrapper (prints script path and contents)'
|
||||
required: false
|
||||
default: 'false'
|
||||
|
||||
outputs:
|
||||
ssh-config-path:
|
||||
|
|
@ -212,10 +216,21 @@ runs:
|
|||
# Use BatchMode to prevent interactive prompts
|
||||
# ConnectTimeout to fail fast if connection issues
|
||||
echo "Executing script on remote server '${{ inputs.ssh-host }}' via SSH..."
|
||||
# Print some debug information if requested. See 'debug-shell-wrapper' input.
|
||||
if [ "${SSH_REMOTE_DEBUG-}" = "true" ]; then
|
||||
echo "[ssh-remote wrapper] Script file: $SCRIPT_FILE"
|
||||
echo "[ssh-remote wrapper] Script contents:" >&2
|
||||
sed -n '1,200p' "$SCRIPT_FILE"
|
||||
echo "[ssh-remote wrapper] ---------- end script ----------"
|
||||
fi
|
||||
ssh -o BatchMode=yes \
|
||||
-o ConnectTimeout=10 \
|
||||
github-action-host \
|
||||
"${{ inputs.remote-shell }} -s" < "$SCRIPT_FILE"
|
||||
SSH_EXIT_CODE=$?
|
||||
if [ "${SSH_REMOTE_DEBUG-}" = "true" ]; then
|
||||
echo "[ssh-remote wrapper] SSH exit code: $SSH_EXIT_CODE"
|
||||
fi
|
||||
WRAPPER_EOF
|
||||
|
||||
chmod +x "$WRAPPER_PATH"
|
||||
|
|
@ -223,12 +238,12 @@ runs:
|
|||
# We also create symlink without the .sh extension to provide a
|
||||
# short executable name inside the wrapper dir (e.g. $WRAPPER_DIR/ssh-remote)
|
||||
ln -s "$WRAPPER_PATH" "$WRAPPER_DIR/ssh-remote"
|
||||
if [ "${{ inputs.use-shell-wrapper }}" = "true" ]; then
|
||||
echo ""
|
||||
echo "To use the remote shell in subsequent steps, add:"
|
||||
echo " shell: ssh-remote {0}"
|
||||
echo ""
|
||||
echo "The 'ssh-remote' shell is now available for use."
|
||||
if [ "${{ inputs.debug-shell-wrapper }}" = "true" ]; then
|
||||
# Persist debug flag to the job environment; the wrapper can pick
|
||||
# this up later when the job runs. This allows debugging without
|
||||
# changing the wrapper script at runtime.
|
||||
echo "SSH_REMOTE_DEBUG=true" >> $GITHUB_ENV
|
||||
echo "⚠️ SSH remote shell wrapper debug is enabled (SSH_REMOTE_DEBUG=true)"
|
||||
fi
|
||||
echo "shell-wrapper-dir=$WRAPPER_DIR" >> $GITHUB_OUTPUT
|
||||
echo "shell-wrapper-path=$WRAPPER_PATH" >> $GITHUB_OUTPUT
|
||||
|
|
@ -243,3 +258,8 @@ runs:
|
|||
echo "Adding custom shell 'ssh-remote' to PATH"
|
||||
echo "PATH=$SHELL_WRAPPER_DIR:$PATH" >> $GITHUB_ENV
|
||||
echo "✅ Custom shell 'ssh-remote' registered for this job"
|
||||
echo ""
|
||||
echo "To use the remote shell in subsequent steps, add:"
|
||||
echo " shell: ssh-remote {0}"
|
||||
echo ""
|
||||
echo "The 'ssh-remote' shell is now available for use."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue