local-dir path, excludes param logging

This commit is contained in:
SamKirkland 2020-11-13 12:12:25 -06:00
parent 649aa38be8
commit f0ef8012ea
6 changed files with 40 additions and 47 deletions

View File

@ -3,8 +3,6 @@ name: FTP Test
on: on:
push: push:
branches: [ master ] branches: [ master ]
pull_request:
branches: [ master ]
jobs: jobs:
deploy: deploy:
@ -12,7 +10,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: 🚚 Get latest code - name: 🚚 Get latest code
uses: actions/checkout@v2 uses: actions/checkout@v2.3.2
- name: 📂 Sync files - name: 📂 Sync files
uses: ./ uses: ./

View File

@ -3,8 +3,6 @@ name: FTPS Test
on: on:
push: push:
branches: [ master ] branches: [ master ]
pull_request:
branches: [ master ]
jobs: jobs:
deploy: deploy:
@ -12,7 +10,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: 🚚 Get latest code - name: 🚚 Get latest code
uses: actions/checkout@v2 uses: actions/checkout@v2.3.2
- name: 📂 Sync files - name: 📂 Sync files
uses: ./ uses: ./
@ -21,4 +19,4 @@ jobs:
username: test@samkirkland.com username: test@samkirkland.com
password: ${{ secrets.ftp_password }} password: ${{ secrets.ftp_password }}
protocol: ftps protocol: ftps
secure: strict security: strict

57
dist/index.js vendored
View File

