From 644b4b43b0d938c76a8cb1a8d7acb5a7956fcc3f Mon Sep 17 00:00:00 2001
From: Kyle Leonhard <leonhard.kyle@gmail.com>
Date: Wed, 23 Oct 2024 18:58:10 -0700
Subject: [PATCH] Support running commands from a file

---
 .github/workflows/main.yml |  9 +++++++++
 README.md                  | 14 ++++++++++++++
 action.yml                 |  3 +++
 testdata/test.sh           |  3 +++
 4 files changed, 29 insertions(+)
 create mode 100644 testdata/test.sh

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index e248967..6c35463 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -42,6 +42,15 @@ jobs:
             set -e
             whoami
 
+      - name: ssh commands from a file
+        uses: ./
+        with:
+          host: ${{ env.REMOTE_HOST }}
+          username: linuxserver.io
+          password: password
+          port: 2222
+          script_path: testdata/test.sh
+
   check-ssh-key:
     runs-on: ubuntu-latest
     steps:
diff --git a/README.md b/README.md
index 347f512..2e893af 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,7 @@ See [action.yml](./action.yml) for more detailed information.
 | proxy_cipher              | Allowed cipher algorithms for the proxy                                                  |               |
 | proxy_use_insecure_cipher | Include more ciphers with use_insecure_cipher for the proxy                              | false         |
 | script                    | Execute commands                                                                         |               |
+| script_file               | Execute commands from a file                                                             |               |
 | script_stop               | Stop script after first failure                                                          | false         |
 | envs                      | Pass environment variables to shell script                                               |               |
 | envs_format               | Flexible configuration of environment value transfer                                     |               |
@@ -221,6 +222,19 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
 
 ![result](./images/output-result.png)
 
+#### Commands from a file
+
+```yaml
+- name: file commands
+  uses: appleboy/ssh-action@v1.1.0
+  with:
+    host: ${{ secrets.HOST }}
+    username: ${{ secrets.USERNAME }}
+    key: ${{ secrets.KEY }}
+    port: ${{ secrets.PORT }}
+    script_path: scripts/script.sh 
+```
+
 #### Multiple Hosts
 
 ```diff
diff --git a/action.yml b/action.yml
index 4a16472..d5f019c 100644
--- a/action.yml
+++ b/action.yml
@@ -60,6 +60,8 @@ inputs:
     description: "Include more ciphers for the proxy by using insecure ciphers."
   script:
     description: "Commands to be executed."
+  script_path:
+    description: "Path to the file containing commands to be executed."
   script_stop:
     description: "Stop the script after the first failure."
   envs:
@@ -107,6 +109,7 @@ runs:
         INPUT_PROXY_TIMEOUT: ${{ inputs.proxy_timeout }}
         INPUT_COMMAND_TIMEOUT: ${{ inputs.command_timeout }}
         INPUT_SCRIPT: ${{ inputs.script }}
+        INPUT_SCRIPT_FILE: ${{ inputs.script_path }}
         INPUT_SCRIPT_STOP: ${{ inputs.script_stop }}
         INPUT_ENVS: ${{ inputs.envs }}
         INPUT_ENVS_FORMAT: ${{ inputs.envs_format }}
diff --git a/testdata/test.sh b/testdata/test.sh
new file mode 100644
index 0000000..3574ebc
--- /dev/null
+++ b/testdata/test.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+set -e
+whoami
\ No newline at end of file