39 Commits

Author SHA1 Message Date
Bo-Yi Wu
8b3eebcc8d Merge pull request #11 from dbingham/fixTypo
Some checks failed
scp files / Build (push) Failing after 5s
Update to drone-scp 1.5.6
2020-02-27 11:19:51 +08:00
Daniel Bingham
861f2e0e7b Update to drone-scp 1.5.6
To pull in the fix for the typo related to proxy_paraphrase
2020-02-26 18:19:00 -08:00
Bo-Yi Wu
6971270956 Add rm default value. 2020-02-25 23:47:04 +08:00
Bo-Yi Wu
bac6c9e026 update rm default value 2020-02-25 23:46:08 +08:00
Bo-Yi Wu
b04405242e chore: improve ci workflow 2020-02-14 00:49:23 +08:00
Bo-Yi Wu
5cb36bda99 chore: add proxy setting
Some checks failed
scp files / Build (push) Failing after 4s
2020-01-20 23:08:15 +08:00
Bo-Yi Wu
6c5771fab8 chore: Add passphrase 2020-01-20 23:07:25 +08:00
Bo-Yi Wu
193fd4eaa9 chore: add passphrase testing 2020-01-20 22:51:17 +08:00
Bo-Yi Wu
a5de8af6d5 chore: update default timeout to 10 minutes
Some checks failed
scp files / Build (push) Failing after 4s
2019-11-30 23:17:05 +08:00
Bo-Yi Wu
671c934c80 Update README.md 2019-09-30 21:52:10 +08:00
Bo-Yi Wu
8da6e3d335 update docs
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-30 16:59:44 +08:00
Bo-Yi Wu
196ea3f88f chore(scp): default port is 22
Some checks failed
scp files / Build (push) Failing after 4s
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-30 16:58:33 +08:00
Bo-Yi Wu
034b0ad00c Update README.md 2019-09-30 11:38:02 +08:00
Bo-Yi Wu
95e250284b docs: update readme 2019-09-29 14:16:22 +08:00
Bo-Yi Wu
a593d18cb8 docs: add default value of timeout 2019-09-29 01:45:56 +08:00
Bo-Yi Wu
2e28e2ddc9 chore: bump drone-scp to 1.5.3
Some checks failed
scp files / Build (push) Failing after 6s
2019-09-29 01:43:03 +08:00
Bo-Yi Wu
f8189f0fbf chore(scp): add overwrite and tar_tmp_path 2019-09-29 01:42:21 +08:00
Bo-Yi Wu
722ddfc32b chore: upgrade to drone-scp:1.5.2
Some checks failed
scp files / Build (push) Failing after 7s
2019-09-28 12:55:25 +08:00
Bo-Yi Wu
e506e72e83 remove debug message
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-28 12:45:17 +08:00
Bo-Yi Wu
bd7b71696a debug
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-28 12:43:06 +08:00
Bo-Yi Wu
b1b9ed628c docs: update default value 2019-09-28 12:41:21 +08:00
Bo-Yi Wu
72fe6fa2ca add default value
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-28 12:39:28 +08:00
Bo-Yi Wu
f1b7ce641c update INPUT_STRIP_COMPONENTS
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-28 12:37:22 +08:00
Bo-Yi Wu
722d935a90 update INPUT_STRIP_COMPONENTS
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-28 12:34:38 +08:00
Bo-Yi Wu
6fd371aeaf docs: add example 2019-09-28 12:26:40 +08:00
Bo-Yi Wu
5138976c70 docs: add badge 2019-09-28 12:17:08 +08:00
Bo-Yi Wu
d322577e98 docs: update readme 2019-09-28 12:16:21 +08:00
Bo-Yi Wu
c0a815a115 docs: update readme. 2019-09-28 12:13:03 +08:00
Bo-Yi Wu
afd2e26f9f chore: copy file via ssh key 2019-09-28 12:01:18 +08:00
Bo-Yi Wu
2ef3f5e459 chore: check timeout variable 2019-09-28 11:40:28 +08:00
Bo-Yi Wu
f0de4fea6f chore: add default timeout 2019-09-28 11:37:34 +08:00
Bo-Yi Wu
03e93ae863 chore: update target 2019-09-28 11:32:50 +08:00
Bo-Yi Wu
bffdab6759 chore: update 2019-09-28 11:23:50 +08:00
Bo-Yi Wu
e22c039905 chore: checkout source code. 2019-09-28 11:15:01 +08:00
Bo-Yi Wu
44284b60e4 chore: add timeout flag 2019-09-28 11:10:11 +08:00
Bo-Yi Wu
b154adaf5c chore: copy file via ssh password 2019-09-28 10:54:49 +08:00
Bo-Yi Wu
a6224ab4f0 chore: add github actions config 2019-09-28 10:42:13 +08:00
Bo-Yi Wu
1a31789cbc chore: rename the worflow file 2019-09-28 10:32:00 +08:00
Bo-Yi Wu
74e3e1df58 docs: add args command helper. 2019-05-12 10:25:37 +08:00
6 changed files with 263 additions and 147 deletions

