Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Dalla Santa committed Dec 18, 2020
0 parents commit ca82210
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test

on:
push:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- uses: underscore69/ssh-scp-deploy@main
with:
local: "./"
remote: "~/"
host: ${{secrets.HOST}}
user: ${{secrets.USER}}
key: ${{secrets.KEY}}
pre_upload: echo "pre_upload 👈"
post_upload: echo "post_upload 👉"
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# [Unreleased]

## [v1.0.0] - 2020-12-18

### Added
- First definition of the action.


[v1.0.0]: https://github.com/underscore69/ssh-scp-deploy/tree/v1.0.0
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM alpine:latest

RUN apk update && \
apk add --no-cache ca-certificates \
openssh-client \
sshpass \
bash

COPY LICENSE README.md /

COPY entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)

Copyright (c) 2020 Marco Dalla Santa and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ssh-scp-deploy

[![Action type](https://img.shields.io/badge/Docker%20action-262b31?logo=docker&logoColor=2496ed)](https://docs.github.com/en/actions/creating-actions/about-actions#types-of-actions)
[![License](https://img.shields.io/github/license/underscore69/ssh-scp-deploy)](https://opensource.org/licenses/MIT)
[![Pipeline status](https://img.shields.io/github/workflow/status/underscore69/ssh-scp-deploy/Test?label=test)](./)

This action provide an easy and higly customizable way to upload files via scp and execute a set of command via ssh before or/and after.

## Supported runners
[![Supported runner](https://img.shields.io/badge/Linux-262b31?style=for-the-badge&logo=linux&logoColor=fcc624)](https://docs.github.com/en/actions/creating-actions/about-actions#docker-container-actions)

## Usage
```yaml
- uses: underscore69/[email protected]
with:
local: './' # Local file path - REQUIRED false - DEFAULT ./
remote: '~/' # Remote file path - REQUIRED false - DEFAULT ~/
host: ${{secrets.HOST}} # Remote server address - REQUIRED true
port: ${{secrets.PORT}} # Remote server port - REQUIRED false - DEFAULT 22
user: ${{secrets.USER}} # Remote server user - REQUIRED true
password: ${{secrets.PASSWORD}} # User password - REQUIRED at least one of "password" or "key"
key: ${{secrets.KEY}} # Remote server private key - REQUIRED at least one of "password" or "key"
pre_upload: echo "This will be executed before the upload!" # Command to run via ssh before scp upload - REQUIRED false
post_upload: echo "This will be executed after the upload!" # Command to run via ssh after scp upload - REQUIRED false
ssh_options: -o StrictHostKeyChecking=no # A set of ssh_option separated by -o - REQUIRED false - DEFAULT -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
scp_options: -v # Flags to use during scp - REQUIRED false - DEFAULT ''
```
## License
The source code, scripts and documentation in this project are released under the [MIT License](LICENSE)
61 changes: 61 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: 'ssh-scp-deploy'
description: 'A GitHub Action that upload the artifact via scp and runs commands before or/and after.'
author: 'Marco Dalla Santa'

inputs:
local:
description: 'Local file path'
required: false
default: './'

remote:
description: 'Remote file path'
required: false
default: '~/'

host:
description: 'Remote server address'
required: true

port:
description: 'Remote server port (default 22)'
required: false
default: 22

user:
description: 'Remote server user'
required: true

password:
description: 'User password'
required: false

key:
description: 'Remote server private key'
required: false

pre_upload:
description: 'Command to run via ssh before scp upload'
required: false

post_upload:
description: 'Command to run via ssh after scp upload'
required: false

ssh_options:
description: 'A set of ssh_option separated by -o'
required: false
default: -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null

scp_options:
description: 'Flags to use during scp'
required: false
default:

runs:
using: 'docker'
image: 'Dockerfile'

branding:
icon: 'upload-cloud'
color: 'green'
15 changes: 15 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
PASSWORD=${INPUT_PASSWORD}
KEY=${INPUT_KEY}
if [ -z "$PRE_UPLOAD" and "$PASSWORD"]; then
echo "🔑 Please provide at least a key or a password...";
exit 0;
fi

if [[ ! -z "$KEY" ]]; then
echo "🔑 Using key file...";
. with_key.sh;
else
echo "🔑 Using password...";
. with_pass.sh;
fi
24 changes: 24 additions & 0 deletions with_key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
echo "🔑 Adding ssh key..." &&
eval $(ssh-agent -s) &&
ssh-add <(echo "${INPUT_KEY}") &&
echo "🔐 Added ssh key";

PRE_UPLOAD=${INPUT_PRE_UPLOAD}
if [ ! -z "$PRE_UPLOAD" ]; then
echo "👌 Executing pre-upload script..." &&
ssh ${INPUT_SSH_OPTIONS} ${INPUT_USER}@${INPUT_HOST} "$INPUT_PRE_UPLOAD && exit" &&
echo "✅ Executed pre-upload script";
fi

echo "🚚 Uploading via scp..." &&
scp ${INPUT_SSH_OPTIONS} ${INPUT_SCP_OPTIONS} -P "${INPUT_PORT}" -r ${INPUT_LOCAL} ubuntu@${INPUT_HOST}:"${INPUT_REMOTE}" &&
echo "🙌 Uploaded via scp";

POST_UPLOAD=${INPUT_POST_UPLOAD}
if [ ! -z "$POST_UPLOAD" ]; then
echo "👌 Executing post-upload script..." &&
ssh ${INPUT_SSH_OPTIONS} ${INPUT_USER}@${INPUT_HOST} "$POST_UPLOAD && exit" &&
echo "✅ Executed post-upload script";
fi

echo "🎉 Done";
19 changes: 19 additions & 0 deletions with_pass.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PRE_UPLOAD=${INPUT_PRE_UPLOAD}
if [ ! -z "$PRE_UPLOAD" ]; then
echo "👌 Executing pre-upload script..." &&
sshpass -p ${PASSWORD} ssh ${INPUT_SSH_OPTIONS} ${INPUT_USER}@${INPUT_HOST} "$INPUT_PRE_UPLOAD && exit" &&
echo "✅ Executed pre-upload script";
fi

echo "🚚 Uploading via scp..." &&
sshpass -p ${PASSWORD} scp ${INPUT_SSH_OPTIONS} ${INPUT_SCP_OPTIONS} -P "${INPUT_PORT}" -r ${INPUT_LOCAL} ubuntu@${INPUT_HOST}:"${INPUT_REMOTE}" &&
echo "🙌 Uploaded via scp";

POST_UPLOAD=${INPUT_POST_UPLOAD}
if [ ! -z "$POST_UPLOAD" ]; then
echo "👌 Executing post-upload script..." &&
sshpass -p ${PASSWORD} ssh ${INPUT_SSH_OPTIONS} ${INPUT_USER}@${INPUT_HOST} "$POST_UPLOAD && exit" &&
echo "✅ Executed post-upload script";
fi

echo "🎉 Done";

0 comments on commit ca82210

Please sign in to comment.