mirror of
https://github.com/appleboy/ssh-action.git
synced 2025-04-07 19:21:59 +00:00
Merge branch 'appleboy:master' into master
This commit is contained in:
commit
fbf2b7866a
9 changed files with 203 additions and 129 deletions
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
|
@ -25,7 +25,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
|
9
.github/workflows/main.yml
vendored
9
.github/workflows/main.yml
vendored
|
@ -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:
|
||||
|
|
41
.github/workflows/stable.yml
vendored
41
.github/workflows/stable.yml
vendored
|
@ -31,7 +31,7 @@ jobs:
|
|||
sleep 2
|
||||
|
||||
- name: ssh by username and password
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
|
@ -42,6 +42,15 @@ jobs:
|
|||
set -e
|
||||
whoami
|
||||
|
||||
- name: ssh commands from a file
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
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:
|
||||
|
@ -86,7 +95,7 @@ jobs:
|
|||
sleep 2
|
||||
|
||||
- name: ssh by private key
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
|
@ -95,7 +104,7 @@ jobs:
|
|||
script: whoami
|
||||
|
||||
- name: wrong password but correct key
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
|
@ -105,7 +114,7 @@ jobs:
|
|||
script: whoami
|
||||
|
||||
- name: correct password but wrong key
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
|
@ -115,7 +124,7 @@ jobs:
|
|||
script: whoami
|
||||
|
||||
- name: stop script if command error
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
|
@ -174,7 +183,7 @@ jobs:
|
|||
sleep 2
|
||||
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
|
@ -186,7 +195,7 @@ jobs:
|
|||
ls -al
|
||||
|
||||
- name: missing ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
|
@ -199,7 +208,7 @@ jobs:
|
|||
|
||||
# https://github.com/appleboy/ssh-action/issues/75#issuecomment-668314271
|
||||
- name: Multiline SSH commands interpreted as single lines
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
|
@ -277,7 +286,7 @@ jobs:
|
|||
|
||||
# https://github.com/appleboy/ssh-action/issues/85
|
||||
- name: Deployment to multiple hosts with different ports
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: "${{ env.REMOTE_HOST_01 }}:2222,${{ env.REMOTE_HOST_02 }}:2222"
|
||||
username: linuxserver.io
|
||||
|
@ -331,7 +340,7 @@ jobs:
|
|||
sleep 2
|
||||
|
||||
- name: testing id_ed25519 key
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
|
@ -384,7 +393,7 @@ jobs:
|
|||
sleep 2
|
||||
|
||||
- name: testing id_ed25519 key
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
|
@ -395,7 +404,7 @@ jobs:
|
|||
ls -al
|
||||
|
||||
- name: pass environment
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
env:
|
||||
FOO: "BAR"
|
||||
with:
|
||||
|
@ -409,7 +418,7 @@ jobs:
|
|||
echo "I am $BAR, thanks"
|
||||
|
||||
- name: pass multiple environment
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
env:
|
||||
FOO: "BAR"
|
||||
BAR: "FOO"
|
||||
|
@ -428,7 +437,7 @@ jobs:
|
|||
echo "port: $PORT"
|
||||
|
||||
- name: custom envs format
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
env:
|
||||
FOO: "BAR"
|
||||
AAA: "BBB"
|
||||
|
@ -446,7 +455,7 @@ jobs:
|
|||
echo "I am $TEST_AAA, thanks"
|
||||
|
||||
- name: pass all ENV variables to script
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
env:
|
||||
INPUT_FOO: "BAR"
|
||||
INPUT_AAA: "BBB"
|
||||
|
@ -463,7 +472,7 @@ jobs:
|
|||
echo "$GITHUB_REF"
|
||||
|
||||
- name: switch to root user
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ env.REMOTE_HOST }}
|
||||
username: linuxserver.io
|
||||
|
|
55
README.md
55
README.md
|
@ -3,15 +3,13 @@
|
|||
[繁體中文](./README.zh-tw.md)
|
||||
[简体中文](./README.zh-cn.md)
|
||||
|
||||
[GitHub Action](https://github.com/features/actions) for executing remote ssh commands.
|
||||
[GitHub Action](https://github.com/features/actions) for executing remote SSH commands.
|
||||
|
||||

|
||||
|
||||
[](https://github.com/appleboy/ssh-action/actions)
|
||||
[](https://github.com/appleboy/ssh-action/actions/workflows/main.yml)
|
||||
|
||||
**Important**: Only support **Linux** [docker](https://www.docker.com/) container.
|
||||
|
||||
This thing is built using [Golang](https://go.dev) and [drone-ssh](https://github.com/appleboy/drone-ssh). 🚀
|
||||
This project is built using [Golang](https://go.dev) and [drone-ssh](https://github.com/appleboy/drone-ssh). 🚀
|
||||
|
||||
## Input variables
|
||||
|
||||
|
@ -35,6 +33,7 @@ See [action.yml](./action.yml) for more detailed information.
|
|||
| fingerprint | SHA256 fingerprint of the host public key | |
|
||||
| proxy_host | SSH proxy host | |
|
||||
| proxy_port | SSH proxy port | 22 |
|
||||
| proxy_protocol | SSH proxy protocol version (tcp, tcp4, tcp6) | tcp |
|
||||
| proxy_username | SSH proxy username | |
|
||||
| proxy_password | SSH proxy password | |
|
||||
| proxy_passphrase | SSH proxy key passphrase | |
|
||||
|
@ -45,16 +44,17 @@ 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 | |
|
||||
| debug | Enable debug mode | false |
|
||||
| allenvs | pass the environment variables with prefix value of `GITHUB_` and `INPUT_` to the script | false |
|
||||
| allenvs | Pass the environment variables with prefix value of `GITHUB_` and `INPUT_` to the script | false |
|
||||
| request_pty | Request a pseudo-terminal from the server | false |
|
||||
|
||||
## Usage
|
||||
|
||||
Executing remote ssh commands.
|
||||
Executing remote SSH commands.
|
||||
|
||||
```yaml
|
||||
name: remote ssh command
|
||||
|
@ -66,10 +66,10 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
username: linuxserver.io
|
||||
password: ${{ secrets.PASSWORD }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script: whoami
|
||||
|
@ -81,7 +81,7 @@ output:
|
|||
======CMD======
|
||||
whoami
|
||||
======END======
|
||||
out: ***
|
||||
linuxserver.io
|
||||
===============================================
|
||||
✅ Successfully executed commands to all hosts.
|
||||
===============================================
|
||||
|
@ -182,7 +182,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -195,7 +195,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using ssh key
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -208,7 +208,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||
|
||||
```yaml
|
||||
- name: multiple command
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -221,11 +221,24 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||
|
||||

|
||||
|
||||
#### Commands from a file
|
||||
|
||||
```yaml
|
||||
- name: file commands
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script_path: scripts/script.sh
|
||||
```
|
||||
|
||||
#### Multiple Hosts
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
- host: "foo.com"
|
||||
+ host: "foo.com,bar.com"
|
||||
|
@ -243,7 +256,7 @@ The default value of `port` is `22`.
|
|||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
- host: "foo.com"
|
||||
+ host: "foo.com:1234,bar.com:5678"
|
||||
|
@ -258,7 +271,7 @@ The default value of `port` is `22`.
|
|||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: "foo.com,bar.com"
|
||||
+ sync: true
|
||||
|
@ -274,7 +287,7 @@ The default value of `port` is `22`.
|
|||
|
||||
```diff
|
||||
- name: pass environment
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
+ env:
|
||||
+ FOO: "BAR"
|
||||
+ BAR: "FOO"
|
||||
|
@ -299,7 +312,7 @@ _Inside `env` object, you need to pass every environment variable as a string, p
|
|||
|
||||
```diff
|
||||
- name: stop script if command error
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -352,7 +365,7 @@ Host FooServer
|
|||
|
||||
```diff
|
||||
- name: ssh proxy command
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -375,7 +388,7 @@ It is not uncommon for files to leak from backups or decommissioned hardware, an
|
|||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -401,7 +414,7 @@ Now you can adjust you config:
|
|||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
|
|
@ -4,9 +4,7 @@
|
|||
|
||||

|
||||
|
||||
[](https://github.com/appleboy/ssh-action/actions)
|
||||
|
||||
**注意**: 只支持在 **Linux** [docker](https://www.docker.com/) 容器上执行。
|
||||
[](https://github.com/appleboy/ssh-action/actions/workflows/main.yml)
|
||||
|
||||
## 输入变量
|
||||
|
||||
|
@ -24,6 +22,7 @@
|
|||
* `key_path` - SSH 私钥的路径
|
||||
* `fingerprint` - 主机公钥的 SHA256 指纹,默认为跳过验证
|
||||
* `script` - 执行命令
|
||||
* `script_file` - 執行命令的文件
|
||||
* `script_stop` - 当出现第一个错误时停止执行命令
|
||||
* `envs` - 传递环境变量到 shell script
|
||||
* `debug` - 启用调试模式
|
||||
|
@ -58,7 +57,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -157,7 +156,7 @@ ssh-keygen -t ed25519 -a 200 -C ”your_email@example.com“
|
|||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -170,7 +169,7 @@ ssh-keygen -t ed25519 -a 200 -C ”your_email@example.com“
|
|||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using ssh key
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -183,7 +182,7 @@ ssh-keygen -t ed25519 -a 200 -C ”your_email@example.com“
|
|||
|
||||
```yaml
|
||||
- name: multiple command
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -200,7 +199,7 @@ ssh-keygen -t ed25519 -a 200 -C ”your_email@example.com“
|
|||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
- host: ”foo.com“
|
||||
+ host: ”foo.com,bar.com“
|
||||
|
@ -212,11 +211,24 @@ ssh-keygen -t ed25519 -a 200 -C ”your_email@example.com“
|
|||
ls -al
|
||||
```
|
||||
|
||||
#### Commands from a file
|
||||
|
||||
```yaml
|
||||
- name: file commands
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script_path: scripts/script.sh
|
||||
```
|
||||
|
||||
#### 多个不同端口的主机
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
- host: ”foo.com“
|
||||
+ host: ”foo.com:1234,bar.com:5678“
|
||||
|
@ -231,7 +243,7 @@ ssh-keygen -t ed25519 -a 200 -C ”your_email@example.com“
|
|||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ”foo.com,bar.com“
|
||||
+ sync: true
|
||||
|
@ -247,7 +259,7 @@ ssh-keygen -t ed25519 -a 200 -C ”your_email@example.com“
|
|||
|
||||
```diff
|
||||
- name: pass environment
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
+ env:
|
||||
+ FOO: ”BAR“
|
||||
+ BAR: ”FOO“
|
||||
|
@ -272,7 +284,7 @@ _在 `env` 对象中,您需要将每个环境变量作为字符串传递,传
|
|||
|
||||
```diff
|
||||
- name: stop script if command error
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -325,7 +337,7 @@ Host FooServer
|
|||
|
||||
```diff
|
||||
- name: ssh proxy command
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -346,7 +358,7 @@ Host FooServer
|
|||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -372,7 +384,7 @@ ssh example.com ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub | cut -d ’
|
|||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
|
119
README.zh-tw.md
119
README.zh-tw.md
|
@ -1,50 +1,58 @@
|
|||
# 🚀 用於 GitHub Actions 的 SSH
|
||||
# 🚀 GitHub Actions 的 SSH
|
||||
|
||||
[GitHub Action](https://github.com/features/actions) for executing remote ssh commands.
|
||||
[English](./README.md)
|
||||
[简体中文](./README.zh-cn.md)
|
||||
|
||||
[GitHub Action](https://github.com/features/actions) 用於執行遠端 SSH 命令。
|
||||
|
||||

|
||||
|
||||
[](https://github.com/appleboy/ssh-action/actions)
|
||||
[](https://github.com/appleboy/ssh-action/actions/workflows/main.yml)
|
||||
|
||||
**注意**: 只支援在 **Linux** [docker](https://www.docker.com/) 容器上執行。
|
||||
此專案使用 [Golang](https://go.dev) 和 [drone-ssh](https://github.com/appleboy/drone-ssh) 建立。🚀
|
||||
|
||||
## 輸入變數
|
||||
|
||||
更詳細的資訊,請參閱 [action.yml](./action.yml)。
|
||||
請參閱 [action.yml](./action.yml) 以獲取更詳細的信息。
|
||||
|
||||
* `host` - SSH 主機
|
||||
* `port` - SSH 連接埠,預設為 `22`
|
||||
* `username` - SSH 使用者名稱
|
||||
* `password` - SSH 密碼
|
||||
* `passphrase` - 通常用於加密私鑰的 passphrase
|
||||
* `sync` - 同步執行多個主機上的命令,預設為 false
|
||||
* `timeout` - SSH 連接到遠端主機的超時時間,預設為 `30s`
|
||||
* `command_timeout` - SSH 命令超時時間,預設為 10m
|
||||
* `key` - SSH 私鑰的內容,例如 ~/.ssh/id_rsa 的原始內容,請記得包含 BEGIN 和 END 行
|
||||
* `key_path` - SSH 私鑰的路徑
|
||||
* `fingerprint` - 主機公鑰的 SHA256 指紋,預設為略過驗證
|
||||
* `script` - 執行命令
|
||||
* `script_stop` - 當出現第一個錯誤時停止執行命令
|
||||
* `envs` - 傳遞環境變數到 shell script
|
||||
* `debug` - 啟用偵錯模式
|
||||
* `use_insecure_cipher` - 使用不安全的密碼(ciphers)進行加密,參見 [#56](https://github.com/appleboy/ssh-action/issues/56)
|
||||
* `cipher` - 允許使用的密碼(ciphers)演算法。如果未指定,則使用適當的演算法
|
||||
| 輸入參數 | 描述 | 預設值 |
|
||||
| ------------------------- | ----------------------------------------------------- | ------ |
|
||||
| host | SSH 主機地址 | |
|
||||
| port | SSH 埠號 | 22 |
|
||||
| passphrase | SSH 金鑰密碼 | |
|
||||
| username | SSH 使用者名稱 | |
|
||||
| password | SSH 密碼 | |
|
||||
| protocol | SSH 協議版本 (tcp, tcp4, tcp6) | tcp |
|
||||
| sync | 如果有多個主機,啟用同步執行 | false |
|
||||
| use_insecure_cipher | 包含更多不安全的加密算法 | false |
|
||||
| cipher | 允許的加密算法。如果未指定,則使用合理的預設值 | |
|
||||
| timeout | SSH 連接主機的超時時間 | 30s |
|
||||
| command_timeout | SSH 命令的超時時間 | 10m |
|
||||
| key | SSH 私鑰的內容。例如,~/.ssh/id_rsa 的原始內容 | |
|
||||
| key_path | SSH 私鑰的路徑 | |
|
||||
| fingerprint | 主機公鑰的 SHA256 指紋 | |
|
||||
| proxy_host | SSH 代理主機 | |
|
||||
| proxy_port | SSH 代理埠號 | 22 |
|
||||
| proxy_protocol | SSH 代理協議版本 (tcp, tcp4, tcp6) | tcp |
|
||||
| proxy_username | SSH 代理使用者名稱 | |
|
||||
| proxy_password | SSH 代理密碼 | |
|
||||
| proxy_passphrase | SSH 代理金鑰密碼 | |
|
||||
| proxy_timeout | SSH 連接代理主機的超時時間 | 30s |
|
||||
| proxy_key | SSH 代理私鑰的內容 | |
|
||||
| proxy_key_path | SSH 代理私鑰的路徑 | |
|
||||
| proxy_fingerprint | 代理主機公鑰的 SHA256 指紋 | |
|
||||
| proxy_cipher | 代理允許的加密算法 | |
|
||||
| proxy_use_insecure_cipher | 包含更多不安全的加密算法 | false |
|
||||
| script | 執行命令 | |
|
||||
| script_file | 從文件中執行命令 | |
|
||||
| script_stop | 在第一次失敗後停止腳本 | false |
|
||||
| envs | 將環境變數傳遞給 shell 腳本 | |
|
||||
| envs_format | 環境值傳遞的靈活配置 | |
|
||||
| debug | 啟用調試模式 | false |
|
||||
| allenvs | 將帶有 `GITHUB_` 和 `INPUT_` 前綴的環境變數傳遞給腳本 | false |
|
||||
| request_pty | 從伺服器請求偽終端 | false |
|
||||
|
||||
SSH 代理設置:
|
||||
|
||||
* `proxy_host` - 代理主機
|
||||
* `proxy_port` - 代理端口,預設為 `22`
|
||||
* `proxy_username` - 代理使用者名稱
|
||||
* `proxy_password` - 代理密碼
|
||||
* `proxy_passphrase` - 密碼通常用於加密私有金鑰
|
||||
* `proxy_timeout` - SSH 連線至代理主機的逾時時間,預設為 `30s`
|
||||
* `proxy_key` - SSH 代理私有金鑰內容
|
||||
* `proxy_key_path` - SSH 代理私有金鑰路徑
|
||||
* `proxy_fingerprint` - 代理主機公鑰的 SHA256 指紋,預設為跳過驗證
|
||||
* `proxy_use_insecure_cipher` - 使用不安全的加密方式,請參閱 [#56](https://github.com/appleboy/ssh-action/issues/56)
|
||||
* `proxy_cipher` - 允許的加密算法。如果未指定,則使用合理的算法
|
||||
|
||||
## 使用方式
|
||||
## 用法
|
||||
|
||||
執行遠端 SSH 命令
|
||||
|
||||
|
@ -58,7 +66,7 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -157,7 +165,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using password
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -170,7 +178,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||
|
||||
```yaml
|
||||
- name: executing remote ssh commands using ssh key
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -183,7 +191,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||
|
||||
```yaml
|
||||
- name: multiple command
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -196,11 +204,24 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||
|
||||

|
||||
|
||||
#### Commands from a file
|
||||
|
||||
```yaml
|
||||
- name: file commands
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
key: ${{ secrets.KEY }}
|
||||
port: ${{ secrets.PORT }}
|
||||
script_path: scripts/script.sh
|
||||
```
|
||||
|
||||
#### 多台主機
|
||||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
- host: "foo.com"
|
||||
+ host: "foo.com,bar.com"
|
||||
|
@ -216,7 +237,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
- host: "foo.com"
|
||||
+ host: "foo.com:1234,bar.com:5678"
|
||||
|
@ -231,7 +252,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||
|
||||
```diff
|
||||
- name: multiple host
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: "foo.com,bar.com"
|
||||
+ sync: true
|
||||
|
@ -247,7 +268,7 @@ ssh-keygen -t ed25519 -a 200 -C "your_email@example.com"
|
|||
|
||||
```diff
|
||||
- name: pass environment
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
+ env:
|
||||
+ FOO: "BAR"
|
||||
+ BAR: "FOO"
|
||||
|
@ -272,7 +293,7 @@ _在 `env` 對象中,您需要將每個環境變量作為字符串傳遞,傳
|
|||
|
||||
```diff
|
||||
- name: stop script if command error
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -325,7 +346,7 @@ Host FooServer
|
|||
|
||||
```diff
|
||||
- name: ssh proxy command
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -346,7 +367,7 @@ Host FooServer
|
|||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
@ -372,7 +393,7 @@ ssh example.com ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub | cut -d ' '
|
|||
|
||||
```diff
|
||||
- name: ssh key passphrase
|
||||
uses: appleboy/ssh-action@v1.1.0
|
||||
uses: appleboy/ssh-action@v1.2.0
|
||||
with:
|
||||
host: ${{ secrets.HOST }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
|
|
|
@ -43,6 +43,9 @@ inputs:
|
|||
description: "SSH proxy username."
|
||||
proxy_password:
|
||||
description: "SSH proxy password."
|
||||
proxy_protocol:
|
||||
description: 'The IP protocol to use. Valid values are "tcp". "tcp4" or "tcp6". Default to tcp.'
|
||||
default: "tcp"
|
||||
proxy_passphrase:
|
||||
description: "SSH proxy key passphrase."
|
||||
proxy_timeout:
|
||||
|
@ -60,6 +63,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:
|
||||
|
@ -113,6 +118,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 }}
|
||||
|
|
|
@ -8,7 +8,7 @@ export GITHUB="true"
|
|||
|
||||
GITHUB_ACTION_PATH="${GITHUB_ACTION_PATH%/}"
|
||||
DRONE_SSH_RELEASE_URL="${DRONE_SSH_RELEASE_URL:-https://github.com/appleboy/drone-ssh/releases/download}"
|
||||
DRONE_SSH_VERSION="${DRONE_SSH_VERSION:-1.7.7}"
|
||||
DRONE_SSH_VERSION="${DRONE_SSH_VERSION:-1.8.0}"
|
||||
|
||||
function detect_client_info() {
|
||||
if [ -n "${SSH_CLIENT_OS-}" ]; then
|
||||
|
@ -17,20 +17,21 @@ function detect_client_info() {
|
|||
local kernel
|
||||
kernel="$(uname -s)"
|
||||
case "${kernel}" in
|
||||
Darwin)
|
||||
CLIENT_PLATFORM="darwin"
|
||||
;;
|
||||
Linux)
|
||||
CLIENT_PLATFORM="linux"
|
||||
;;
|
||||
Windows)
|
||||
CLIENT_PLATFORM="windows"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown, unsupported platform: ${kernel}." >&2
|
||||
echo "Supported platforms: Linux, Darwin and Windows." >&2
|
||||
echo "Bailing out." >&2
|
||||
exit 2
|
||||
Darwin)
|
||||
CLIENT_PLATFORM="darwin"
|
||||
;;
|
||||
Linux)
|
||||
CLIENT_PLATFORM="linux"
|
||||
;;
|
||||
Windows)
|
||||
CLIENT_PLATFORM="windows"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown, unsupported platform: ${kernel}." >&2
|
||||
echo "Supported platforms: Linux, Darwin and Windows." >&2
|
||||
echo "Bailing out." >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
|
@ -40,18 +41,18 @@ function detect_client_info() {
|
|||
local machine
|
||||
machine="$(uname -m)"
|
||||
case "${machine}" in
|
||||
x86_64*|i?86_64*|amd64*)
|
||||
CLIENT_ARCH="amd64"
|
||||
;;
|
||||
aarch64*|arm64*)
|
||||
CLIENT_ARCH="arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown, unsupported architecture (${machine})." >&2
|
||||
echo "Supported architectures x86_64, i686, arm64." >&2
|
||||
echo "Bailing out." >&2
|
||||
exit 3
|
||||
;;
|
||||
x86_64* | i?86_64* | amd64*)
|
||||
CLIENT_ARCH="amd64"
|
||||
;;
|
||||
aarch64* | arm64*)
|
||||
CLIENT_ARCH="arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown, unsupported architecture (${machine})." >&2
|
||||
echo "Supported architectures x86_64, i686, arm64." >&2
|
||||
echo "Bailing out." >&2
|
||||
exit 3
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
|
3
testdata/test.sh
vendored
Normal file
3
testdata/test.sh
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
whoami
|
Loading…
Add table
Reference in a new issue