@ -1739,12 +1739,11 @@ exports.HashDiff = HashDiff;
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.prettyError = void 0; exports.prettyError = void 0;
const types_1 = __webpack_require__(6703); const types_1 = __webpack_require__(6703);
function outputOriginalErrorAndExit(logger, error) { function logOriginalError(logger, error) {
logger.all(); logger.all();
logger.all(`----------------------------------------------------------------`); logger.all(`----------------------------------------------------------------`);
logger.all(`---------------------- Full Error below ----------------------`); logger.all(`---------------------- Full Error below ----------------------`);
logger.all(error); logger.all(error);
process.exit();
} }
/** /**
* Converts a exception to helpful debug info * Converts a exception to helpful debug info
@ -1755,41 +1754,36 @@ function prettyError(logger, args, error) {
logger.all(`----------------------------------------------------------------`); logger.all(`----------------------------------------------------------------`);
logger.all(`--------------- 🔥🔥🔥 A error occurred 🔥🔥🔥 --------------`); logger.all(`--------------- 🔥🔥🔥 A error occurred 🔥🔥🔥 --------------`);
logger.all(`----------------------------------------------------------------`); logger.all(`----------------------------------------------------------------`);
const ftpError = error;
if (typeof error.code === "string") { if (typeof error.code === "string") {
const errorCode = error.code; const errorCode = error.code;
if (errorCode === "ENOTFOUND") { if (errorCode === "ENOTFOUND") {
logger.all(`The server "${args.server}" doesn't seem to exist. Do you have a typo?`); logger.all(`The server "${args.server}" doesn't seem to exist. Do you have a typo?`);
outputOriginalErrorAndExit(logger, error);
} }
} }
if (typeof error.name === "string") { else if (typeof error.name === "string") {
const errorName = error.name; const errorName = error.name;
if (errorName.includes("ERR_TLS_CERT_ALTNAME_INVALID")) { if (errorName.includes("ERR_TLS_CERT_ALTNAME_INVALID")) {
logger.all(`The certificate for "${args.server}" is likely shared. The host did not place your server on the list of valid domains for this cert.`); logger.all(`The certificate for "${args.server}" is likely shared. The host did not place your server on the list of valid domains for this cert.`);
logger.all(`This is a common issue with shared hosts. You have a few options:`); logger.all(`This is a common issue with shared hosts. You have a few options:`);
logger.all(` - Ignore this error by setting security back to loose`); logger.all(` - Ignore this error by setting security back to loose`);
logger.all(` - Contact your hosting provider and ask them for your servers hostname`); logger.all(` - Contact your hosting provider and ask them for your servers hostname`);
outputOriginalErrorAndExit(logger, error);
} }
} }
const ftpError = error; else if (typeof ftpError.code === "number") {
if (typeof ftpError.code === "number") {
if (ftpError.code === types_1.ErrorCode.NotLoggedIn) { if (ftpError.code === types_1.ErrorCode.NotLoggedIn) {
const serverRequiresFTPS = ftpError.message.toLowerCase().includes("must use encryption"); const serverRequiresFTPS = ftpError.message.toLowerCase().includes("must use encryption");
if (serverRequiresFTPS) { if (serverRequiresFTPS) {
logger.all(`The server you are connecting to requires encryption (ftps)`); logger.all(`The server you are connecting to requires encryption (ftps)`);
logger.all(`Enable FTPS by using the protocol option.`); logger.all(`Enable FTPS by using the protocol option.`);
outputOriginalErrorAndExit(logger, error);
} }
else { else {
logger.all(`Could not login with the username "${args.username}" and password "${args.password}".`); logger.all(`Could not login with the username "${args.username}" and password "${args.password}".`);
logger.all(`Make sure you can login with those credentials. If you have a space or a quote in your username or password be sure to escape them!`); logger.all(`Make sure you can login with those credentials. If you have a space or a quote in your username or password be sure to escape them!`);
outputOriginalErrorAndExit(logger, error);
} }
} }
} }
// unknown error :( logOriginalError(logger, error);
outputOriginalErrorAndExit(logger, error);
} }
exports.prettyError = prettyError; exports.prettyError = prettyError;
@ -1833,7 +1827,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.deploy = exports.excludeDefaults = void 0; exports.deploy = exports.getLocalFiles = exports.excludeDefaults = void 0;
const ftp = __importStar(__webpack_require__(7957)); const ftp = __importStar(__webpack_require__(7957));
const readdir_enhanced_1 = __importDefault(__webpack_require__(8811)); const readdir_enhanced_1 = __importDefault(__webpack_require__(8811));
const crypto_1 = __importDefault(__webpack_require__(6417)); const crypto_1 = __importDefault(__webpack_require__(6417));
@ -1902,7 +1896,7 @@ function getLocalFiles(args) {
type: "file", type: "file",
name: stat.path, name: stat.path,
size: stat.size, size: stat.size,
hash: yield fileHash(stat.path, "sha256") hash: yield fileHash(args["local-dir"] + stat.path, "sha256")
}); });
continue; continue;
} }
@ -1912,12 +1906,13 @@ function getLocalFiles(args) {
} }
return { return {
description: types_1.syncFileDescription, description: types_1.syncFileDescription,
version: types_1.currentVersion, version: types_1.currentSyncFileVersion,
generatedTime: new Date().getTime(), generatedTime: new Date().getTime(),
data: records data: records
}; };
}); });
} }
exports.getLocalFiles = getLocalFiles;
function downloadFileList(client, logger, path) { function downloadFileList(client, logger, path) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
// note: originally this was using a writable stream instead of a buffer file // note: originally this was using a writable stream instead of a buffer file
@ -2116,7 +2111,7 @@ function getServerFiles(client, logger, timings, args) {
// set the server state to nothing, because we don't know what the server state is // set the server state to nothing, because we don't know what the server state is
return { return {
description: types_1.syncFileDescription, description: types_1.syncFileDescription,
version: types_1.currentVersion, version: types_1.currentSyncFileVersion,
generatedTime: new Date().getTime(), generatedTime: new Date().getTime(),
data: [], data: [],
}; };
@ -2194,7 +2189,7 @@ function deploy(deployArgs) {
// header // header
// todo allow swapping out library/version text based on if we are using action // todo allow swapping out library/version text based on if we are using action
logger.all(`----------------------------------------------------------------`); logger.all(`----------------------------------------------------------------`);
logger.all(`🚀 Thanks for using ftp-deploy version ${types_1.currentVersion}. Let's deploy some stuff! `); logger.all(`🚀 Thanks for using ftp-deploy version ${types_1.currentSyncFileVersion}. Let's deploy some stuff! `);
logger.all(`----------------------------------------------------------------`); logger.all(`----------------------------------------------------------------`);
logger.all(`If you found this project helpful, please support it`); logger.all(`If you found this project helpful, please support it`);
logger.all(`by giving it a ⭐ on Github --> https://github.com/SamKirkland/FTP-Deploy-Action`); logger.all(`by giving it a ⭐ on Github --> https://github.com/SamKirkland/FTP-Deploy-Action`);
@ -2216,8 +2211,10 @@ function deploy(deployArgs) {
yield global.reconnect(); yield global.reconnect();
try { try {
const serverFiles = yield getServerFiles(client, logger, timings, args); const serverFiles = yield getServerFiles(client, logger, timings, args);
timings.start("logging");
const diffTool = new HashDiff_1.HashDiff(); const diffTool = new HashDiff_1.HashDiff();
const diffs = diffTool.getDiffs(localFiles, serverFiles, logger); const diffs = diffTool.getDiffs(localFiles, serverFiles, logger);
timings.stop("logging");
totalBytesUploaded = diffs.sizeUpload + diffs.sizeReplace; totalBytesUploaded = diffs.sizeUpload + diffs.sizeReplace;
timings.start("upload"); timings.start("upload");
try { try {
@ -2226,11 +2223,9 @@ function deploy(deployArgs) {
catch (e) { catch (e) {
if (e.code === types_1.ErrorCode.FileNameNotAllowed) { if (e.code === types_1.ErrorCode.FileNameNotAllowed) {
logger.all("Error 553 FileNameNotAllowed, you don't have access to upload that file"); logger.all("Error 553 FileNameNotAllowed, you don't have access to upload that file");
logger.all(e);
process.exit();
} }
logger.all(e); logger.all(e);
process.exit(); throw e;
} }
finally { finally {
timings.stop("upload"); timings.stop("upload");
@ -2246,6 +2241,7 @@ function deploy(deployArgs) {
} }
catch (error) { catch (error) {
errorHandling_1.prettyError(logger, args, error); errorHandling_1.prettyError(logger, args, error);
throw error;
} }
finally { finally {
client.close(); client.close();
@ -2258,6 +2254,7 @@ function deploy(deployArgs) {
logger.all(`Time spent connecting to server: ${timings.getTimeFormatted("connecting")}`); logger.all(`Time spent connecting to server: ${timings.getTimeFormatted("connecting")}`);
logger.all(`Time spent deploying: ${timings.getTimeFormatted("upload")} (${uploadSpeed}/second)`); logger.all(`Time spent deploying: ${timings.getTimeFormatted("upload")} (${uploadSpeed}/second)`);
logger.all(` - changing dirs: ${timings.getTimeFormatted("changingDir")}`); logger.all(` - changing dirs: ${timings.getTimeFormatted("changingDir")}`);
logger.all(` - logging: ${timings.getTimeFormatted("logging")}`);
logger.all(`----------------------------------------------------------------`); logger.all(`----------------------------------------------------------------`);
logger.all(`Total time: ${timings.getTimeFormatted("total")}`); logger.all(`Total time: ${timings.getTimeFormatted("total")}`);
logger.all(`----------------------------------------------------------------`); logger.all(`----------------------------------------------------------------`);
@ -2274,8 +2271,8 @@ exports.deploy = deploy;
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ErrorCode = exports.syncFileDescription = exports.currentVersion = void 0; exports.ErrorCode = exports.syncFileDescription = exports.currentSyncFileVersion = void 0;
exports.currentVersion = "1.0.0"; exports.currentSyncFileVersion = "1.0.0";
exports.syncFileDescription = "DO NOT DELETE THIS FILE. This file is used to keep track of which files have been synced in the most recent deployment. If you delete this file a resync will need to be done (which can take a while) - read more: https://github.com/SamKirkland/FTP-Deploy-Action"; exports.syncFileDescription = "DO NOT DELETE THIS FILE. This file is used to keep track of which files have been synced in the most recent deployment. If you delete this file a resync will need to be done (which can take a while) - read more: https://github.com/SamKirkland/FTP-Deploy-Action";
var ErrorCode; var ErrorCode;
(function (ErrorCode) { (function (ErrorCode) {
@ -3303,12 +3300,8 @@ class Client {
return res; return res;
} }
catch (err) { catch (err) {
// Receiving an FTPError means that the last transfer strategy failed and we should // Try the next candidate no matter the exact error. It's possible that a server
// try the next one. Any other exception should stop the evaluation of strategies because // answered incorrectly to a strategy, for example a PASV answer to an EPSV.
// something else went wrong.
if (!(err instanceof FtpContext_1.FTPError)) {
throw err;
}
} }
} }
throw new Error("None of the available transfer strategies work."); throw new Error("None of the available transfer strategies work.");
@ -3970,9 +3963,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
o[k2] = m[k]; o[k2] = m[k];
})); }));
var __exportStar = (this && this.__exportStar) || function(m, exports) { var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.enterPassiveModeIPv6 = exports.enterPassiveModeIPv4 = void 0;
/** /**
* Public API * Public API
*/ */
@ -4131,7 +4125,7 @@ function positiveIntermediate(code) {
} }
exports.positiveIntermediate = positiveIntermediate; exports.positiveIntermediate = positiveIntermediate;
function isNotBlank(str) { function isNotBlank(str) {
return str !== ""; return str.trim() !== "";
} }
@ -4157,7 +4151,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
var __importStar = (this && this.__importStar) || function (mod) { var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod; if (mod && mod.__esModule) return mod;
var result = {}; var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod); __setModuleDefault(result, mod);
return result; return result;
}; };
@ -6655,11 +6649,12 @@ function optionalInt(argumentName, rawValue) {
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`); core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`);
} }
function optionalStringArray(argumentName, rawValue) { function optionalStringArray(argumentName, rawValue) {
console.log(rawValue);
if (rawValue.length === 0) { if (rawValue.length === 0) {
return undefined; return undefined;
} }
// split value by space and comma // split value by space and comma
return rawValue.split(", "); return rawValue.split("\n").filter(str => str !== "");
} }

