mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2024-11-19 08:08:05 +08:00
Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
51b2009841 | ||
|
530a3691f2 | ||
|
509caf1bb9 | ||
|
54f8b6c60b | ||
|
d9d134f8e5 | ||
|
e7b2312bc9 | ||
|
f0c02fb2a5 | ||
|
ae4970d4cf | ||
|
5894f5e290 | ||
|
c381b885db | ||
|
756a522533 | ||
|
45cee3db2e | ||
|
59827af83c | ||
|
adb1a2ce99 | ||
|
4d086346af | ||
|
056fb0fea7 | ||
|
d7e6989d58 | ||
|
0fb307eb41 | ||
|
a7b7e1e49d | ||
|
e995cb4b7b | ||
|
808b0020d4 | ||
|
d5e1f75798 | ||
|
a1e01b2fad | ||
|
164a3e861e | ||
|
426f06d922 | ||
|
245b7a9d2f | ||
|
4c8eee72bd | ||
|
0a1df91f97 |
6
.github/workflows/e2e.yml
vendored
6
.github/workflows/e2e.yml
vendored
@@ -100,6 +100,12 @@ jobs:
|
|||||||
# Shared ENV Vars created in previous steps
|
# Shared ENV Vars created in previous steps
|
||||||
REMOTE_USER: ${{ env.TEST_USER2 }}
|
REMOTE_USER: ${{ env.TEST_USER2 }}
|
||||||
TARGET: /var/www/html/${{ env.TEST_USER2 }}
|
TARGET: /var/www/html/${{ env.TEST_USER2 }}
|
||||||
|
|
||||||
|
- name: e2e Test ssh-deploy action - Default values
|
||||||
|
uses: easingthemes/ssh-deploy@main
|
||||||
|
env:
|
||||||
|
# Shared ENV Vars created in previous steps
|
||||||
|
REMOTE_USER: ${{ env.TEST_USER }}
|
||||||
e2e-v3:
|
e2e-v3:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
9
.github/workflows/manual-release.yml
vendored
9
.github/workflows/manual-release.yml
vendored
@@ -6,11 +6,10 @@ on:
|
|||||||
description: 'Version'
|
description: 'Version'
|
||||||
type: choice
|
type: choice
|
||||||
required: true
|
required: true
|
||||||
default: patch
|
default: fix
|
||||||
options:
|
options:
|
||||||
- patch
|
- fix
|
||||||
- minor
|
- feat
|
||||||
- major
|
|
||||||
dryRun:
|
dryRun:
|
||||||
description: 'DryRun'
|
description: 'DryRun'
|
||||||
type: boolean
|
type: boolean
|
||||||
@@ -64,7 +63,7 @@ jobs:
|
|||||||
run: npm run build --if-present
|
run: npm run build --if-present
|
||||||
- name: Run Tests
|
- name: Run Tests
|
||||||
run: npm test --if-present
|
run: npm test --if-present
|
||||||
- name: Publish npm package
|
- name: Create a release - ${{ github.event.inputs.version }}
|
||||||
uses: cycjimmy/semantic-release-action@v3
|
uses: cycjimmy/semantic-release-action@v3
|
||||||
with:
|
with:
|
||||||
dry_run: ${{ github.event.inputs.dryRun == 'true' }}
|
dry_run: ${{ github.event.inputs.dryRun == 'true' }}
|
||||||
|
@@ -22,7 +22,7 @@ inputs:
|
|||||||
TARGET:
|
TARGET:
|
||||||
description: "Target directory"
|
description: "Target directory"
|
||||||
required: false
|
required: false
|
||||||
default: "/home/REMOTE_USER/"
|
default: ""
|
||||||
ARGS:
|
ARGS:
|
||||||
description: "Arguments to pass to rsync"
|
description: "Arguments to pass to rsync"
|
||||||
required: false
|
required: false
|
||||||
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,3 +1,59 @@
|
|||||||
|
## [4.1.6](https://github.com/easingthemes/ssh-deploy/compare/v4.1.5...v4.1.6) (2023-02-21)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#118](https://github.com/easingthemes/ssh-deploy/issues/118) check undefined default values rebuild ([54f8b6c](https://github.com/easingthemes/ssh-deploy/commit/54f8b6c60b8f2f926d5ed9538557e5521a905d87))
|
||||||
|
|
||||||
|
## [4.1.5](https://github.com/easingthemes/ssh-deploy/compare/v4.1.4...v4.1.5) (2023-02-21)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#118](https://github.com/easingthemes/ssh-deploy/issues/118) check undefined default values ([f0c02fb](https://github.com/easingthemes/ssh-deploy/commit/f0c02fb2a5b3b69bb91004dd49d409eb6adfe7cd))
|
||||||
|
|
||||||
|
## [4.1.4](https://github.com/easingthemes/ssh-deploy/compare/v4.1.3...v4.1.4) (2023-02-21)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#113](https://github.com/easingthemes/ssh-deploy/issues/113) limit ssh script input ([5894f5e](https://github.com/easingthemes/ssh-deploy/commit/5894f5e29008feccaf42787330ec8f49f3ad50b0))
|
||||||
|
|
||||||
|
## [4.1.3](https://github.com/easingthemes/ssh-deploy/compare/v4.1.2...v4.1.3) (2023-02-21)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#113](https://github.com/easingthemes/ssh-deploy/issues/113) limit ssh script output - rebuild ([756a522](https://github.com/easingthemes/ssh-deploy/commit/756a522533d2206203b5d13b5aa11c88b3313784))
|
||||||
|
|
||||||
|
## [4.1.2](https://github.com/easingthemes/ssh-deploy/compare/v4.1.1...v4.1.2) (2023-02-21)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#113](https://github.com/easingthemes/ssh-deploy/issues/113) limit ssh script output ([59827af](https://github.com/easingthemes/ssh-deploy/commit/59827af83c934996efda72f9fbd1fcd0bb9ccaac))
|
||||||
|
|
||||||
|
## [4.1.1](https://github.com/easingthemes/ssh-deploy/compare/v4.1.0...v4.1.1) (2023-02-21)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* fix default TARGET ([4d08634](https://github.com/easingthemes/ssh-deploy/commit/4d086346af62ac5d57fa37ee6bb46f8de8ad48c3))
|
||||||
|
|
||||||
|
# [4.1.0](https://github.com/easingthemes/ssh-deploy/compare/v4.0.5...v4.1.0) (2023-02-19)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add ssh port from VARs, fix package-lock ([808b002](https://github.com/easingthemes/ssh-deploy/commit/808b0020d44b7c25ef1c13b3979ffdab4f503236))
|
||||||
|
|
||||||
|
## [4.0.5](https://github.com/easingthemes/ssh-deploy/compare/v4.0.4...v4.0.5) (2023-01-06)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* fix manual release action ([245b7a9](https://github.com/easingthemes/ssh-deploy/commit/245b7a9d2fe5272ee34608f86a612d643694c23b))
|
||||||
|
|
||||||
## [4.0.4](https://github.com/easingthemes/ssh-deploy/compare/v4.0.3...v4.0.4) (2023-01-03)
|
## [4.0.4](https://github.com/easingthemes/ssh-deploy/compare/v4.0.3...v4.0.4) (2023-01-03)
|
||||||
|
|
||||||
|
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@draganfilipovic/ssh-deploy",
|
"name": "@draganfilipovic/ssh-deploy",
|
||||||
"version": "4.0.3",
|
"version": "4.0.5",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@draganfilipovic/ssh-deploy",
|
"name": "@draganfilipovic/ssh-deploy",
|
||||||
"version": "4.0.3",
|
"version": "4.0.5",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"rsyncwrapper": "^3.0.1"
|
"rsyncwrapper": "^3.0.1"
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@draganfilipovic/ssh-deploy",
|
"name": "@draganfilipovic/ssh-deploy",
|
||||||
"version": "4.0.4",
|
"version": "4.1.6",
|
||||||
"description": "Fast NodeJS action to deploy specific directory from `GITHUB_WORKSPACE` to a server via rsync over ssh.",
|
"description": "Fast NodeJS action to deploy specific directory from `GITHUB_WORKSPACE` to a server via rsync over ssh.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
@@ -20,7 +20,7 @@ const run = async () => {
|
|||||||
const { path: privateKeyPath } = getPrivateKeyPath(deployKeyName);
|
const { path: privateKeyPath } = getPrivateKeyPath(deployKeyName);
|
||||||
// Update known hosts if ssh command is present to avoid prompt
|
// Update known hosts if ssh command is present to avoid prompt
|
||||||
if (scriptBefore || scriptAfter) {
|
if (scriptBefore || scriptAfter) {
|
||||||
updateKnownHosts(remoteHost);
|
updateKnownHosts(remoteHost, remotePort);
|
||||||
}
|
}
|
||||||
// Check Script before
|
// Check Script before
|
||||||
if (scriptBefore) {
|
if (scriptBefore) {
|
||||||
|
@@ -7,7 +7,7 @@ const inputNames = [
|
|||||||
'SCRIPT_BEFORE', 'SCRIPT_AFTER'];
|
'SCRIPT_BEFORE', 'SCRIPT_AFTER'];
|
||||||
|
|
||||||
const githubWorkspace = process.env.GITHUB_WORKSPACE;
|
const githubWorkspace = process.env.GITHUB_WORKSPACE;
|
||||||
const remoteUser = process.env.REMOTE_USER;
|
const remoteUser = process.env.REMOTE_USER || process.env.INPUT_REMOTE_USER;
|
||||||
|
|
||||||
const defaultInputs = {
|
const defaultInputs = {
|
||||||
source: '',
|
source: '',
|
||||||
@@ -24,7 +24,7 @@ const inputs = {
|
|||||||
|
|
||||||
inputNames.forEach((input) => {
|
inputNames.forEach((input) => {
|
||||||
const inputName = snakeToCamel(input.toLowerCase());
|
const inputName = snakeToCamel(input.toLowerCase());
|
||||||
const inputVal = process.env[input] || process.env[`INPUT_${input}`];
|
const inputVal = process.env[input] || process.env[`INPUT_${input}`] || defaultInputs[inputName];
|
||||||
const validVal = inputVal === undefined ? defaultInputs[inputName] : inputVal;
|
const validVal = inputVal === undefined ? defaultInputs[inputName] : inputVal;
|
||||||
let extendedVal = validVal;
|
let extendedVal = validVal;
|
||||||
// eslint-disable-next-line default-case
|
// eslint-disable-next-line default-case
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const { sshServer, githubWorkspace } = require('./inputs');
|
const { sshServer, githubWorkspace, remotePort } = require('./inputs');
|
||||||
const { writeToFile } = require('./helpers');
|
const { writeToFile } = require('./helpers');
|
||||||
|
|
||||||
const handleError = (message, isRequired, callback) => {
|
const handleError = (message, isRequired, callback) => {
|
||||||
@@ -15,17 +15,20 @@ const remoteCmd = async (content, privateKeyPath, isRequired, label) => new Prom
|
|||||||
const filename = `local_ssh_script-${label}.sh`;
|
const filename = `local_ssh_script-${label}.sh`;
|
||||||
try {
|
try {
|
||||||
writeToFile({ dir: githubWorkspace, filename, content });
|
writeToFile({ dir: githubWorkspace, filename, content });
|
||||||
|
const dataLimit = 10000;
|
||||||
|
const rsyncStdout = process.env.RSYNC_STDOUT.substring(0, dataLimit);
|
||||||
console.log(`Executing remote script: ssh -i ${privateKeyPath} ${sshServer}`);
|
console.log(`Executing remote script: ssh -i ${privateKeyPath} ${sshServer}`);
|
||||||
exec(
|
exec(
|
||||||
`DEBIAN_FRONTEND=noninteractive ssh -i ${privateKeyPath} -o StrictHostKeyChecking=no ${sshServer} 'RSYNC_STDOUT="${process.env.RSYNC_STDOUT}" bash -s' < ${filename}`,
|
`DEBIAN_FRONTEND=noninteractive ssh -p ${(remotePort || 22)} -i ${privateKeyPath} -o StrictHostKeyChecking=no ${sshServer} 'RSYNC_STDOUT="${rsyncStdout}" bash -s' < ${filename}`,
|
||||||
(err, data, stderr) => {
|
(err, data, stderr) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
const message = `⚠️ [CMD] Remote script failed: ${err.message}`;
|
const message = `⚠️ [CMD] Remote script failed: ${err.message}`;
|
||||||
console.warn(`${message} \n`, data, stderr);
|
console.warn(`${message} \n`, data, stderr);
|
||||||
handleError(message, isRequired, reject);
|
handleError(message, isRequired, reject);
|
||||||
} else {
|
} else {
|
||||||
console.log('✅ [CMD] Remote script executed. \n', data, stderr);
|
const limited = data.substring(0, dataLimit);
|
||||||
resolve(data);
|
console.log('✅ [CMD] Remote script executed. \n', limited, stderr);
|
||||||
|
resolve(limited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@@ -19,15 +19,15 @@ const addSshKey = (content, deployKeyName) => {
|
|||||||
const { dir, filename } = getPrivateKeyPath(deployKeyName);
|
const { dir, filename } = getPrivateKeyPath(deployKeyName);
|
||||||
writeToFile({ dir, filename: KNOWN_HOSTS, content: '' });
|
writeToFile({ dir, filename: KNOWN_HOSTS, content: '' });
|
||||||
console.log('✅ [SSH] known_hosts file ensured', dir);
|
console.log('✅ [SSH] known_hosts file ensured', dir);
|
||||||
writeToFile({ dir, filename, content, isRequired: true, mode: '0400' });
|
writeToFile({ dir, filename, content: `${content}\r\n`, isRequired: true, mode: '0400' });
|
||||||
console.log('✅ [SSH] key added to `.ssh` dir ', dir, filename);
|
console.log('✅ [SSH] key added to `.ssh` dir ', dir, filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateKnownHosts = (host) => {
|
const updateKnownHosts = (host, remotePort) => {
|
||||||
const { knownHostsPath } = getPrivateKeyPath();
|
const { knownHostsPath } = getPrivateKeyPath();
|
||||||
console.log('[SSH] Adding host to `known_hosts` ....', host, knownHostsPath);
|
console.log('[SSH] Adding host to `known_hosts` ....', host, knownHostsPath);
|
||||||
try {
|
try {
|
||||||
execSync(`ssh-keyscan -H ${host} >> ${knownHostsPath}`, {
|
execSync(`ssh-keyscan -p ${(remotePort || 22)} -H ${host} >> ${knownHostsPath}`, {
|
||||||
stdio: 'inherit'
|
stdio: 'inherit'
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Reference in New Issue
Block a user