mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2024-11-19 08:08:05 +08:00
Compare commits
4 Commits
01a39e3348
...
v5.1.0
Author | SHA1 | Date | |
---|---|---|---|
|
ece05a2275 | ||
|
b99511bf85 | ||
|
b82eced457 | ||
|
1befdb1c6b |
@@ -1,3 +1,11 @@
|
|||||||
|
# [5.1.0](https://github.com/easingthemes/ssh-deploy/compare/v5.0.3...v5.1.0) (2024-07-24)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Add deleteFile function to helpers module ([1befdb1](https://github.com/easingthemes/ssh-deploy/commit/1befdb1c6bf3282aa34e6caa431cb2da23d2b17d))
|
||||||
|
* apply deleteFile function to remoteCmd ([b82eced](https://github.com/easingthemes/ssh-deploy/commit/b82eced4571cb3f63369d51760a81820ffb1bc7f))
|
||||||
|
|
||||||
## [5.0.3](https://github.com/easingthemes/ssh-deploy/compare/v5.0.2...v5.0.3) (2024-02-27)
|
## [5.0.3](https://github.com/easingthemes/ssh-deploy/compare/v5.0.2...v5.0.3) (2024-02-27)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@draganfilipovic/ssh-deploy",
|
"name": "@draganfilipovic/ssh-deploy",
|
||||||
"version": "5.0.3",
|
"version": "5.1.0",
|
||||||
"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": [
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
const { existsSync, mkdirSync, writeFileSync } = require('fs');
|
const { existsSync, mkdirSync, writeFileSync, unlink } = require('fs');
|
||||||
const { join } = require('path');
|
const { join } = require('path');
|
||||||
|
|
||||||
const validateDir = (dir) => {
|
const validateDir = (dir) => {
|
||||||
@@ -45,6 +45,29 @@ const writeToFile = ({ dir, filename, content, isRequired, mode = '0644' }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteFile = ({ dir, filename, isRequired }) => {
|
||||||
|
validateDir(dir);
|
||||||
|
const filePath = join(dir, filename);
|
||||||
|
|
||||||
|
if (existsSync(filePath)) {
|
||||||
|
const message = `⚠️ [FILE] ${filePath} Required file exist.`;
|
||||||
|
handleError(message, isRequired);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(`[FILE] Deleting ${filePath} file ...`);
|
||||||
|
unlink(filePath, (error) => {
|
||||||
|
if (error) {
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
const message = `⚠️[FILE] Deleting file error. filePath: ${filePath}, message: ${error.message}`;
|
||||||
|
handleError(message, isRequired);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const validateRequiredInputs = (inputs) => {
|
const validateRequiredInputs = (inputs) => {
|
||||||
const inputKeys = Object.keys(inputs);
|
const inputKeys = Object.keys(inputs);
|
||||||
const validInputs = inputKeys.filter((inputKey) => {
|
const validInputs = inputKeys.filter((inputKey) => {
|
||||||
@@ -66,6 +89,7 @@ const snakeToCamel = (str) => str.replace(/[^a-zA-Z0-9]+(.)/g, (m, chr) => chr.t
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
writeToFile,
|
writeToFile,
|
||||||
|
deleteFile,
|
||||||
validateRequiredInputs,
|
validateRequiredInputs,
|
||||||
snakeToCamel
|
snakeToCamel
|
||||||
};
|
};
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const { sshServer, githubWorkspace, remotePort } = require('./inputs');
|
const { sshServer, githubWorkspace, remotePort } = require('./inputs');
|
||||||
const { writeToFile } = require('./helpers');
|
const { writeToFile, deleteFile } = require('./helpers');
|
||||||
|
|
||||||
const handleError = (message, isRequired, callback) => {
|
const handleError = (message, isRequired, callback) => {
|
||||||
if (isRequired) {
|
if (isRequired) {
|
||||||
@@ -30,6 +30,8 @@ const remoteCmd = async (content, privateKeyPath, isRequired, label) => new Prom
|
|||||||
} else {
|
} else {
|
||||||
const limited = data.substring(0, dataLimit);
|
const limited = data.substring(0, dataLimit);
|
||||||
console.log('✅ [CMD] Remote script executed. \n', limited, stderr);
|
console.log('✅ [CMD] Remote script executed. \n', limited, stderr);
|
||||||
|
deleteFile({ dir: githubWorkspace, filename });
|
||||||
|
console.log('✅ [FILE] Script file deleted.');
|
||||||
resolve(limited);
|
resolve(limited);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user