65
.github/main.workflow vendored
View File

@@ -1,65 +0,0 @@
workflow "Copy File Via SSH" {
on = "push"
resolves = [
"Copy file via ssh password",
"Copy file via ssh key",
"Add source in args",
"Add secret in args",
]
}
action "Copy file via ssh password" {
uses = "appleboy/scp-action@master"
env = {
SOURCE = "tests/a.txt,tests/b.txt"
TARGET = "/home/actions/test"
}
secrets = [
"HOST",
"USERNAME",
"PASSWORD",
]
}
action "Copy file via ssh key" {
uses = "appleboy/scp-action@master"
env = {
SOURCE = "tests/a.txt,tests/b.txt"
TARGET = "/home/actions/test"
}
secrets = [
"HOST",
"USERNAME",
"KEY",
]
}
action "Add source in args" {
uses = "appleboy/scp-action@master"
env = {
TARGET = "/home/actions/test1234"
}
secrets = [
"HOST",
"USERNAME",
"KEY",
]
args = ["--source", "tests/a.txt", "--source", "tests/b.txt"]
}
action "Add secret in args" {
uses = "appleboy/scp-action@master"
env = {
TARGET = "/home/actions/test1234"
}
secrets = [
"HOST",
"TEST_USERNAME",
"KEY",
]
args = [
"--username", "$TEST_USERNAME",
"--source", "tests/a.txt",
"--source", "tests/b.txt",
]
}

52
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,52 @@
name: scp files
on: [push]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v1
- name: copy file via ssh password
uses: ./
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
source: "tests/a.txt,tests/b.txt"
target: "test"
- name: copy file via ssh key
uses: ./
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
source: "tests/a.txt,tests/b.txt"
target: "test"
- name: remove the specified number of leading path elements
uses: ./
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
source: "tests/a.txt,tests/b.txt"
target: "foobar"
strip_components: 1
- name: ssh key with passphrase
uses: ./
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH2 }}
passphrase: ${{ secrets.PASSPHRASE }}
port: ${{ secrets.PORT }}
source: "tests/a.txt,tests/b.txt"
target: "test"

View File

@@ -1,15 +1,4 @@
FROM appleboy/drone-scp:1.5.1-linux-amd64
# Github labels
LABEL "com.github.actions.name"="SCP Files"
LABEL "com.github.actions.description"="Copy files and artifacts via SSH"
LABEL "com.github.actions.icon"="copy"
LABEL "com.github.actions.color"="gray-dark"
LABEL "repository"="https://github.com/appleboy/scp-action"
LABEL "homepage"="https://github.com/appleboy"
LABEL "maintainer"="Bo-Yi Wu <appleboy.tw@gmail.com>"
LABEL "version"="0.0.1"
FROM appleboy/drone-scp:1.5.6-linux-amd64
ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

