mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2024-11-19 08:08:05 +08:00
Compare commits
103 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
83d848a9e4 | ||
|
9c02ed6208 | ||
|
2197bc60ef | ||
|
eb4a19604b | ||
|
09342ca039 | ||
|
40096bf224 | ||
|
4383250122 | ||
|
142b71c9e1 | ||
|
8218c8ed95 | ||
|
b75a6aac49 | ||
|
a0be71d296 | ||
|
87ad6713b5 | ||
|
b12dcbe93c | ||
|
c984a47bf5 | ||
|
5e456a475a | ||
|
a9eda89ad7 | ||
|
3cfa1cdc25 | ||
|
ce56d75fc1 | ||
|
74b3a2aba4 | ||
|
77bfc8c169 | ||
|
ac3c9b51d5 | ||
|
a0be893c82 | ||
|
50d1f576f9 | ||
|
20a0cae1ae | ||
|
95f4dc8069 | ||
|
b2adc00c92 | ||
|
a50a999528 | ||
|
1242867d7a | ||
|
33648ba2ca | ||
|
40a3789c05 | ||
|
7e2c0f29d6 | ||
|
e9c43c6900 | ||
|
9ae3c340cb | ||
|
386c8766a0 | ||
|
130901534a | ||
|
8b977327bb | ||
|
880f3b6b88 | ||
|
ec4a00fe02 | ||
|
a04c641775 | ||
|
9483c83d88 | ||
|
e41d593e15 | ||
|
9ab3993555 | ||
|
07265c8c95 | ||
|
a27b8667de | ||
|
2b38f7bf7a | ||
|
cd3b869a28 | ||
|
191986574c | ||
|
d41b136666 | ||
|
1ac1bcb558 | ||
|
c14eb85faf | ||
|
2bc5e10d4d | ||
|
4f928a3efc | ||
|
aac4cbf0db | ||
|
4042d3876f | ||
|
68f9da66f0 | ||
|
073bd0b6f6 | ||
|
14eb503e62 | ||
|
a9e37f3cb5 | ||
|
ff615959b6 | ||
|
5c4b90e3f8 | ||
|
66b3ffb0f7 | ||
|
037d157977 | ||
|
e34308df6c | ||
|
ad838db71f | ||
|
7f1c0e0111 | ||
|
54f2361d27 | ||
|
101b6c13a0 | ||
|
ac4f0895a6 | ||
|
0711330570 | ||
|
62063532be | ||
|
1a29114d7b | ||
|
e23436526e | ||
|
bf3218eb12 | ||
|
7269cb396a | ||
|
460751d7c3 | ||
|
9cdc72374b | ||
|
19689edd76 | ||
|
53c00dce2b | ||
|
140e959df8 | ||
|
00e4d7e856 | ||
|
37e21b5b6b | ||
|
19dbe22d4f | ||
|
733f9fc153 | ||
|
749cc36d5d | ||
|
f09a8d0277 | ||
|
82ccbba7dc | ||
|
ff832e4e77 | ||
|
3f84fa4ae1 | ||
|
c28aa7215e | ||
|
caaa95b651 | ||
|
d86da2b0b7 | ||
|
445db7826b | ||
|
4a2dc47c39 | ||
|
0d77a6681b | ||
|
a3d2df0501 | ||
|
7d63f7f134 | ||
|
5fdc019220 | ||
|
177ffc3a2a | ||
|
b5d54bf446 | ||
|
a20c19a8d1 | ||
|
4bf88310d4 | ||
|
81256f2671 | ||
|
3c2d851430 |
11
.editorconfig
Normal file
11
.editorconfig
Normal file
@@ -0,0 +1,11 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 2
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
max_line_length = 120
|
||||
tab_width = 4
|
||||
trim_trailing_whitespace = true
|
25
.eslintrc.js
Normal file
25
.eslintrc.js
Normal file
@@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
env: {
|
||||
commonjs: true,
|
||||
es6: true,
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'airbnb-base'
|
||||
],
|
||||
globals: {
|
||||
Atomics: 'readonly',
|
||||
SharedArrayBuffer: 'readonly'
|
||||
},
|
||||
parserOptions: {
|
||||
ecmaVersion: 2018,
|
||||
},
|
||||
rules: {
|
||||
"comma-dangle": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"no-console": "off",
|
||||
"object-curly-newline": "off"
|
||||
}
|
||||
};
|
31
.github/workflows/build.yml
vendored
Normal file
31
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ '**' ]
|
||||
pull_request:
|
||||
branches: [ $default-branch ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
node-version: [14.x]
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Build Library
|
||||
run: npm run build
|
||||
- name: Run Tests
|
||||
run: npm test --if-present
|
47
.github/workflows/codeql-analysis.yml
vendored
Normal file
47
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ main ]
|
||||
schedule:
|
||||
- cron: '20 12 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'javascript' ]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
|
||||
- run: |
|
||||
npm ci
|
||||
npm run build --if-present
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
44
.github/workflows/manual-release.yml
vendored
Normal file
44
.github/workflows/manual-release.yml
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
name: Manual Release
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
dryrun:
|
||||
description: 'DryRUn'
|
||||
required: true
|
||||
default: 'false'
|
||||
jobs:
|
||||
release:
|
||||
name: Test, Build and Release
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ ubuntu-latest ]
|
||||
node-version: [ 14.x ]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix['node-version'] }}
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Build Library
|
||||
run: npm run build --if-present
|
||||
- name: Run Tests
|
||||
run: npm test --if-present
|
||||
- name: Release
|
||||
uses: cycjimmy/semantic-release-action@v2
|
||||
with:
|
||||
dry_run: ${{ github.event.inputs.dryrun == 'true' }}
|
||||
extra_plugins: |
|
||||
@semantic-release/changelog@3.0.0
|
||||
@semantic-release/git
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
GIT_AUTHOR_NAME: github-actions
|
||||
GIT_AUTHOR_EMAIL: github-actions@github.com
|
||||
GIT_COMMITTER_NAME: github-actions
|
||||
GIT_COMMITTER_EMAIL: github-actions@github.com
|
||||
CI: true
|
44
.github/workflows/release.yml
vendored
Normal file
44
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Test, Build and Release
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ ubuntu-latest ]
|
||||
node-version: [ 14.x ]
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix['node-version'] }}
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Build Library
|
||||
run: npm run build --if-present
|
||||
- name: Run Tests
|
||||
run: npm test --if-present
|
||||
- name: Release
|
||||
uses: cycjimmy/semantic-release-action@v2
|
||||
with:
|
||||
dry_run: false
|
||||
extra_plugins: |
|
||||
@semantic-release/changelog@3.0.0
|
||||
@semantic-release/git
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
GIT_AUTHOR_NAME: github-actions
|
||||
GIT_AUTHOR_EMAIL: github-actions@github.com
|
||||
GIT_COMMITTER_NAME: github-actions
|
||||
GIT_COMMITTER_EMAIL: github-actions@github.com
|
||||
CI: true
|
21
.gitignore
vendored
Normal file
21
.gitignore
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
### Node template
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# IDE
|
||||
.idea
|
22
.releaserc
Normal file
22
.releaserc
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"branches": ["main"],
|
||||
"plugins": [
|
||||
"@semantic-release/commit-analyzer",
|
||||
"@semantic-release/release-notes-generator",
|
||||
[
|
||||
"@semantic-release/changelog",
|
||||
{
|
||||
"changelogFile": "docs/CHANGELOG.md"
|
||||
}
|
||||
],
|
||||
["@semantic-release/npm", {
|
||||
"npmPublish": false
|
||||
}],
|
||||
[
|
||||
"@semantic-release/git",
|
||||
{
|
||||
"assets": ["docs/CHANGELOG.md"]
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
22
Dockerfile
22
Dockerfile
@@ -1,22 +0,0 @@
|
||||
FROM debian:9.5-slim
|
||||
|
||||
# Update
|
||||
RUN apt-get update
|
||||
|
||||
# Install packages
|
||||
RUN apt-get -yq install rsync openssh-client
|
||||
|
||||
# Label
|
||||
LABEL "com.github.actions.name"="ssh deploy"
|
||||
LABEL "com.github.actions.description"="For deploying code over ssh"
|
||||
LABEL "com.github.actions.icon"="truck"
|
||||
LABEL "com.github.actions.color"="green"
|
||||
|
||||
LABEL "repository"="http://github.com/easingthemes/ssh-deploy"
|
||||
LABEL "homepage"="https://github.com/easingthemes/ssh-deploy"
|
||||
LABEL "maintainer"="Dragan Filipovic <info@frontenddot.com>"
|
||||
|
||||
# Copy entrypoint
|
||||
ADD entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
101
README.md
101
README.md
@@ -1,6 +1,10 @@
|
||||
# ssh deployments
|
||||
|
||||
This GitHub Action deploys specific directory from `GITHUB_WORKSPACE` to a folder on a server via rsync over ssh.
|
||||
Deploy code with rsync over ssh, using NodeJS.
|
||||
|
||||
NodeJS version is more than a minute `faster` than simple Docker version.
|
||||
|
||||
This GitHub Action deploys specific directory from `GITHUB_WORKSPACE` to a folder on a server via rsync over ssh, using NodeJS.
|
||||
|
||||
This action would usually follow a build/test action which leaves deployable code in `GITHUB_WORKSPACE`, eg `dist`;
|
||||
|
||||
@@ -8,30 +12,66 @@ This action would usually follow a build/test action which leaves deployable cod
|
||||
|
||||
Pass configuration with `env` vars
|
||||
|
||||
1. `DEPLOY_KEY`
|
||||
This should be the private key part of an ssh key pair. The public key part should be added to the authorized_keys file on the server that receives the deployment.
|
||||
##### 1. `SSH_PRIVATE_KEY` [required]
|
||||
|
||||
Private key part of an SSH key pair.
|
||||
The public key part should be added to the `authorized_keys` file on the server that receives the deployment.
|
||||
|
||||
More info for SSH keys: https://www.ssh.com/ssh/public-key-authentication
|
||||
|
||||
The keys should be generated using the PEM format. You can use this command
|
||||
|
||||
```
|
||||
ssh-keygen -m PEM -t rsa -b 4096
|
||||
```
|
||||
|
||||
##### 2. `REMOTE_HOST` [required]
|
||||
|
||||
eg: mydomain.com
|
||||
|
||||
##### 3. `REMOTE_USER` [required]
|
||||
|
||||
eg: myusername
|
||||
|
||||
##### 4. `REMOTE_PORT` (optional, default '22')
|
||||
|
||||
eg: '59184'
|
||||
|
||||
##### 5. `ARGS` (optional, default '-rltgoDzvO')
|
||||
|
||||
2. `ARGS`
|
||||
For any initial/required rsync flags, eg: `-avzr --delete`
|
||||
|
||||
3. `SOURCE`
|
||||
The source directory, path relative to `$GITHUB_WORKSPACE` root, eg: `dist`
|
||||
##### 6. `SOURCE` (optional, default '')
|
||||
|
||||
4. `TARGET`
|
||||
The target directory, in the format`[USER]@[HOST]:[PATH]`
|
||||
The source directory, path relative to `$GITHUB_WORKSPACE` root, eg: `dist/`
|
||||
|
||||
##### 7. `TARGET` (optional, default '/home/REMOTE_USER/')
|
||||
|
||||
The target directory
|
||||
|
||||
##### 8. `EXCLUDE` (optional, default '')
|
||||
|
||||
path to exclude separated by `,`, ie: `/dist/, /node_modules/`
|
||||
|
||||
# Usage
|
||||
|
||||
Use the latest version from Marketplace,eg: ssh-deploy@v2
|
||||
or use the latest version from a branch, eg: ssh-deploy@main
|
||||
|
||||
```
|
||||
- name: Deploy to Staging server
|
||||
uses: easingthemes/ssh-deploy@v1.0.0
|
||||
- name: Deploy to Staging server
|
||||
uses: easingthemes/ssh-deploy@main
|
||||
env:
|
||||
DEPLOY_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
||||
ARGS: "-rltgoDzvO --delete"
|
||||
SOURCE: "dist"
|
||||
TARGET: ${{ secrets.SERVER_STAGING }}
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
||||
ARGS: "-rltgoDzvO"
|
||||
SOURCE: "dist/"
|
||||
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
|
||||
REMOTE_USER: ${{ secrets.REMOTE_USER }}
|
||||
TARGET: ${{ secrets.REMOTE_TARGET }}
|
||||
EXCLUDE: "/dist/, /node_modules/"
|
||||
```
|
||||
|
||||
# Example usage
|
||||
# Example usage in workflow
|
||||
|
||||
```
|
||||
name: Node CI
|
||||
@@ -43,33 +83,28 @@ jobs:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [10.x]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
- name: Install Node.js
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
node-version: '10.x'
|
||||
- name: Install npm dependencies
|
||||
run: |
|
||||
npm install
|
||||
run: npm install
|
||||
- name: Run build task
|
||||
run: |
|
||||
npm run build --if-present
|
||||
- name: Deploy to Staging server
|
||||
uses: easingthemes/ssh-deploy@v1.0.0
|
||||
run: npm run build --if-present
|
||||
- name: Deploy to Server
|
||||
uses: easingthemes/ssh-deploy@main
|
||||
env:
|
||||
DEPLOY_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_KEY }}
|
||||
ARGS: "-rltgoDzvO --delete"
|
||||
SOURCE: "dist"
|
||||
TARGET: ${{ secrets.SERVER_STAGING }}
|
||||
SOURCE: "dist/"
|
||||
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
|
||||
REMOTE_USER: ${{ secrets.REMOTE_USER }}
|
||||
TARGET: ${{ secrets.REMOTE_TARGET }}
|
||||
EXCLUDE: "/dist/, /node_modules/"
|
||||
```
|
||||
|
||||
## Disclaimer
|
||||
|
||||
If you're using GitHub Actions, you'll probably already know that it's still in limited public beta, and GitHub advise against using Actions in production.
|
||||
|
||||
So, check your keys. Check your deployment paths. And use at your own risk.
|
||||
Check your keys. Check your deployment paths. And use at your own risk.
|
||||
|
42
action.yml
Normal file
42
action.yml
Normal file
@@ -0,0 +1,42 @@
|
||||
name: "ssh deploy"
|
||||
description: "NodeJS action for FAST deployment with rsync/ssh"
|
||||
author: "easingthemes"
|
||||
inputs:
|
||||
SSH_PRIVATE_KEY: # Private Key
|
||||
description: "Private Key"
|
||||
required: true
|
||||
REMOTE_HOST:
|
||||
description: "Remote host"
|
||||
required: true
|
||||
REMOTE_USER:
|
||||
description: "Remote user"
|
||||
required: true
|
||||
REMOTE_PORT:
|
||||
description: "Remote port"
|
||||
required: false
|
||||
default: "22"
|
||||
SOURCE:
|
||||
description: "Source directory"
|
||||
required: false
|
||||
default: ""
|
||||
TARGET:
|
||||
description: "Target directory"
|
||||
required: false
|
||||
default: "/home/REMOTE_USER/"
|
||||
ARGS:
|
||||
description: "Arguments to pass to rsync"
|
||||
required: false
|
||||
default: "-rltgoDzvO"
|
||||
EXCLUDE:
|
||||
description: "An array of folder to exclude"
|
||||
required: false
|
||||
default: ""
|
||||
outputs:
|
||||
status:
|
||||
description: "Status"
|
||||
runs:
|
||||
using: "node12"
|
||||
main: "dist/index.js"
|
||||
branding:
|
||||
color: "green"
|
||||
icon: "truck"
|
746
dist/index.js
vendored
Executable file
746
dist/index.js
vendored
Executable file
@@ -0,0 +1,746 @@
|
||||
#!/usr/bin/env node
|
||||
/******/ (() => { // webpackBootstrap
|
||||
/******/ var __webpack_modules__ = ({
|
||||
|
||||
/***/ 569:
|
||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||
|
||||
module.exports = __nccwpck_require__(325);
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 325:
|
||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var exec = __nccwpck_require__(129).exec;
|
||||
var execSync = __nccwpck_require__(129).execSync;
|
||||
var fs = __nccwpck_require__(747);
|
||||
var path = __nccwpck_require__(622);
|
||||
var access = fs.access;
|
||||
var accessSync = fs.accessSync;
|
||||
var constants = fs.constants || fs;
|
||||
|
||||
var isUsingWindows = process.platform == 'win32'
|
||||
|
||||
var fileNotExists = function(commandName, callback){
|
||||
access(commandName, constants.F_OK,
|
||||
function(err){
|
||||
callback(!err);
|
||||
});
|
||||
};
|
||||
|
||||
var fileNotExistsSync = function(commandName){
|
||||
try{
|
||||
accessSync(commandName, constants.F_OK);
|
||||
return false;
|
||||
}catch(e){
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
var localExecutable = function(commandName, callback){
|
||||
access(commandName, constants.F_OK | constants.X_OK,
|
||||
function(err){
|
||||
callback(null, !err);
|
||||
});
|
||||
};
|
||||
|
||||
var localExecutableSync = function(commandName){
|
||||
try{
|
||||
accessSync(commandName, constants.F_OK | constants.X_OK);
|
||||
return true;
|
||||
}catch(e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var commandExistsUnix = function(commandName, cleanedCommandName, callback) {
|
||||
|
||||
fileNotExists(commandName, function(isFile){
|
||||
|
||||
if(!isFile){
|
||||
var child = exec('command -v ' + cleanedCommandName +
|
||||
' 2>/dev/null' +
|
||||
' && { echo >&1 ' + cleanedCommandName + '; exit 0; }',
|
||||
function (error, stdout, stderr) {
|
||||
callback(null, !!stdout);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
localExecutable(commandName, callback);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
var commandExistsWindows = function(commandName, cleanedCommandName, callback) {
|
||||
// Regex from Julio from: https://stackoverflow.com/questions/51494579/regex-windows-path-validator
|
||||
if (!(/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName))) {
|
||||
callback(null, false);
|
||||
return;
|
||||
}
|
||||
var child = exec('where ' + cleanedCommandName,
|
||||
function (error) {
|
||||
if (error !== null){
|
||||
callback(null, false);
|
||||
} else {
|
||||
callback(null, true);
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
var commandExistsUnixSync = function(commandName, cleanedCommandName) {
|
||||
if(fileNotExistsSync(commandName)){
|
||||
try {
|
||||
var stdout = execSync('command -v ' + cleanedCommandName +
|
||||
' 2>/dev/null' +
|
||||
' && { echo >&1 ' + cleanedCommandName + '; exit 0; }'
|
||||
);
|
||||
return !!stdout;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return localExecutableSync(commandName);
|
||||
}
|
||||
|
||||
var commandExistsWindowsSync = function(commandName, cleanedCommandName, callback) {
|
||||
// Regex from Julio from: https://stackoverflow.com/questions/51494579/regex-windows-path-validator
|
||||
if (!(/^(?!(?:.*\s|.*\.|\W+)$)(?:[a-zA-Z]:)?(?:(?:[^<>:"\|\?\*\n])+(?:\/\/|\/|\\\\|\\)?)+$/m.test(commandName))) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
var stdout = execSync('where ' + cleanedCommandName, {stdio: []});
|
||||
return !!stdout;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var cleanInput = function(s) {
|
||||
if (/[^A-Za-z0-9_\/:=-]/.test(s)) {
|
||||
s = "'"+s.replace(/'/g,"'\\''")+"'";
|
||||
s = s.replace(/^(?:'')+/g, '') // unduplicate single-quote at the beginning
|
||||
.replace(/\\'''/g, "\\'" ); // remove non-escaped single-quote if there are enclosed between 2 escaped
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
if (isUsingWindows) {
|
||||
cleanInput = function(s) {
|
||||
var isPathName = /[\\]/.test(s);
|
||||
if (isPathName) {
|
||||
var dirname = '"' + path.dirname(s) + '"';
|
||||
var basename = '"' + path.basename(s) + '"';
|
||||
return dirname + ':' + basename;
|
||||
}
|
||||
return '"' + s + '"';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function commandExists(commandName, callback) {
|
||||
var cleanedCommandName = cleanInput(commandName);
|
||||
if (!callback && typeof Promise !== 'undefined') {
|
||||
return new Promise(function(resolve, reject){
|
||||
commandExists(commandName, function(error, output) {
|
||||
if (output) {
|
||||
resolve(commandName);
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
if (isUsingWindows) {
|
||||
commandExistsWindows(commandName, cleanedCommandName, callback);
|
||||
} else {
|
||||
commandExistsUnix(commandName, cleanedCommandName, callback);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.sync = function(commandName) {
|
||||
var cleanedCommandName = cleanInput(commandName);
|
||||
if (isUsingWindows) {
|
||||
return commandExistsWindowsSync(commandName, cleanedCommandName);
|
||||
} else {
|
||||
return commandExistsUnixSync(commandName, cleanedCommandName);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 748:
|
||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||
|
||||
const { exec, execSync } = __nccwpck_require__(129);
|
||||
|
||||
const commandline={
|
||||
run:runCommand,
|
||||
runSync:runSync,
|
||||
//will be deprecated soon as run is now the same.
|
||||
get:runCommand,
|
||||
|
||||
};
|
||||
|
||||
function runCommand(command,callback){
|
||||
|
||||
return exec(
|
||||
command,
|
||||
(
|
||||
function(){
|
||||
return function(err,data,stderr){
|
||||
if(!callback)
|
||||
return;
|
||||
|
||||
callback(err, data, stderr);
|
||||
}
|
||||
}
|
||||
)(callback)
|
||||
);
|
||||
}
|
||||
|
||||
function runSync(command){
|
||||
try {
|
||||
return {
|
||||
data: execSync(command).toString(),
|
||||
err: null,
|
||||
stderr: null
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
return {
|
||||
data: null,
|
||||
err: error.stderr.toString(),
|
||||
stderr: error.stderr.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports=commandline;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 898:
|
||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
var spawn = __nccwpck_require__(129).spawn
|
||||
var util = __nccwpck_require__(669)
|
||||
|
||||
var escapeSpaces = function(path) {
|
||||
if (typeof path === 'string') {
|
||||
return path.replace(/\b\s/g, '\\ ')
|
||||
} else {
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
var escapeSpacesInOptions = function(options) {
|
||||
// Escape paths in the src, dest, include, exclude, and excludeFirst arguments
|
||||
;['src', 'dest', 'include', 'exclude', 'excludeFirst'].forEach(function(
|
||||
optionKey
|
||||
) {
|
||||
var option = options[optionKey]
|
||||
if (typeof option === 'string') {
|
||||
options[optionKey] = escapeSpaces(option)
|
||||
} else if (Array.isArray(option) === true) {
|
||||
options[optionKey] = option.map(escapeSpaces)
|
||||
}
|
||||
})
|
||||
|
||||
return options
|
||||
}
|
||||
|
||||
module.exports = function(options, callback) {
|
||||
options = options || {}
|
||||
options = util._extend({}, options)
|
||||
options = escapeSpacesInOptions(options)
|
||||
|
||||
var platform = options.platform || process.platform // Enable process.platform to be mocked in options for testing
|
||||
var isWin = platform === 'win32'
|
||||
|
||||
if (typeof options.src === 'undefined') {
|
||||
throw new Error("'src' directory is missing from options")
|
||||
}
|
||||
|
||||
if (typeof options.dest === 'undefined') {
|
||||
throw new Error("'dest' directory is missing from options")
|
||||
}
|
||||
|
||||
var dest = options.dest
|
||||
|
||||
if (typeof options.host !== 'undefined') {
|
||||
dest = options.host + ':' + options.dest
|
||||
}
|
||||
|
||||
if (!Array.isArray(options.src)) {
|
||||
options.src = [options.src]
|
||||
}
|
||||
|
||||
var args = [].concat(options.src)
|
||||
|
||||
args.push(dest)
|
||||
|
||||
// [rsync failed on windows, copying persmissions](https://github.com/jedrichards/rsyncwrapper/issues/28)
|
||||
// [set chmod flag by default on Windows](https://github.com/jedrichards/rsyncwrapper/pull/29)
|
||||
var chmodArg = (options.args || []).find(function(arg) {
|
||||
return arg.match(/--chmod=/)
|
||||
})
|
||||
if (isWin && !chmodArg) {
|
||||
args.push('--chmod=ugo=rwX')
|
||||
}
|
||||
|
||||
if (typeof options.host !== 'undefined' || options.ssh) {
|
||||
args.push('--rsh')
|
||||
var rshCmd = 'ssh'
|
||||
if (typeof options.port !== 'undefined') {
|
||||
rshCmd += ' -p ' + options.port
|
||||
}
|
||||
if (typeof options.privateKey !== 'undefined') {
|
||||
rshCmd += ' -i ' + options.privateKey
|
||||
}
|
||||
if (typeof options.sshCmdArgs !== 'undefined') {
|
||||
rshCmd += ' ' + options.sshCmdArgs.join(' ')
|
||||
}
|
||||
args.push(rshCmd)
|
||||
}
|
||||
|
||||
if (options.recursive === true) {
|
||||
args.push('--recursive')
|
||||
}
|
||||
|
||||
if (options.times === true) {
|
||||
args.push('--times')
|
||||
}
|
||||
|
||||
if (options.syncDest === true || options.deleteAll === true) {
|
||||
args.push('--delete')
|
||||
args.push('--delete-excluded')
|
||||
}
|
||||
|
||||
if (options.syncDestIgnoreExcl === true || options.delete === true) {
|
||||
args.push('--delete')
|
||||
}
|
||||
|
||||
if (options.dryRun === true) {
|
||||
args.push('--dry-run')
|
||||
args.push('--verbose')
|
||||
}
|
||||
|
||||
if (
|
||||
typeof options.excludeFirst !== 'undefined' &&
|
||||
util.isArray(options.excludeFirst)
|
||||
) {
|
||||
options.excludeFirst.forEach(function(value, index) {
|
||||
args.push('--exclude=' + value)
|
||||
})
|
||||
}
|
||||
|
||||
if (typeof options.include !== 'undefined' && util.isArray(options.include)) {
|
||||
options.include.forEach(function(value, index) {
|
||||
args.push('--include=' + value)
|
||||
})
|
||||
}
|
||||
|
||||
if (typeof options.exclude !== 'undefined' && util.isArray(options.exclude)) {
|
||||
options.exclude.forEach(function(value, index) {
|
||||
args.push('--exclude=' + value)
|
||||
})
|
||||
}
|
||||
|
||||
switch (options.compareMode) {
|
||||
case 'sizeOnly':
|
||||
args.push('--size-only')
|
||||
break
|
||||
case 'checksum':
|
||||
args.push('--checksum')
|
||||
break
|
||||
}
|
||||
|
||||
if (typeof options.args !== 'undefined' && util.isArray(options.args)) {
|
||||
args = [...new Set([...args, ...options.args])]
|
||||
}
|
||||
|
||||
args = [...new Set(args)]
|
||||
|
||||
var noop = function() {}
|
||||
var onStdout = options.onStdout || noop
|
||||
var onStderr = options.onStderr || noop
|
||||
|
||||
var cmd = 'rsync '
|
||||
args.forEach(function(arg) {
|
||||
if (arg.substr(0, 4) === 'ssh ') {
|
||||
arg = '"' + arg + '"'
|
||||
}
|
||||
cmd += arg + ' '
|
||||
})
|
||||
cmd = cmd.trim()
|
||||
|
||||
if (options.noExec) {
|
||||
callback(null, null, null, cmd)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
var stdout = ''
|
||||
var stderr = ''
|
||||
// Launch cmd in a shell just like Node's child_process.exec() does:
|
||||
// see https://github.com/joyent/node/blob/937e2e351b2450cf1e9c4d8b3e1a4e2a2def58bb/lib/child_process.js#L589
|
||||
var child
|
||||
if (isWin) {
|
||||
child = spawn('cmd.exe', ['/s', '/c', '"' + cmd + '"'], {
|
||||
windowsVerbatimArguments: true,
|
||||
stdio: [process.stdin, 'pipe', 'pipe'],
|
||||
})
|
||||
} else {
|
||||
child = spawn('/bin/sh', ['-c', cmd])
|
||||
}
|
||||
|
||||
child.stdout.on('data', function(data) {
|
||||
onStdout(data)
|
||||
stdout += data
|
||||
})
|
||||
|
||||
child.stderr.on('data', function(data) {
|
||||
onStderr(data)
|
||||
stderr += data
|
||||
})
|
||||
|
||||
child.on('exit', function(code) {
|
||||
var err = null
|
||||
if (code !== 0) {
|
||||
err = new Error('rsync exited with code ' + code)
|
||||
err.code = code
|
||||
}
|
||||
callback(err, stdout, stderr, cmd)
|
||||
})
|
||||
} catch (err) {
|
||||
callback(err, null, null, cmd)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 505:
|
||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||
|
||||
const { existsSync, mkdirSync, writeFileSync } = __nccwpck_require__(747);
|
||||
|
||||
const {
|
||||
GITHUB_WORKSPACE
|
||||
} = process.env;
|
||||
|
||||
const validateDir = (dir) => {
|
||||
if (!existsSync(dir)) {
|
||||
console.log(`[SSH] Creating ${dir} dir in `, GITHUB_WORKSPACE);
|
||||
mkdirSync(dir);
|
||||
console.log('✅ [SSH] dir created.');
|
||||
} else {
|
||||
console.log(`[SSH] ${dir} dir exist`);
|
||||
}
|
||||
};
|
||||
|
||||
const validateFile = (filePath) => {
|
||||
if (!existsSync(filePath)) {
|
||||
console.log(`[SSH] Creating ${filePath} file in `, GITHUB_WORKSPACE);
|
||||
try {
|
||||
writeFileSync(filePath, '', {
|
||||
encoding: 'utf8',
|
||||
mode: 0o600
|
||||
});
|
||||
console.log('✅ [SSH] file created.');
|
||||
} catch (e) {
|
||||
console.error('⚠️ [SSH] writeFileSync error', filePath, e.message);
|
||||
process.abort();
|
||||
}
|
||||
} else {
|
||||
console.log(`[SSH] ${filePath} file exist`);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validateDir,
|
||||
validateFile
|
||||
};
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 229:
|
||||
/***/ ((module) => {
|
||||
|
||||
const inputNames = ['REMOTE_HOST', 'REMOTE_USER', 'REMOTE_PORT', 'SSH_PRIVATE_KEY', 'DEPLOY_KEY_NAME', 'SOURCE', 'TARGET', 'ARGS', 'EXCLUDE'];
|
||||
|
||||
const inputs = {
|
||||
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE
|
||||
};
|
||||
// Get inputs from ENV or WITH workflow settings
|
||||
inputNames.forEach((input) => {
|
||||
inputs[input] = process.env[input] || process.env[`INPUT_${input}`];
|
||||
});
|
||||
|
||||
module.exports = inputs;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 447:
|
||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||
|
||||
const { sync: commandExists } = __nccwpck_require__(569);
|
||||
const { get: nodeCmd } = __nccwpck_require__(748);
|
||||
|
||||
const validateRsync = (callback = () => {}) => {
|
||||
const rsyncCli = commandExists('rsync');
|
||||
|
||||
if (!rsyncCli) {
|
||||
nodeCmd(
|
||||
'sudo apt-get --no-install-recommends install rsync',
|
||||
(err, data, stderr) => {
|
||||
if (err) {
|
||||
console.log('⚠️ [CLI] Rsync installation failed. Aborting ... ', err.message);
|
||||
process.abort();
|
||||
} else {
|
||||
console.log('✅ [CLI] Rsync installed. \n', data, stderr);
|
||||
callback();
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
const validateInputs = (inputs) => {
|
||||
const inputKeys = Object.keys(inputs);
|
||||
const validInputs = inputKeys.filter((inputKey) => {
|
||||
const inputValue = inputs[inputKey];
|
||||
|
||||
if (!inputValue) {
|
||||
console.error(`⚠️ [INPUTS] ${inputKey} is mandatory`);
|
||||
}
|
||||
|
||||
return inputValue;
|
||||
});
|
||||
|
||||
if (validInputs.length !== inputKeys.length) {
|
||||
console.error('⚠️ [INPUTS] Inputs not valid, aborting ...');
|
||||
process.abort();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validateRsync,
|
||||
validateInputs
|
||||
};
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 822:
|
||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||
|
||||
const { writeFileSync } = __nccwpck_require__(747);
|
||||
const { join } = __nccwpck_require__(622);
|
||||
|
||||
const {
|
||||
validateDir,
|
||||
validateFile
|
||||
} = __nccwpck_require__(505);
|
||||
|
||||
const {
|
||||
HOME
|
||||
} = process.env;
|
||||
|
||||
const addSshKey = (key, name) => {
|
||||
const sshDir = join(HOME || __dirname, '.ssh');
|
||||
const filePath = join(sshDir, name);
|
||||
|
||||
validateDir(sshDir);
|
||||
validateFile(`${sshDir}/known_hosts`);
|
||||
|
||||
try {
|
||||
writeFileSync(filePath, key, {
|
||||
encoding: 'utf8',
|
||||
mode: 0o600
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('⚠️ writeFileSync error', filePath, e.message);
|
||||
process.abort();
|
||||
}
|
||||
|
||||
console.log('✅ Ssh key added to `.ssh` dir ', filePath);
|
||||
|
||||
return filePath;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
addSshKey
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 129:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("child_process");;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 747:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("fs");;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 622:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("path");;
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 669:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("util");;
|
||||
|
||||
/***/ })
|
||||
|
||||
/******/ });
|
||||
/************************************************************************/
|
||||
/******/ // The module cache
|
||||
/******/ var __webpack_module_cache__ = {};
|
||||
/******/
|
||||
/******/ // The require function
|
||||
/******/ function __nccwpck_require__(moduleId) {
|
||||
/******/ // Check if module is in cache
|
||||
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
||||
/******/ if (cachedModule !== undefined) {
|
||||
/******/ return cachedModule.exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||||
/******/ // no module.id needed
|
||||
/******/ // no module.loaded needed
|
||||
/******/ exports: {}
|
||||
/******/ };
|
||||
/******/
|
||||
/******/ // Execute the module function
|
||||
/******/ var threw = true;
|
||||
/******/ try {
|
||||
/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
|
||||
/******/ threw = false;
|
||||
/******/ } finally {
|
||||
/******/ if(threw) delete __webpack_module_cache__[moduleId];
|
||||
/******/ }
|
||||
/******/
|
||||
/******/ // Return the exports of the module
|
||||
/******/ return module.exports;
|
||||
/******/ }
|
||||
/******/
|
||||
/************************************************************************/
|
||||
/******/ /* webpack/runtime/compat */
|
||||
/******/
|
||||
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
|
||||
var __webpack_exports__ = {};
|
||||
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
||||
(() => {
|
||||
const nodeRsync = __nccwpck_require__(898);
|
||||
|
||||
const { validateRsync, validateInputs } = __nccwpck_require__(447);
|
||||
const { addSshKey } = __nccwpck_require__(822);
|
||||
|
||||
const {
|
||||
REMOTE_HOST, REMOTE_USER,
|
||||
REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME,
|
||||
SOURCE, TARGET, ARGS, EXCLUDE,
|
||||
GITHUB_WORKSPACE
|
||||
} = __nccwpck_require__(229);
|
||||
|
||||
const defaultOptions = {
|
||||
ssh: true,
|
||||
sshCmdArgs: ['-o StrictHostKeyChecking=no'],
|
||||
recursive: true
|
||||
};
|
||||
|
||||
console.log('[general] GITHUB_WORKSPACE: ', GITHUB_WORKSPACE);
|
||||
|
||||
const sshDeploy = (() => {
|
||||
const rsync = ({ privateKey, port, src, dest, args, exclude }) => {
|
||||
console.log(`[Rsync] Starting Rsync Action: ${src} to ${dest}`);
|
||||
if (exclude) console.log(`[Rsync] exluding folders ${exclude}`);
|
||||
|
||||
try {
|
||||
// RSYNC COMMAND
|
||||
nodeRsync({
|
||||
src, dest, args, privateKey, port, excludeFirst: exclude, ...defaultOptions
|
||||
}, (error, stdout, stderr, cmd) => {
|
||||
if (error) {
|
||||
console.error('⚠️ [Rsync] error: ', error.message);
|
||||
console.log('⚠️ [Rsync] stderr: ', stderr);
|
||||
console.log('⚠️ [Rsync] stdout: ', stdout);
|
||||
console.log('⚠️ [Rsync] cmd: ', cmd);
|
||||
process.abort();
|
||||
} else {
|
||||
console.log('✅ [Rsync] finished.', stdout);
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('⚠️ [Rsync] command error: ', err.message, err.stack);
|
||||
process.abort();
|
||||
}
|
||||
};
|
||||
|
||||
const init = ({ src, dest, args, host = 'localhost', port, username, privateKeyContent, exclude = [] }) => {
|
||||
validateRsync(() => {
|
||||
const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME || 'deploy_key');
|
||||
const remoteDest = `${username}@${host}:${dest}`;
|
||||
|
||||
rsync({ privateKey, port, src, dest: remoteDest, args, exclude });
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
init
|
||||
};
|
||||
})();
|
||||
|
||||
const run = () => {
|
||||
validateInputs({ SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER });
|
||||
|
||||
sshDeploy.init({
|
||||
src: `${GITHUB_WORKSPACE}/${SOURCE || ''}`,
|
||||
dest: TARGET || `/home/${REMOTE_USER}/`,
|
||||
args: ARGS ? [ARGS] : ['-rltgoDzvO'],
|
||||
host: REMOTE_HOST,
|
||||
port: REMOTE_PORT || '22',
|
||||
username: REMOTE_USER,
|
||||
privateKeyContent: SSH_PRIVATE_KEY,
|
||||
exclude: (EXCLUDE || '').split(',').map((item) => item.trim()) // split by comma and trim whitespace
|
||||
});
|
||||
};
|
||||
|
||||
run();
|
||||
|
||||
})();
|
||||
|
||||
module.exports = __webpack_exports__;
|
||||
/******/ })()
|
||||
;
|
57
docs/CHANGELOG.md
Normal file
57
docs/CHANGELOG.md
Normal file
@@ -0,0 +1,57 @@
|
||||
## [2.2.6](https://github.com/easingthemes/ssh-deploy/compare/v2.2.5...v2.2.6) (2021-05-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add NPM token ([2197bc6](https://github.com/easingthemes/ssh-deploy/commit/2197bc60ef7870d4bd494966b314eabec1615bd7))
|
||||
|
||||
## [2.2.5](https://github.com/easingthemes/ssh-deploy/compare/v2.2.4...v2.2.5) (2021-05-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* semantic-release/npm update config ([40096bf](https://github.com/easingthemes/ssh-deploy/commit/40096bf22459d1dd82172d2bd20c0c149e70b1e1))
|
||||
|
||||
## [2.2.4](https://github.com/easingthemes/ssh-deploy/compare/v2.2.3...v2.2.4) (2021-05-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add branch instead of a version in a readme ([8218c8e](https://github.com/easingthemes/ssh-deploy/commit/8218c8ed9514d772933e1ab4d1c725a7c05e149f))
|
||||
|
||||
## [2.2.3](https://github.com/easingthemes/ssh-deploy/compare/v2.2.2...v2.2.3) (2021-05-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* codeql yaml syntax update ([87ad671](https://github.com/easingthemes/ssh-deploy/commit/87ad6713b53d454bd7ad6c4576cea7b2e3e2f4f3))
|
||||
|
||||
## [2.2.2](https://github.com/easingthemes/ssh-deploy/compare/v2.2.1...v2.2.2) (2021-05-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* codeql build ([5e456a4](https://github.com/easingthemes/ssh-deploy/commit/5e456a475a15096d08ccd2aff2734b3f1250b308))
|
||||
|
||||
## [2.2.1](https://github.com/easingthemes/ssh-deploy/compare/v2.2.0...v2.2.1) (2021-05-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* add package json auto updates ([ce56d75](https://github.com/easingthemes/ssh-deploy/commit/ce56d75fc1b62a99d72ffba70dcb24fcc3b6b3df))
|
||||
|
||||
# [2.2.0](https://github.com/easingthemes/ssh-deploy/compare/v2.1.7...v2.2.0) (2021-05-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* only=prod package json ([95f4dc8](https://github.com/easingthemes/ssh-deploy/commit/95f4dc8069045c1f5f726e00cb519b46e4f14267))
|
||||
* replace i with ci ([50d1f57](https://github.com/easingthemes/ssh-deploy/commit/50d1f576f95c0d7e8ce99fb1b2ab68b2594973e5))
|
||||
* update ncc ([20a0cae](https://github.com/easingthemes/ssh-deploy/commit/20a0cae1ae81bcc430507363e800342976307a81))
|
||||
* update plugins ([b2adc00](https://github.com/easingthemes/ssh-deploy/commit/b2adc00c92f129aef41ae46441411c2bebc0dbe4))
|
||||
* update plugins ([a50a999](https://github.com/easingthemes/ssh-deploy/commit/a50a999528b503846cc7fdf26210f710bd95565a))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add semantic-release-action ([ac3c9b5](https://github.com/easingthemes/ssh-deploy/commit/ac3c9b51d5cb52f4add40e2fc2dcc5e970153afc))
|
@@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
# Set deploy key
|
||||
SSH_PATH="$HOME/.ssh"
|
||||
mkdir "$SSH_PATH"
|
||||
echo "$DEPLOY_KEY" > "$SSH_PATH/deploy_key"
|
||||
chmod 600 "$SSH_PATH/deploy_key"
|
||||
|
||||
|
||||
# Do deployment
|
||||
sh -c "rsync $ARGS -e 'ssh -i $SSH_PATH/deploy_key -o StrictHostKeyChecking=no' $GITHUB_WORKSPACE/$SOURCE $TARGET"
|
1672
package-lock.json
generated
Normal file
1672
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
37
package.json
Normal file
37
package.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "ssh-deploy",
|
||||
"version": "2.1.9",
|
||||
"description": "Fast NodeJS action to deploy specific directory from `GITHUB_WORKSPACE` to a server via rsync over ssh.",
|
||||
"main": "src/index.js",
|
||||
"dependencies": {
|
||||
"command-exists": "1.2.9",
|
||||
"node-cmd": "4.0.0",
|
||||
"rsyncwrapper": "3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vercel/ncc": "^0.28.6",
|
||||
"eslint": "^7.27.0",
|
||||
"eslint-config-airbnb-base": "^14.2.1",
|
||||
"eslint-plugin-import": "^2.23.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run lint && ncc build ./src/index.js -o dist",
|
||||
"lint": "eslint ./src/index.js",
|
||||
"lint:fix": "eslint ./src/index.js --fix"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/easingthemes/ssh-deploy.git"
|
||||
},
|
||||
"keywords": [
|
||||
"deploy",
|
||||
"ssh",
|
||||
"rsync"
|
||||
],
|
||||
"author": "Dragan Filipovic",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/easingthemes/ssh-deploy/issues"
|
||||
},
|
||||
"homepage": "https://github.com/easingthemes/ssh-deploy#readme"
|
||||
}
|
38
src/helpers.js
Normal file
38
src/helpers.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const { existsSync, mkdirSync, writeFileSync } = require('fs');
|
||||
|
||||
const {
|
||||
GITHUB_WORKSPACE
|
||||
} = process.env;
|
||||
|
||||
const validateDir = (dir) => {
|
||||
if (!existsSync(dir)) {
|
||||
console.log(`[SSH] Creating ${dir} dir in `, GITHUB_WORKSPACE);
|
||||
mkdirSync(dir);
|
||||
console.log('✅ [SSH] dir created.');
|
||||
} else {
|
||||
console.log(`[SSH] ${dir} dir exist`);
|
||||
}
|
||||
};
|
||||
|
||||
const validateFile = (filePath) => {
|
||||
if (!existsSync(filePath)) {
|
||||
console.log(`[SSH] Creating ${filePath} file in `, GITHUB_WORKSPACE);
|
||||
try {
|
||||
writeFileSync(filePath, '', {
|
||||
encoding: 'utf8',
|
||||
mode: 0o600
|
||||
});
|
||||
console.log('✅ [SSH] file created.');
|
||||
} catch (e) {
|
||||
console.error('⚠️ [SSH] writeFileSync error', filePath, e.message);
|
||||
process.abort();
|
||||
}
|
||||
} else {
|
||||
console.log(`[SSH] ${filePath} file exist`);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validateDir,
|
||||
validateFile
|
||||
};
|
77
src/index.js
Normal file
77
src/index.js
Normal file
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env node
|
||||
const nodeRsync = require('rsyncwrapper');
|
||||
|
||||
const { validateRsync, validateInputs } = require('./rsyncCli');
|
||||
const { addSshKey } = require('./sshKey');
|
||||
|
||||
const {
|
||||
REMOTE_HOST, REMOTE_USER,
|
||||
REMOTE_PORT, SSH_PRIVATE_KEY, DEPLOY_KEY_NAME,
|
||||
SOURCE, TARGET, ARGS, EXCLUDE,
|
||||
GITHUB_WORKSPACE
|
||||
} = require('./inputs');
|
||||
|
||||
const defaultOptions = {
|
||||
ssh: true,
|
||||
sshCmdArgs: ['-o StrictHostKeyChecking=no'],
|
||||
recursive: true
|
||||
};
|
||||
|
||||
console.log('[general] GITHUB_WORKSPACE: ', GITHUB_WORKSPACE);
|
||||
|
||||
const sshDeploy = (() => {
|
||||
const rsync = ({ privateKey, port, src, dest, args, exclude }) => {
|
||||
console.log(`[Rsync] Starting Rsync Action: ${src} to ${dest}`);
|
||||
if (exclude) console.log(`[Rsync] exluding folders ${exclude}`);
|
||||
|
||||
try {
|
||||
// RSYNC COMMAND
|
||||
nodeRsync({
|
||||
src, dest, args, privateKey, port, excludeFirst: exclude, ...defaultOptions
|
||||
}, (error, stdout, stderr, cmd) => {
|
||||
if (error) {
|
||||
console.error('⚠️ [Rsync] error: ', error.message);
|
||||
console.log('⚠️ [Rsync] stderr: ', stderr);
|
||||
console.log('⚠️ [Rsync] stdout: ', stdout);
|
||||
console.log('⚠️ [Rsync] cmd: ', cmd);
|
||||
process.abort();
|
||||
} else {
|
||||
console.log('✅ [Rsync] finished.', stdout);
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('⚠️ [Rsync] command error: ', err.message, err.stack);
|
||||
process.abort();
|
||||
}
|
||||
};
|
||||
|
||||
const init = ({ src, dest, args, host = 'localhost', port, username, privateKeyContent, exclude = [] }) => {
|
||||
validateRsync(() => {
|
||||
const privateKey = addSshKey(privateKeyContent, DEPLOY_KEY_NAME || 'deploy_key');
|
||||
const remoteDest = `${username}@${host}:${dest}`;
|
||||
|
||||
rsync({ privateKey, port, src, dest: remoteDest, args, exclude });
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
init
|
||||
};
|
||||
})();
|
||||
|
||||
const run = () => {
|
||||
validateInputs({ SSH_PRIVATE_KEY, REMOTE_HOST, REMOTE_USER });
|
||||
|
||||
sshDeploy.init({
|
||||
src: `${GITHUB_WORKSPACE}/${SOURCE || ''}`,
|
||||
dest: TARGET || `/home/${REMOTE_USER}/`,
|
||||
args: ARGS ? [ARGS] : ['-rltgoDzvO'],
|
||||
host: REMOTE_HOST,
|
||||
port: REMOTE_PORT || '22',
|
||||
username: REMOTE_USER,
|
||||
privateKeyContent: SSH_PRIVATE_KEY,
|
||||
exclude: (EXCLUDE || '').split(',').map((item) => item.trim()) // split by comma and trim whitespace
|
||||
});
|
||||
};
|
||||
|
||||
run();
|
11
src/inputs.js
Normal file
11
src/inputs.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const inputNames = ['REMOTE_HOST', 'REMOTE_USER', 'REMOTE_PORT', 'SSH_PRIVATE_KEY', 'DEPLOY_KEY_NAME', 'SOURCE', 'TARGET', 'ARGS', 'EXCLUDE'];
|
||||
|
||||
const inputs = {
|
||||
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE
|
||||
};
|
||||
// Get inputs from ENV or WITH workflow settings
|
||||
inputNames.forEach((input) => {
|
||||
inputs[input] = process.env[input] || process.env[`INPUT_${input}`];
|
||||
});
|
||||
|
||||
module.exports = inputs;
|
46
src/rsyncCli.js
Normal file
46
src/rsyncCli.js
Normal file
@@ -0,0 +1,46 @@
|
||||
const { sync: commandExists } = require('command-exists');
|
||||
const { get: nodeCmd } = require('node-cmd');
|
||||
|
||||
const validateRsync = (callback = () => {}) => {
|
||||
const rsyncCli = commandExists('rsync');
|
||||
|
||||
if (!rsyncCli) {
|
||||
nodeCmd(
|
||||
'sudo apt-get --no-install-recommends install rsync',
|
||||
(err, data, stderr) => {
|
||||
if (err) {
|
||||
console.log('⚠️ [CLI] Rsync installation failed. Aborting ... ', err.message);
|
||||
process.abort();
|
||||
} else {
|
||||
console.log('✅ [CLI] Rsync installed. \n', data, stderr);
|
||||
callback();
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
const validateInputs = (inputs) => {
|
||||
const inputKeys = Object.keys(inputs);
|
||||
const validInputs = inputKeys.filter((inputKey) => {
|
||||
const inputValue = inputs[inputKey];
|
||||
|
||||
if (!inputValue) {
|
||||
console.error(`⚠️ [INPUTS] ${inputKey} is mandatory`);
|
||||
}
|
||||
|
||||
return inputValue;
|
||||
});
|
||||
|
||||
if (validInputs.length !== inputKeys.length) {
|
||||
console.error('⚠️ [INPUTS] Inputs not valid, aborting ...');
|
||||
process.abort();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validateRsync,
|
||||
validateInputs
|
||||
};
|
37
src/sshKey.js
Normal file
37
src/sshKey.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const { writeFileSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
const {
|
||||
validateDir,
|
||||
validateFile
|
||||
} = require('./helpers');
|
||||
|
||||
const {
|
||||
HOME
|
||||
} = process.env;
|
||||
|
||||
const addSshKey = (key, name) => {
|
||||
const sshDir = join(HOME || __dirname, '.ssh');
|
||||
const filePath = join(sshDir, name);
|
||||
|
||||
validateDir(sshDir);
|
||||
validateFile(`${sshDir}/known_hosts`);
|
||||
|
||||
try {
|
||||
writeFileSync(filePath, key, {
|
||||
encoding: 'utf8',
|
||||
mode: 0o600
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('⚠️ writeFileSync error', filePath, e.message);
|
||||
process.abort();
|
||||
}
|
||||
|
||||
console.log('✅ Ssh key added to `.ssh` dir ', filePath);
|
||||
|
||||
return filePath;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
addSshKey
|
||||
}
|
Reference in New Issue
Block a user