Resolving sync state issue, added tests

fixes #124
fixes #122
fixes #120
This commit is contained in:
SamKirkland
2020-11-23 01:22:34 -06:00
parent bc95d3edc3
commit 2a4e9b1312
10 changed files with 3961 additions and 245 deletions

75
dist/index.js vendored
View File

@@ -2178,7 +2178,7 @@ function syncLocalToServer(client, diffs, logger, timings, args) {
logger.all(`----------------------------------------------------------------`);
logger.all(`🎉 Sync complete. Saving current server state to "${args["server-dir"] + args["state-name"]}"`);
if (args["dry-run"] === false) {
yield utilities_1.retryRequest(logger, () => __awaiter(this, void 0, void 0, function* () { return yield client.uploadFrom(args["local-dir"] + args["state-name"], args["server-dir"] + args["state-name"]); }));
yield utilities_1.retryRequest(logger, () => __awaiter(this, void 0, void 0, function* () { return yield client.uploadFrom(args["local-dir"] + args["state-name"], args["state-name"]); }));
}
});
}
@@ -2189,9 +2189,8 @@ function deploy(deployArgs) {
const timings = new utilities_1.Timings();
timings.start("total");
// header
// todo allow swapping out library/version text based on if we are using action
logger.all(`----------------------------------------------------------------`);
logger.all(`🚀 Thanks for using ftp-deploy version ${types_1.currentSyncFileVersion}. Let's deploy some stuff! `);
logger.all(`🚀 Thanks for using ftp-deploy. Let's deploy some stuff! `);
logger.all(`----------------------------------------------------------------`);
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`);
@@ -6552,23 +6551,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__webpack_require__(2186));
const ftp_deploy_1 = __webpack_require__(8347);
const parse_1 = __webpack_require__(6089);
async function runDeployment() {
const args = {
server: core.getInput("server", { required: true }),
username: core.getInput("username", { required: true }),
password: core.getInput("password", { required: true }),
port: optionalInt("port", core.getInput("port")),
protocol: optionalProtocol("protocol", core.getInput("protocol")),
"local-dir": optionalString(core.getInput("local-dir")),
"server-dir": optionalString(core.getInput("server-dir")),
"state-name": optionalString(core.getInput("state-name")),
"dry-run": optionalBoolean("dry-run", core.getInput("dry-run")),
"dangerous-clean-slate": optionalBoolean("dangerous-clean-slate", core.getInput("dangerous-clean-slate")),
"exclude": optionalStringArray("exclude", core.getInput("exclude")),
"log-level": optionalLogLevel("log-level", core.getInput("log-level")),
"security": optionalSecurity("security", core.getInput("security"))
};
try {
const args = {
server: core.getInput("server", { required: true }),
username: core.getInput("username", { required: true }),
password: core.getInput("password", { required: true }),
port: parse_1.optionalInt("port", core.getInput("port")),
protocol: parse_1.optionalProtocol("protocol", core.getInput("protocol")),
"local-dir": parse_1.optionalString(core.getInput("local-dir")),
"server-dir": parse_1.optionalString(core.getInput("server-dir")),
"state-name": parse_1.optionalString(core.getInput("state-name")),
"dry-run": parse_1.optionalBoolean("dry-run", core.getInput("dry-run")),
"dangerous-clean-slate": parse_1.optionalBoolean("dangerous-clean-slate", core.getInput("dangerous-clean-slate")),
"exclude": parse_1.optionalStringArray("exclude", core.getInput("exclude")),
"log-level": parse_1.optionalLogLevel("log-level", core.getInput("log-level")),
"security": parse_1.optionalSecurity("security", core.getInput("security"))
};
await ftp_deploy_1.deploy(args);
}
catch (error) {
@@ -6576,12 +6576,24 @@ async function runDeployment() {
}
}
runDeployment();
/***/ }),
/***/ 6089:
/***/ ((__unused_webpack_module, exports) => {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.optionalStringArray = exports.optionalInt = exports.optionalSecurity = exports.optionalLogLevel = exports.optionalProtocol = exports.optionalBoolean = exports.optionalString = void 0;
function optionalString(rawValue) {
if (rawValue.length === 0) {
return undefined;
}
return rawValue;
}
exports.optionalString = optionalString;
function optionalBoolean(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
@@ -6593,8 +6605,9 @@ function optionalBoolean(argumentName, rawValue) {
if (cleanValue === "false") {
return false;
}
core.setFailed(`${argumentName}: invalid parameter - please use a boolean, you provided "${rawValue}". Try true or false instead.`);
throw new Error(`${argumentName}: invalid parameter - please use a boolean, you provided "${rawValue}". Try true or false instead.`);
}
exports.optionalBoolean = optionalBoolean;
function optionalProtocol(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
@@ -6609,8 +6622,9 @@ function optionalProtocol(argumentName, rawValue) {
if (cleanValue === "ftps-legacy") {
return "ftps-legacy";
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "ftp", "ftps", or "ftps-legacy" instead.`);
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "ftp", "ftps", or "ftps-legacy" instead.`);
}
exports.optionalProtocol = optionalProtocol;
function optionalLogLevel(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
@@ -6625,8 +6639,9 @@ function optionalLogLevel(argumentName, rawValue) {
if (cleanValue === "verbose") {
return "verbose";
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "minimal", "standard", or "verbose" instead.`);
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "minimal", "standard", or "verbose" instead.`);
}
exports.optionalLogLevel = optionalLogLevel;
function optionalSecurity(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
@@ -6638,8 +6653,9 @@ function optionalSecurity(argumentName, rawValue) {
if (cleanValue === "strict") {
return "strict";
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "loose" or "strict" instead.`);
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "loose" or "strict" instead.`);
}
exports.optionalSecurity = optionalSecurity;
function optionalInt(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
@@ -6648,15 +6664,26 @@ function optionalInt(argumentName, rawValue) {
if (Number.isInteger(valueAsNumber)) {
return valueAsNumber;
}
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`);
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`);
}
exports.optionalInt = optionalInt;
function optionalStringArray(argumentName, rawValue) {
if (rawValue.length === 0) {
return undefined;
}
const valueTrim = rawValue.trim();
if (valueTrim.startsWith("[")) {
// remove [ and ] - then convert to array
return rawValue.replace(/[\[\]]/g, "").trim().split(", ").filter(str => str !== "");
}
// split value by space and comma
return rawValue.split(" - ").filter(str => str !== "");
const valueAsArrayDouble = rawValue.split(" - ").map(str => str.trim()).filter(str => str !== "");
if (valueAsArrayDouble.length) {
return valueAsArrayDouble;
}
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". This option excepts an array in the format [val1, val2] or val1\/n - val2`);
}
exports.optionalStringArray = optionalStringArray;
/***/ }),