Skip to content

Commit 2a4e9b1

Browse files
committed
Resolving sync state issue, added tests
fixes #124 fixes #122 fixes #120
1 parent bc95d3e commit 2a4e9b1

File tree

10 files changed

+3978
-262
lines changed

10 files changed

+3978
-262
lines changed

.github/workflows/ftps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: 📂 Sync files
1616
uses: ./
1717
with:
18-
server: wwwssr16.supercp.com
18+
server: ftp.samkirkland.com
1919
2020
password: ${{ secrets.ftp_password }}
2121
protocol: ftps

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ Keys can be added directly to your .yml config file or referenced from your proj
5555
To add a `secret` go to the `Settings` tab in your project then select `Secrets`.
5656
I strongly recommend you store your `password` as a secret.
5757

58-
| Key Name | Required | Example | Default Value | Description |
59-
|-------------------------|----------|----------------------------|----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
60-
| `server` | Yes | `ftp.samkirkland.com` | | Deployment destination server |
61-
| `username` | Yes | `[email protected]` | | FTP user name |
62-
| `password` | Yes | `CrazyUniquePassword&%123` | | FTP password, be sure to escape quotes and spaces |
63-
| `port` | No | `990` | `21` | Server port to connect to (read your web hosts docs) |
64-
| `protocol` | No | `ftps` | `ftp` | `ftp`: provides no encryption, `ftps`: full encryption newest standard (aka "explicit" ftps), `ftps-legacy`: full encryption legacy standard (aka "implicit" ftps) |
65-
| `local-dir` | No | `./myFolderToPublish/` | `./` | Path to upload to on the server, must end with trailing slash `/` |
66-
| `server-dir` | No | `public_html/www/` | `./` | Folder to upload from, must end with trailing slash `/` |
67-
| `state-name` | No | `folder/.sync-state.json` | `.ftp-deploy-sync-state.json` | Path and name of the state file - this file is used to track which files have been deployed |
68-
| `dry-run` | No | `true` | `false` | Prints which modifications will be made with current config options, but doesn't actually make any changes |
69-
| `dangerous-clean-slate` | No | `true` | `false` | Deletes ALL contents of server-dir, even items in excluded with 'exclude' argument |
70-
| `exclude` | No | | `.git*` `.git*/**` `node_modules/**` `node_modules/**/*` | An array of glob patterns, these files will not be included in the publish/delete process |
71-
| `log-level` | No | `minimal` | `standard` | `minimal`: only important info, `standard`: important info and basic file changes, `verbose`: print everything the script is doing |
72-
| `security` | No | `strict` | `loose` | `strict`: Reject any connection which is not authorized with the list of supplied CAs. `loose`: Allow connection even when the domain is not certificate |
58+
| Key Name | Required | Example | Default Value | Description |
59+
|-------------------------|----------|----------------------------|---------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
60+
| `server` | Yes | `ftp.samkirkland.com` | | Deployment destination server |
61+
| `username` | Yes | `[email protected]` | | FTP user name |
62+
| `password` | Yes | `CrazyUniquePassword&%123` | | FTP password, be sure to escape quotes and spaces |
63+
| `port` | No | `990` | `21` | Server port to connect to (read your web hosts docs) |
64+
| `protocol` | No | `ftps` | `ftp` | `ftp`: provides no encryption, `ftps`: full encryption newest standard (aka "explicit" ftps), `ftps-legacy`: full encryption legacy standard (aka "implicit" ftps) |
65+
| `local-dir` | No | `./myFolderToPublish/` | `./` | Path to upload to on the server, must end with trailing slash `/` |
66+
| `server-dir` | No | `public_html/www/` | `./` | Folder to upload from, must end with trailing slash `/` |
67+
| `state-name` | No | `folder/.sync-state.json` | `.ftp-deploy-sync-state.json` | Path and name of the state file - this file is used to track which files have been deployed |
68+
| `dry-run` | No | `true` | `false` | Prints which modifications will be made with current config options, but doesn't actually make any changes |
69+
| `dangerous-clean-slate` | No | `true` | `false` | Deletes ALL contents of server-dir, even items in excluded with 'exclude' argument |
70+
| `exclude` | No | | `[.git*, .git*/**, node_modules/**, node_modules/**/*]` | An array of glob patterns, these files will not be included in the publish/delete process |
71+
| `log-level` | No | `minimal` | `standard` | `minimal`: only important info, `standard`: important info and basic file changes, `verbose`: print everything the script is doing |
72+
| `security` | No | `strict` | `loose` | `strict`: Reject any connection which is not authorized with the list of supplied CAs. `loose`: Allow connection even when the domain is not certificate |
7373

