From c54d7dfa895c5826003391bb8a947f9c3c6b1c23 Mon Sep 17 00:00:00 2001 From: Karolis2011 Date: Wed, 19 Nov 2025 23:21:20 +0200 Subject: [PATCH] feat: check for SSH, attempt install via package manager if missing --- action.yml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/action.yml b/action.yml index 27fb301..78f6ee8 100644 --- a/action.yml +++ b/action.yml @@ -57,6 +57,46 @@ runs: # Create SSH directory mkdir -p ~/.ssh chmod 700 ~/.ssh + + # Ensure ssh client is present. If not, try to install using a known + # package manager (apt, yum/dnf, apk, brew, pkg). If installation + # fails, stop early with helpful message. + if ! command -v ssh >/dev/null 2>&1; then + echo "SSH client 'ssh' not found. Attempting to install..." + + if command -v apt-get >/dev/null 2>&1; then + echo "Using apt-get to install openssh-client" + sudo apt-get update -qq + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y openssh-client + + elif command -v yum >/dev/null 2>&1 || command -v dnf >/dev/null 2>&1; then + echo "Using yum/dnf to install openssh-clients" + sudo yum install -y openssh-clients || sudo dnf install -y openssh-clients + + elif command -v apk >/dev/null 2>&1; then + echo "Using apk to install openssh-client" + sudo apk add --no-cache openssh-client + + elif command -v brew >/dev/null 2>&1; then + echo "Using Homebrew to install openssh" + brew update >/dev/null || true + brew install openssh + + elif command -v pkg >/dev/null 2>&1; then + echo "Using pkg to install openssh" + sudo pkg install -y openssh + + else + echo "No known package manager found to install SSH client. Please install 'ssh' and rerun." >&2 + exit 1 + fi + + # Verify the install worked + if ! command -v ssh >/dev/null 2>&1; then + echo "Failed to install SSH client automatically — please install 'ssh' and rerun." >&2 + exit 1 + fi + fi # Setup SSH private key SSH_KEY_PATH="$HOME/.ssh/github_action_key"