14
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "ftp-deploy-action", "name": "ftp-deploy-action",
"version": "1.0.1", "version": "4.0.0",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@ -147,9 +147,9 @@
} }
}, },
"@samkirkland/ftp-deploy": { "@samkirkland/ftp-deploy": {
"version": "1.0.0", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/@samkirkland/ftp-deploy/-/ftp-deploy-1.0.0.tgz", "resolved": "https://registry.npmjs.org/@samkirkland/ftp-deploy/-/ftp-deploy-1.0.1.tgz",
"integrity": "sha512-K1Iu2FJZuPH30v9EUmXQjS/8nTtFUTWURKv4SN4F6jSViyoUrf+ZtlzLZaUQU4/WMC80qdtEKCAvV3DTHSCfBA==", "integrity": "sha512-axyX1OLDulqh7/NW/yrcu/BQCGGgY/lt8AI7cHotR8ebq1awYHkf3aV0sEc11Blb2ZtezyKmd8SMIEVN4UGLQg==",
"requires": { "requires": {
"basic-ftp": "^4.6.2", "basic-ftp": "^4.6.2",
"lodash": "^4.17.20", "lodash": "^4.17.20",
@ -345,9 +345,9 @@
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
}, },
"basic-ftp": { "basic-ftp": {
"version": "4.6.2", "version": "4.6.3",
"resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-4.6.2.tgz", "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-4.6.3.tgz",
"integrity": "sha512-UO1L54c/ThZkW9ygaN3NJ4igA6BLoATUpaYARrmH4EXV86WNsk1BS2plFeePx3/vMaoLf1cLWI67uuMayZagDw==" "integrity": "sha512-u/zMus8UacMmsxko3szgmuMYaf7pvYV/k/rMJb1I9RCByURWaVP7/jii/8cvPWF3Co7qqBgwRMhyI5vg727OhA=="
}, },
"binary-extensions": { "binary-extensions": {
"version": "2.1.0", "version": "2.1.0",

View File

@ -22,7 +22,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.2.6",
"@samkirkland/ftp-deploy": "^1.0.0", "@samkirkland/ftp-deploy": "^1.0.1",
"ts-node-dev": "^1.0.0-pre.62" "ts-node-dev": "^1.0.0-pre.62"
}, },
"devDependencies": { "devDependencies": {

View File

@ -129,10 +129,12 @@ function optionalInt(argumentName: string, rawValue: string): number | undefined
} }
function optionalStringArray(argumentName: string, rawValue: string): string[] | undefined { function optionalStringArray(argumentName: string, rawValue: string): string[] | undefined {
console.log(rawValue);
if (rawValue.length === 0) { if (rawValue.length === 0) {
return undefined; return undefined;
} }
// split value by space and comma // split value by space and comma
return rawValue.split(", "); return rawValue.split("\n").filter(str => str !== "");
} }