Compare commits

..

4 Commits

Author SHA1 Message Date
Dragan Filipovic
ad912febba fix: update sub dependencies 2023-01-03 23:39:42 +01:00
Dragan Filipovic
f53f7cb352 fix: add githubWorkspace as default source root 2023-01-03 23:04:15 +01:00
Dragan Filipović
4180a30117 Merge pull request #100 from easingthemes/bugfix/v3/fix-empty-src
fix: fix default source if empty
2023-01-03 22:09:11 +01:00
Dragan Filipovic
2520d9e7f7 fix: fix default source if empty 2023-01-03 22:06:00 +01:00
13 changed files with 28 additions and 205 deletions

View File

@@ -6,7 +6,7 @@ on:
ARGS:
description: 'ARGS'
required: true
default: '-rlgoDzvc -i --delete --chmod=ugo+rwX --progress'
default: '-rltgoDzvO --delete --chmod=ugo+rwX --progress'
EXCLUDE:
description: 'EXCLUDE'
required: true

View File

@@ -74,7 +74,7 @@ jobs:
- name: set shared ENV variables for multi target deployment
run: |
echo "ARGS=-rlgoDzvcR -i --delete --chmod=ugo+rwX --progress" >> $GITHUB_ENV
echo "ARGS=-rltgoDzvOR --delete --chmod=ugo+rwX --progress" >> $GITHUB_ENV
echo "SSH_CMD_ARGS=-o StrictHostKeyChecking=no, -o UserKnownHostsFile=/dev/null" >> $GITHUB_ENV
echo "SOURCE=test_project/ test_project2/" >> $GITHUB_ENV
echo "EXCLUDE=skip_dir/, /node_modules/" >> $GITHUB_ENV
@@ -95,85 +95,8 @@ jobs:
TARGET: /var/www/html/${{ env.TEST_USER }}
- name: e2e Test ssh-deploy action - Target 2
uses: easingthemes/ssh-deploy@main
uses: easingthemes/ssh-deploy@feature/main
env:
# Shared ENV Vars created in previous steps
REMOTE_USER: ${{ 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:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
# : ---------------------------------------------------------------
# : START E2E Test Specific - steps
# : ----------------------------------------------------------------
- name: E2E Test Specific - Clean up old test files
run: |
docker stop ssh-host-container || true && docker rm ssh-host-container || true
- name: E2E Test Specific - Create ssh keys
run: |
echo $HOME
ls -la $HOME
ssh-keygen -m PEM -t rsa -b 4096 -f "$HOME/.ssh/id_rsa" -N ""
eval `ssh-agent -s`
ssh-add "$HOME/.ssh/id_rsa"
ssh-add -l
echo "SSH_PRIVATE_KEY<<EOF" >> $GITHUB_ENV
cat $HOME/.ssh/id_rsa >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: E2E Test Specific - Build Host Server Image
working-directory: ${{ env.TEST_HOST_DOCKER }}
run: |
docker build \
-t ssh-host-image . \
--build-arg SSH_PUB_KEY="$(cat $HOME/.ssh/id_rsa.pub)"
docker run -d -p 8822:22 --name=ssh-host-container ssh-host-image
docker exec ssh-host-container sh -c "hostname --ip-address" > ip.txt
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
cat ip.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
shell: bash
- name: E2E Test Specific - Create project file
run: |
mkdir test_project2 && cd "$_"
truncate -s 5MB info2.txt
cd ../
mkdir test_project && cd "$_"
touch index.html
date +"%Y-%m-%d %H:%M:%S,%3N" >> index.html
truncate -s 50MB image.svg
truncate -s 5MB info.txt
truncate -s 500MB big_file.txt
mkdir skip_dir && cd "$_"
truncate -s 5MB text_in_skip_dir.txt
cd ../
cat index.html
echo "test_project:" && ls -lR
echo "skip_dir:" && ls -lR skip_dir
# ----------------------------------------------------------------
# END E2E Test Specific - steps
# ----------------------------------------------------------------
- name: e2e Test ssh-deploy action - Target 1
uses: easingthemes/ssh-deploy@v3
env:
# Shared ENV Vars created in previous steps
REMOTE_USER: ${{ env.TEST_USER }}
TARGET: /var/www/html/${{ env.TEST_USER }}
SOURCE: test_project/
EXCLUDE: skip_dir/, /node_modules/
ARGS: -rlgoDzvcO

View File

@@ -6,10 +6,11 @@ on:
description: 'Version'
type: choice
required: true
default: fix
default: patch
options:
- fix
- feat
- patch
- minor
- major
dryRun:
description: 'DryRun'
type: boolean
@@ -63,7 +64,7 @@ jobs:
run: npm run build --if-present
- name: Run Tests
run: npm test --if-present
- name: Create a release - ${{ github.event.inputs.version }}
- name: Publish npm package
uses: cycjimmy/semantic-release-action@v3
with:
dry_run: ${{ github.event.inputs.dryRun == 'true' }}

View File

@@ -41,7 +41,7 @@ eg: myusername
eg: '59184'
##### 5. `ARGS` (optional, default '-rlgoDzvc -i')
##### 5. `ARGS` (optional, default '-rltgoDzvO')
For any initial/required rsync flags, eg: `-avzr --delete`
@@ -62,8 +62,6 @@ path to exclude separated by `,`, ie: `/dist/, /node_modules/`
Script to run on host machine before rsync. Single line or multiline commands.
Execution is preformed by storing commands in `.sh` file and executing it via `.bash` over `ssh`
If you have issues with `ssh` connection, use this var, eg `SCRIPT_BEFORE: ls`.
This will force `known_hosts` update, adding your host via `ssh-keyscan`.
##### 10. `SCRIPT_AFTER` (optional, default '')
@@ -85,7 +83,7 @@ or use the latest version from a branch, eg: ssh-deploy@main
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
ARGS: "-rlgoDzvc -i"
ARGS: "-rltgoDzvO"
SOURCE: "dist/"
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
@@ -126,7 +124,7 @@ jobs:
uses: easingthemes/ssh-deploy@main
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
ARGS: "-rlgoDzvc -i --delete"
ARGS: "-rltgoDzvO --delete"
SOURCE: "dist/"
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
REMOTE_USER: ${{ secrets.REMOTE_USER }}
@@ -158,7 +156,6 @@ For complex use cases, use `ARGS` and `SSH_CMD_ARGS` to fully configure `rsync`
- If you need to use multiple steps, eg multi targets deployment, save shared ENV variables in `>> $GITHUB_ENV`.
Check .github/workflows/e2e.yml for an example
- For multi sources, use -R ARG to manipulate folders structure.
- Great post about `rsync` options specific to usage of this action: https://logansnotes.com/2020/gh-action-site-deploy/
## Disclaimer

View File

@@ -22,11 +22,11 @@ inputs:
TARGET:
description: "Target directory"
required: false
default: ""
default: "/home/REMOTE_USER/"
ARGS:
description: "Arguments to pass to rsync"
required: false
default: "-rlgoDzvc -i"
default: "-rltgoDzvO"
SSH_CMD_ARGS:
description: "An array of ssh arguments, they must be prefixed with -o and separated by a comma, for example: -o SomeArgument=no, -o SomeOtherArgument=5 "
required: false

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,98 +1,3 @@
## [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)
### Bug Fixes
* update sub dependencies ([2a32c8d](https://github.com/easingthemes/ssh-deploy/commit/2a32c8dcde2d64394a3577decdd9c902f37a30f8))
## [4.0.3](https://github.com/easingthemes/ssh-deploy/compare/v4.0.2...v4.0.3) (2023-01-03)
### Bug Fixes
* update v3 e2e test ([450bf42](https://github.com/easingthemes/ssh-deploy/commit/450bf423f388777bde052ad7b5bc24eca392434d))
## [4.0.2](https://github.com/easingthemes/ssh-deploy/compare/v4.0.1...v4.0.2) (2023-01-03)
### Bug Fixes
* add githubWorkspace as default source root ([3ef66d0](https://github.com/easingthemes/ssh-deploy/commit/3ef66d0be999ee45434505e8bedea4f8b5b5a909))
## [4.0.1](https://github.com/easingthemes/ssh-deploy/compare/v4.0.0...v4.0.1) (2023-01-03)
### Bug Fixes
* fix default source if empty ([9f191f4](https://github.com/easingthemes/ssh-deploy/commit/9f191f42633c4a0f66054f0fc229c9e30a08f00c))
# [4.0.0](https://github.com/easingthemes/ssh-deploy/compare/v3.4.3...v4.0.0) (2023-01-03)
### Bug Fixes
* rebuild ([2169399](https://github.com/easingthemes/ssh-deploy/commit/2169399fef9a60a2fea1ab03cce4ec8c2371e5c2))
### Performance Improvements
* update default rsync options ([2be7efb](https://github.com/easingthemes/ssh-deploy/commit/2be7efb376866327c1d1209f51eb43f34f07b354))
### BREAKING CHANGES
* Default rsync options updated to speed up default deployments.
from `rltgoDzvO` to `-rlgoDzvc -i`
## [3.4.3](https://github.com/easingthemes/ssh-deploy/compare/v3.4.2...v3.4.3) (2023-01-03)

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@draganfilipovic/ssh-deploy",
"version": "4.0.5",
"version": "3.4.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@draganfilipovic/ssh-deploy",
"version": "4.0.5",
"version": "3.4.3",
"license": "MIT",
"dependencies": {
"rsyncwrapper": "^3.0.1"

View File

@@ -1,6 +1,6 @@
{
"name": "@draganfilipovic/ssh-deploy",
"version": "4.1.5",
"version": "3.4.3",
"description": "Fast NodeJS action to deploy specific directory from `GITHUB_WORKSPACE` to a server via rsync over ssh.",
"main": "dist/index.js",
"files": [

View File

@@ -20,7 +20,7 @@ const run = async () => {
const { path: privateKeyPath } = getPrivateKeyPath(deployKeyName);
// Update known hosts if ssh command is present to avoid prompt
if (scriptBefore || scriptAfter) {
updateKnownHosts(remoteHost, remotePort);
updateKnownHosts(remoteHost);
}
// Check Script before
if (scriptBefore) {

View File

@@ -7,13 +7,13 @@ const inputNames = [
'SCRIPT_BEFORE', 'SCRIPT_AFTER'];
const githubWorkspace = process.env.GITHUB_WORKSPACE;
const remoteUser = process.env.REMOTE_USER || process.env.INPUT_REMOTE_USER;
const remoteUser = process.env.REMOTE_USER;
const defaultInputs = {
source: '',
target: `/home/${remoteUser}/`,
exclude: '',
args: '-rlgoDzvc -i',
args: '-rltgoDzvO',
sshCmdArgs: '-o StrictHostKeyChecking=no',
deployKeyName: `deploy_key_${remoteUser}_${Date.now()}`
};
@@ -24,7 +24,7 @@ const inputs = {
inputNames.forEach((input) => {
const inputName = snakeToCamel(input.toLowerCase());
const inputVal = process.env[input] || process.env[`INPUT_${input}`] || defaultInputs[inputName];
const inputVal = process.env[input] || process.env[`INPUT_${input}`];
const validVal = inputVal === undefined ? defaultInputs[inputName] : inputVal;
let extendedVal = validVal;
// eslint-disable-next-line default-case

View File

@@ -1,5 +1,5 @@
const { exec } = require('child_process');
const { sshServer, githubWorkspace, remotePort } = require('./inputs');
const { sshServer, githubWorkspace } = require('./inputs');
const { writeToFile } = require('./helpers');
const handleError = (message, isRequired, callback) => {
@@ -15,20 +15,17 @@ const remoteCmd = async (content, privateKeyPath, isRequired, label) => new Prom
const filename = `local_ssh_script-${label}.sh`;
try {
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}`);
exec(
`DEBIAN_FRONTEND=noninteractive ssh -p ${(remotePort || 22)} -i ${privateKeyPath} -o StrictHostKeyChecking=no ${sshServer} 'RSYNC_STDOUT="${rsyncStdout}" bash -s' < ${filename}`,
`DEBIAN_FRONTEND=noninteractive ssh -i ${privateKeyPath} -o StrictHostKeyChecking=no ${sshServer} 'RSYNC_STDOUT="${process.env.RSYNC_STDOUT}" bash -s' < ${filename}`,
(err, data, stderr) => {
if (err) {
const message = `⚠️ [CMD] Remote script failed: ${err.message}`;
console.warn(`${message} \n`, data, stderr);
handleError(message, isRequired, reject);
} else {
const limited = data.substring(0, dataLimit);
console.log('✅ [CMD] Remote script executed. \n', limited, stderr);
resolve(limited);
console.log('✅ [CMD] Remote script executed. \n', data, stderr);
resolve(data);
}
}
);

View File

@@ -19,15 +19,15 @@ const addSshKey = (content, deployKeyName) => {
const { dir, filename } = getPrivateKeyPath(deployKeyName);
writeToFile({ dir, filename: KNOWN_HOSTS, content: '' });
console.log('✅ [SSH] known_hosts file ensured', dir);
writeToFile({ dir, filename, content: `${content}\r\n`, isRequired: true, mode: '0400' });
writeToFile({ dir, filename, content, isRequired: true, mode: '0400' });
console.log('✅ [SSH] key added to `.ssh` dir ', dir, filename);
};
const updateKnownHosts = (host, remotePort) => {
const updateKnownHosts = (host) => {
const { knownHostsPath } = getPrivateKeyPath();
console.log('[SSH] Adding host to `known_hosts` ....', host, knownHostsPath);
try {
execSync(`ssh-keyscan -p ${(remotePort || 22)} -H ${host} >> ${knownHostsPath}`, {
execSync(`ssh-keyscan -H ${host} >> ${knownHostsPath}`, {
stdio: 'inherit'
});
} catch (error) {