213
README.md
View File

@@ -1,97 +1,170 @@
# 🚀 SCP for GitHub Actions
[GitHub Action](https://developer.github.com/actions/) for copying files and artifacts via SSH.
[GitHub Action](https://github.com/features/actions) for copying files and artifacts via SSH.
<img src="./images/copy-multiple-file.png">
![ssh key](./images/copy-multiple-file.png)
[![Actions Status](https://github.com/appleboy/scp-action/workflows/scp%20files/badge.svg)](https://github.com/appleboy/scp-action/actions)
## Usage
copy files and artifacts via SSH as blow.
```
action "Copy multiple file" {
uses = "appleboy/scp-action@master"
env = {
HOST = "example.com"
USERNAME = "foo"
PASSWORD = "bar"
PORT = "22"
SOURCE = "tests/a.txt,tests/b.txt"
TARGET = "/home/foo/test"
}
secrets = [
"PASSWORD",
]
}
```yaml
name: scp files
on: [push]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: copy file via ssh password
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
source: "tests/a.txt,tests/b.txt"
target: "test"
```
## Environment variables
## Input variables
* HOST - ssh server host
* PORT - ssh server port
* USERNAME - ssh server username
* PASSWORD - ssh server password
* KEY - ssh server private key
* TARGET - target folder
* SOURCE - scp file list
see the [action.yml](./action.yml) file for more detail imformation.
* host - scp remote host
* port - scp remote port, default is `22`
* username - scp username
* password - scp password
* passphrase - the passphrase is usually to encrypt the private key
* timeout - timeout for ssh to remote host, default is `30s`
* command_timeout - timeout for scp command, default is `10m`
* key - content of ssh private key. ex raw content of ~/.ssh/id_rsa
* key_path - path of ssh private key
* target - target path on the server
* source - scp file list
* rm - remove target folder before upload data, default is `false`
* strip_components - remove the specified number of leading path elements.
* overwrite - use `--overwrite` flag with tar
* tar_tmp_path - temporary path for tar file on the dest host
SSH Proxy Setting:
* proxy_host - proxy host
* proxy_port - proxy port, default is `22`
* proxy_username - proxy username
* proxy_password - proxy password
* proxy_passphrase - the passphrase is usually to encrypt the private key
* proxy_timeout - timeout for ssh to proxy host, default is `30s`
* proxy_key - content of ssh proxy private key.
* proxy_key_path - path of ssh proxy private key
### Example
Copy file via ssh password
```
action "Copy multiple file" {
uses = "appleboy/scp-action@master"
env = {
HOST = "example.com"
USERNAME = "foo"
PORT = "22"
SOURCE = "tests/a.txt,tests/b.txt"
TARGET = "/home/foo/test"
}
secrets = [
"PASSWORD",
]
}
```yaml
- name: copy file via ssh password
uses: appleboy/scp-action@master
with:
host: example.com
username: foo
password: bar
port: 22
source: "tests/a.txt,tests/b.txt"
target: "test"
```
Copy file via ssh key
```
action "Copy file via ssh key" {
uses = "appleboy/scp-action@master"
env = {
HOST = "example.com"
USERNAME = "foo"
PORT = "22"
SOURCE = "tests/c.txt,tests/d.txt"
TARGET = "/home/actions/test"
}
secrets = [
"KEY",
]
}
```yaml
- name: copy file via ssh key
uses: appleboy/scp-action@master
env:
HOST: ${{ secrets.HOST }}
USERNAME: ${{ secrets.USERNAME }}
PORT: ${{ secrets.PORT }}
KEY: ${{ secrets.KEY }}
with:
source: "tests/a.txt,tests/b.txt"
target: "test"
```
Example configuration for ignore list:
```
action "reqular expression list" {
uses = "appleboy/scp-action@master"
env = {
HOST = "example.com"
USERNAME = "foo"
PORT = "22"
SOURCE = "tests/*.txt,!tests/a.txt"
TARGET = "/home/actions/test"
}
secrets = [
"KEY",
]
}
```yaml
- name: copy file via ssh key
uses: appleboy/scp-action@master
env:
HOST: ${{ secrets.HOST }}
USERNAME: ${{ secrets.USERNAME }}
PORT: ${{ secrets.PORT }}
KEY: ${{ secrets.KEY }}
with:
source: "tests/*.txt,!tests/a.txt"
target: "test"
```
## Secrets
Example configuration for multiple server
* `PASSWORD` - ssh server password
* `KEY` - ssh server private key
```diff
uses: appleboy/scp-action@master
with:
- host: "example.com"
+ host: "foo.com,bar.com"
username: foo
password: bar
port: 22
source: "tests/a.txt,tests/b.txt"
target: "test"
```
remove the specified number of leading path elements
```yaml
- name: remove the specified number of leading path elements
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.KEY }}
port: ${{ secrets.PORT }}
source: "tests/a.txt,tests/b.txt"
target: "foobar"
strip_components: 1
```
old target structure:
```sh
foobar
└── tests
├── a.txt
└── b.txt
```
new target structure:
```sh
foobar
├── a.txt
└── b.txt
```
Protecting a Private Key. The purpose of the passphrase is usually to encrypt the private key. This makes the key file by itself useless to an attacker. It is not uncommon for files to leak from backups or decommissioned hardware, and hackers commonly exfiltrate files from compromised systems.
```diff
- name: ssh key with passphrase
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH2 }}
+ passphrase: ${{ secrets.PASSPHRASE }}
port: ${{ secrets.PORT }}
source: "tests/a.txt,tests/b.txt"
target: "test"
```

65
action.yml Normal file
View File

@@ -0,0 +1,65 @@
name: 'SCP Command to Transfer Files'
description: 'How to Use SCP Command to Transfer Files/Folders in Linux'
author: 'Bo-Yi Wu'
inputs:
host:
description: 'scp remote host'
port:
description: 'scp remote port'
default: 22
username:
description: 'scp username'
password:
description: 'scp password'
timeout:
description: 'timeout for ssh to remote host'
default: "30s"
command_timeout:
description: 'timeout for scp command'
default: "10m"
key:
description: 'content of ssh private key. ex raw content of ~/.ssh/id_rsa'
key_path:
description: 'path of ssh private key'
passphrase:
description: 'ssh key passphrase'
target:
description: 'target path on the server'
source:
description: 'scp file list'
rm:
description: 'remove target folder before upload data'
default: false
strip_components:
description: 'remove the specified number of leading path elements'
default: 0
overwrite:
description: 'use `--overwrite` flag with tar'
default: false
tar_tmp_path:
description: 'temporary path for tar file on the dest host'
proxy_host:
description: 'ssh proxy remote host'
proxy_port:
description: 'ssh proxy remote port'
default: 22
proxy_username:
description: 'ssh proxy username'
proxy_password:
description: 'ssh proxy password'
proxy_passphrase:
description: 'ssh proxy key passphrase'
proxy_timeout:
description: 'timeout for ssh to proxy host'
default: "30s"
proxy_key:
description: 'content of ssh proxy private key. ex raw content of ~/.ssh/id_rsa'
proxy_key_path:
description: 'path of ssh proxy private key'
runs:
using: 'docker'
image: 'Dockerfile'
branding:
icon: 'copy'
color: 'gray-dark'

View File

@@ -4,4 +4,6 @@ set -eu
export GITHUB="true"
[ -n "$INPUT_STRIP_COMPONENTS" ] && export INPUT_STRIP_COMPONENTS=$((INPUT_STRIP_COMPONENTS + 0))
sh -c "/bin/drone-scp $*"