7474

7575
# Common Examples

dist/index.js

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ function syncLocalToServer(client, diffs, logger, timings, args) {
21782178
logger.all(`----------------------------------------------------------------`);
21792179
logger.all(`🎉 Sync complete. Saving current server state to "${args["server-dir"] + args["state-name"]}"`);
21802180
if (args["dry-run"] === false) {
2181-
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"]); }));
2181+
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"]); }));
21822182
}
21832183
});
21842184
}
@@ -2189,9 +2189,8 @@ function deploy(deployArgs) {
21892189
const timings = new utilities_1.Timings();
21902190
timings.start("total");
21912191
// header
2192-
// todo allow swapping out library/version text based on if we are using action
21932192
logger.all(`----------------------------------------------------------------`);
2194-
logger.all(`🚀 Thanks for using ftp-deploy version ${types_1.currentSyncFileVersion}. Let's deploy some stuff! `);
2193+
logger.all(`🚀 Thanks for using ftp-deploy. Let's deploy some stuff! `);
21952194
logger.all(`----------------------------------------------------------------`);
21962195
logger.all(`If you found this project helpful, please support it`);
21972196
logger.all(`by giving it a ⭐ on Github --> https://github.com/SamKirkland/FTP-Deploy-Action`);
@@ -6552,36 +6551,49 @@ var __importStar = (this && this.__importStar) || function (mod) {
65526551
Object.defineProperty(exports, "__esModule", ({ value: true }));
65536552
const core = __importStar(__webpack_require__(2186));
65546553
const ftp_deploy_1 = __webpack_require__(8347);
6554+
const parse_1 = __webpack_require__(6089);
65556555
async function runDeployment() {
6556-
const args = {
6557-
server: core.getInput("server", { required: true }),
6558-
username: core.getInput("username", { required: true }),
6559-
password: core.getInput("password", { required: true }),
6560-
port: optionalInt("port", core.getInput("port")),
6561-
protocol: optionalProtocol("protocol", core.getInput("protocol")),
6562-
"local-dir": optionalString(core.getInput("local-dir")),
6563-
"server-dir": optionalString(core.getInput("server-dir")),
6564-
"state-name": optionalString(core.getInput("state-name")),
6565-
"dry-run": optionalBoolean("dry-run", core.getInput("dry-run")),
6566-
"dangerous-clean-slate": optionalBoolean("dangerous-clean-slate", core.getInput("dangerous-clean-slate")),
6567-
"exclude": optionalStringArray("exclude", core.getInput("exclude")),
6568-
"log-level": optionalLogLevel("log-level", core.getInput("log-level")),
6569-
"security": optionalSecurity("security", core.getInput("security"))
6570-
};
65716556
try {
6557+
const args = {
6558+
server: core.getInput("server", { required: true }),
6559+
username: core.getInput("username", { required: true }),
6560+
password: core.getInput("password", { required: true }),
6561+
port: parse_1.optionalInt("port", core.getInput("port")),
6562+
protocol: parse_1.optionalProtocol("protocol", core.getInput("protocol")),
6563+
"local-dir": parse_1.optionalString(core.getInput("local-dir")),
6564+
"server-dir": parse_1.optionalString(core.getInput("server-dir")),
6565+
"state-name": parse_1.optionalString(core.getInput("state-name")),
6566+
"dry-run": parse_1.optionalBoolean("dry-run", core.getInput("dry-run")),
6567+
"dangerous-clean-slate": parse_1.optionalBoolean("dangerous-clean-slate", core.getInput("dangerous-clean-slate")),
6568+
"exclude": parse_1.optionalStringArray("exclude", core.getInput("exclude")),
6569+
"log-level": parse_1.optionalLogLevel("log-level", core.getInput("log-level")),
6570+
"security": parse_1.optionalSecurity("security", core.getInput("security"))
6571+
};
65726572
await ftp_deploy_1.deploy(args);
65736573
}
65746574
catch (error) {
65756575
core.setFailed(error);
65766576
}
65776577
}
65786578
runDeployment();
6579+
6580+
6581+
/***/ }),
6582+
6583+
/***/ 6089:
6584+
/***/ ((__unused_webpack_module, exports) => {
6585+
6586+
"use strict";
6587+
6588+
Object.defineProperty(exports, "__esModule", ({ value: true }));
6589+
exports.optionalStringArray = exports.optionalInt = exports.optionalSecurity = exports.optionalLogLevel = exports.optionalProtocol = exports.optionalBoolean = exports.optionalString = void 0;
65796590
function optionalString(rawValue) {
65806591
if (rawValue.length === 0) {
65816592
return undefined;
65826593
}
65836594
return rawValue;
65846595
}
6596+
exports.optionalString = optionalString;
65856597
function optionalBoolean(argumentName, rawValue) {
65866598
if (rawValue.length === 0) {
65876599
return undefined;
@@ -6593,8 +6605,9 @@ function optionalBoolean(argumentName, rawValue) {
65936605
if (cleanValue === "false") {
65946606
return false;
65956607
}
6596-
core.setFailed(`${argumentName}: invalid parameter - please use a boolean, you provided "${rawValue}". Try true or false instead.`);
6608+
throw new Error(`${argumentName}: invalid parameter - please use a boolean, you provided "${rawValue}". Try true or false instead.`);
65976609
}
6610+
exports.optionalBoolean = optionalBoolean;
65986611
function optionalProtocol(argumentName, rawValue) {
65996612
if (rawValue.length === 0) {
66006613
return undefined;
@@ -6609,8 +6622,9 @@ function optionalProtocol(argumentName, rawValue) {
66096622
if (cleanValue === "ftps-legacy") {
66106623
return "ftps-legacy";
66116624
}
6612-
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "ftp", "ftps", or "ftps-legacy" instead.`);
6625+
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "ftp", "ftps", or "ftps-legacy" instead.`);
66136626
}
6627+
exports.optionalProtocol = optionalProtocol;
66146628
function optionalLogLevel(argumentName, rawValue) {
66156629
if (rawValue.length === 0) {
66166630
return undefined;
@@ -6625,8 +6639,9 @@ function optionalLogLevel(argumentName, rawValue) {
66256639
if (cleanValue === "verbose") {
66266640
return "verbose";
66276641
}
6628-
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "minimal", "standard", or "verbose" instead.`);
6642+
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "minimal", "standard", or "verbose" instead.`);
66296643
}
6644+
exports.optionalLogLevel = optionalLogLevel;
66306645
function optionalSecurity(argumentName, rawValue) {
66316646
if (rawValue.length === 0) {
66326647
return undefined;
@@ -6638,8 +6653,9 @@ function optionalSecurity(argumentName, rawValue) {
66386653
if (cleanValue === "strict") {
66396654
return "strict";
66406655
}
6641-
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "loose" or "strict" instead.`);
6656+
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try "loose" or "strict" instead.`);
66426657
}
6658+
exports.optionalSecurity = optionalSecurity;
66436659
function optionalInt(argumentName, rawValue) {
66446660
if (rawValue.length === 0) {
66456661
return undefined;
@@ -6648,15 +6664,26 @@ function optionalInt(argumentName, rawValue) {
66486664
if (Number.isInteger(valueAsNumber)) {
66496665
return valueAsNumber;
66506666
}
6651-
core.setFailed(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`);
6667+
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". Try a whole number (no decimals) instead like 1234`);
66526668
}
6669+
exports.optionalInt = optionalInt;
66536670
function optionalStringArray(argumentName, rawValue) {
66546671
if (rawValue.length === 0) {
66556672
return undefined;
66566673
}
6674+
const valueTrim = rawValue.trim();
6675+
if (valueTrim.startsWith("[")) {
6676+
// remove [ and ] - then convert to array
6677+
return rawValue.replace(/[\[\]]/g, "").trim().split(", ").filter(str => str !== "");
6678+
}
66576679
// split value by space and comma
6658-
return rawValue.split(" - ").filter(str => str !== "");
6680+
const valueAsArrayDouble = rawValue.split(" - ").map(str => str.trim()).filter(str => str !== "");
6681+
if (valueAsArrayDouble.length) {
6682+
return valueAsArrayDouble;
6683+
}
6684+
throw new Error(`${argumentName}: invalid parameter - you provided "${rawValue}". This option excepts an array in the format [val1, val2] or val1\/n - val2`);
66596685
}
6686+
exports.optionalStringArray = optionalStringArray;
66606687

66616688

66626689
/***/ }),

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
preset: "ts-jest"
3+
};

0 commit comments

Comments
 (0)